batch-processing-clinical-text
What it does
This skill processes large collections of clinical notes in batches, on your own machine, with progress tracking and saved checkpoints. It is for teams with thousands of documents who need entity extraction or de-identification at scale.
When to use it
- βWhen you need to process a folder or dataset of clinical notes rather than a single note.
- βWhen you need a long batch job that can resume after an interruption.
- βWhen you want results written to JSONL output without holding everything in memory.
Skill link
https://github.com/maziyarpanahi/openmed/blob/master/skills/batch-processing-clinical-text/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βDe-identify the 5,000 discharge notes in this folder on my computer, and let me resume if the job stops halfway.β
5 new skills a week. 1 minute to read.
How it works
The agent splits the corpus into shards, processes each note with the local model, records checkpoints, and writes results to an append-only file that a restart can continue.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Batch processing clinical text
openmed.processing runs OpenMed over many documents efficiently, with progress
tracking, per-item error isolation, and streaming. It runs fully on-device:
the corpus, the model, and the output never leave the host. This skill shows a
resumable runner β sharded, checkpointed, append-only JSONL β that you can
restart without reprocessing.
When to use this skill
For corpora, folders, or datasets β anything beyond a handful of notes. For a
single note, just call openmed.analyze_text / deidentify directly
(extracting-clinical-entities, deidentifying-clinical-text). For an
always-on HTTP service, see serving-openmed-rest-api.
Quick start
from openmed import process_batch
texts = ["Patient has type 2 diabetes.", "No acute distress. BP 120/80."]
result = process_batch(texts, model_name="disease_detection_superclinical")
print(result.summary()) # PHI-safe counts + timing
print(result.successful_items, "/", result.total_items)
for item in result.get_successful_results():
print(item.id, item.result.to_dict()["entities"]) # spans only; avoid raw text in logs
process_batch(...) is a thin wrapper over BatchProcessor. Real signatures
(openmed/processing/batch.py):
process_batch(texts, model_name="disease_detection_superclinical", ids=None, config=None, progress_callback=None, on_progress=None, **kwargs) -> BatchResultBatchProcessor(model_name=..., operation="analyze_text", batch_size=8, continue_on_error=True, **analyze_kwargs)withoperation β {"analyze_text", "extract_pii", "deidentify"}.BatchItem(id, text, source=None, metadata=None)BatchResultβ.items,.total_items,.successful_items,.failed_items,.success_rate,.average_processing_time,.summary(),.to_dict(),.get_successful_results(),.get_failed_results().BatchItemResultβ.id,.result(aPredictionResult/DeidentificationResult),.error,.processing_time,.source,.success,.to_dict().
Choosing the operation
from openmed import BatchProcessor
# NER (default)
ner = BatchProcessor(model_name="disease_detection_superclinical") # operation="analyze_text"
# Detect PHI spans
pii = BatchProcessor(operation="extract_pii", model_name="OpenMed/OpenMed-PII-SuperClinical-Small-44M-v1")
# De-identify (rewrites text)
deid = BatchProcessor(operation="deidentify", method="mask", confidence_threshold=0.7)
BatchProcessor reuses one model loader across items (and a cached privacy
filter for PII ops), so a single processor over many texts is far cheaper than
many one-off calls.
Streaming + PHI-safe progress
from openmed.processing import BatchProcessor, BatchProgress
proc = BatchProcessor(operation="deidentify", method="mask", batch_size=16)
def on_progress(p: BatchProgress) -> None: # frozen record: completed/total/current_index/elapsed
if p.completed % 500 == 0:
print(f"{p.completed}/{p.total} ({p.elapsed:.1f}s)") # NO PHI
for item in proc.iter_process(texts, ids=doc_ids, on_progress=on_progress):
write_jsonl(item) # one result at a time β constant memory for huge corpora
on_progress receives only counts/timing (never text), so it is safe to log.
iter_process yields BatchItemResults without holding the whole corpus.
Workflow
- De-identify upstream if the corpus has PHI, or key everything by stable
internal
idsso logs/output never carry identifiers. - Pick the operation + model β one
BatchProcessorperoperation(analyze_text/extract_pii/deidentify); reuse it across all items so the loader is shared. - Shard the corpus into independent partitions writing to separate JSONL files; run shards as separate processes for parallelism.
- Stream with
iter_processand append eachBatchItemResultto JSONL (flush per item) β that append-only file is your checkpoint. - Track progress with the PHI-safe
on_progresscallback (counts/timing only). - Re-run to resume: skip ids already present in the output; with
continue_on_error=True, failures are recorded, not raised. - Reconcile via
result.get_failed_results()/ a failures pass, then hand JSONL to the downstream consumer.
A resumable batch runner
import json
from pathlib import Path
from openmed.processing import BatchProcessor
def run_resumable(texts, ids, out_path: Path, *, operation="deidentif
FAQ
Does the data leave my computer?
No. The corpus, model and output all stay on the host.
What happens if one document fails?
The batch isolates errors per item, so one bad document does not stop the whole run.
Is a single note simpler?
Yes. For one note, the direct analysis or de-identification calls are the better fit.
Details
Original description by the author
Run large-scale batch NER, PII extraction, or de-identification over many clinical notes on-device with OpenMed, with sharding, checkpointing, resumability, and append-only JSONL output. Use when the user needs to process a corpus or folder of notes, de-identify a dataset, run NER over thousands of documents, build a resumable batch pipeline, or stream results to JSONL without holding everything in memory. Covers process_batch / BatchProcessor / BatchItem / BatchResult, the operation= selector (analyze_text | extract_pii | deidentify), iter_process streaming, the PHI-safe on_progress callback,
repo: maziyarpanahi/openmed
Popularity
- GitHub stars
- 5.8k
- Ranking position
- #14674
- License
- Apache-2.0
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
annotating-variants
5.8kHelps your agent predict what a genetic variant does, convert HGVS names to genome positions and attach population frequencies, using free public annotators.
ask-openmed
5.8kHelps your agent pick the right OpenMed workflow for a clinical text request, starting with a privacy check whenever patient data may be present.
assembling-fhir-bundles
5.8kPackages several FHIR health records into one transaction Bundle ready to send to an EHR, with the internal references linked correctly.
auditing-deid-leakage
5.8kScans de-identified clinical text for leftover identifiers such as SSNs, card numbers, emails and dates, and blocks release if any remain.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.