batch-processing-clinical-text
できること
このスキルは、臨床ノートの大量のコレクションを、自分のマシン上でバッチ処理します。進捗の追跡と保存されたチェックポイントがあります。何千もの文書に対して、エンティティ抽出や匿名化を行うチーム向けです。
使う場面
- ✓一つのノートではなく、臨床ノートのフォルダーやデータセット全体を処理する必要があるとき。
- ✓中断後に再開できる、長いバッチ処理が必要なとき。
- ✓すべてをメモリに保持せず、結果を追記型のJSONLファイルに書き出したいとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/batch-processing-clinical-text/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“このフォルダーにある5,000件の退院ノートを、私のコンピューター上で匿名化してください。途中で止まったら再開できるようにしてください。”
毎週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エージェントが、匿名化済みの臨床テキストに残っている識別子(SSN、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。