batch-processing-clinical-text
它能做什么
这项技能在你自己的机器上分批处理大量临床记录,并提供进度跟踪和保存的检查点。适合拥有数千份文档、需要大规模实体提取或去标识化的团队。
适用场景
- ✓当你需要处理一个文件夹或数据集中的临床记录,而不是单份记录的时候。
- ✓当你需要一个可在中断后恢复的长时间批处理任务的时候。
- ✓当你希望结果写入 JSONL 输出文件,而不必把所有内容都保存在内存中的时候。
技能链接
https://github.com/maziyarpanahi/openmed/blob/master/skills/batch-processing-clinical-text/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在我的电脑上对这个文件夹中的 5000 份出院记录进行去标识化,如果任务中途停止,让我可以继续。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会把语料库拆分为多个分片,用本地模型处理每份记录,记录检查点,并把结果写入只追加的文件,重启后可以继续。
技术内容(原始 SKILL.md)
作者在 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
常见问题
数据会离开我的电脑吗?
不会。语料库、模型和输出都保存在本机。
如果某份文档出错会怎样?
批处理会按条目隔离错误,因此一份有问题的文档不会中止整个任务。
只处理一份记录时怎么办?
那就更简单。对于单份记录,直接的分析或去标识化调用是更合适的选择。
详情
作者的原始描述
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
热度
- GitHub 星标
- 5.8k
- 排名
- #14674
- 许可证
- Apache-2.0
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
annotating-variants
5.8k帮你的智能体预测基因变异的作用,把 HGVS 名称转换为基因组位置,并使用免费的公共注释工具添加人群频率。
ask-openmed
5.8k帮你的智能体为临床文本请求选择合适的 OpenMed 工作流程,并在可能涉及患者数据时,先进行隐私检查。
assembling-fhir-bundles
5.8k把多份 FHIR 健康记录打包成一个事务 Bundle,可直接发送给 EHR 系统,并正确链接其中的内部引用。
auditing-deid-leakage
5.8k扫描已去标识化的临床文本,查找残留的标识符,例如社会安全号、银行卡号、电子邮件地址和日期,若仍有残留则阻止发布。