benchmarking-clinical-ner
できること
このスキルは、人が注釈した正解コーパスに対して、臨床またはバイオメディカルのNERモデルを採点します。エンティティ単位の正直な数値と、誤りの説明が必要なチーム向けです。
使う場面
- ✓自分の正解付きデータに対して、NERモデルのエンティティ単位の成績表がほしいとき。
- ✓厳密な一致と部分一致の結果を並べて見たいとき。
- ✓モデルがどのラベルを見逃しやすいか、どれを混同しやすいかを知りたいとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/benchmarking-clinical-ner/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“臨床NERモデルを、当社の注釈付きテストセットに対して採点し、ラベルごとの適合率、再現率、F1を示してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、予測されたスパンを厳密な規則と緩やかな規則の両方で正解のスパンと照合し、エンティティ単位の指標を計算します。ラベルごとの内訳と誤りの例を示します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Benchmarking Clinical NER
This skill produces an honest entity-level scorecard for an OpenMed NER model: precision / recall / F1 plus a per-label error breakdown. It scores spans, not tokens, because clinical entities are multi-token ("type 2 diabetes mellitus") and token-level accuracy hides boundary errors. Reported numbers are entity-level in the seqeval tradition (CoNLL-2000 / SemEval-2013 families).
When to use this skill
- You have a gold-annotated clinical corpus and an OpenMed NER model to score.
- You want strict (exact-boundary) and partial (relaxed-overlap) span F1.
- You need per-label numbers, not one aggregate — DRUG recall ≠ DISEASE recall.
- You need to explain the errors: what was missed, what was spurious, what was mislabeled.
For PHI de-id specifically, gate on leakage with evaluating-with-leakage-gates
instead of (or in addition to) F1.
Match modes
| Mode | Counts a hit when… | Use for |
|---|---|---|
| Strict / exact | predicted span boundaries and label match gold exactly | release scoring, boundary-sensitive tasks |
| Partial / relaxed | predicted span overlaps gold with the right label | recall-oriented triage, tokenizer-mismatch tolerance |
OpenMed exposes both: compute_exact_span_f1 (strict) and
compute_relaxed_span_f1 (partial), with the full bundle in
compute_metrics_bundle.
Quick start
Run a model over a user-supplied gold fixtures file and print a scorecard:
from openmed.eval import run_suite, error_report
# Fixtures: JSON list of {"id", "text", "gold_spans": [{start, end, label}, ...]}
report = run_suite(
"eval/gold/clinical_ner.json", # YOUR gold corpus, not bundled
suite="golden",
model_name="OpenMed/Disease-Detection",
device="cpu",
)
m = report.metrics
print("exact F1 :", m["exact_span_f1"]["f1"]) # strict
print("relaxed F1:", m["relaxed_span_f1"]["f1"]) # partial
print("recall by label:", m["recall_slices"]["by_label"])
# Per-label confusion matrix + capped, no-PHI error examples.
errors = error_report(
"OpenMed/Disease-Detection",
"eval/gold/clinical_ner.json",
suite_name="clinical_ner",
example_cap=5,
)
print(errors.to_markdown()) # confusion matrix + FN/FP tables
errors.write_json("eval/out/error_analysis.json")
Need just the metrics on spans you already have? Call the metric functions directly:
from openmed.eval import compute_exact_span_f1, compute_relaxed_span_f1
strict = compute_exact_span_f1(gold_spans, predicted_spans)
partial = compute_relaxed_span_f1(gold_spans, predicted_spans)
Workflow
- Align the corpus to OpenMed fixtures. Convert CoNLL/BIO or BRAT
standoff into the fixture shape:
text+gold_spansof{start, end, label}character offsets. (CoNLL → offsets; BRAT.annis already character offsets.) - Normalize labels to OpenMed's canonical set so DRUG/MEDICATION variants don't count as label confusion. Mislabeled-but-overlapping spans show up in the confusion matrix, not as misses.
- Run
run_suite/run_benchmarkto get aBenchmarkReport. - Read both F1s. A large strict↓ / relaxed↑ gap means boundary errors, not detection failures — often tokenizer or whitespace issues.
- Run
error_reportfor the per-label confusion matrix and capped examples.MISSED= false negatives (recall problem);SPURIOUS= false positives (precision problem); off-diagonal = label confusion. - Triage per label. Fix the worst-recall label first; in clinical NER a few labels usually dominate the error budget.
Hand-off to / from OpenMed
- From
extracting-clinical-entities(openmed.analyze_text): the model and predictions you score here come from the NER pipeline. - To
evaluating-with-leakage-gates: for de-id models, F1 is necessary but not sufficient — pass the same fixtures through the release gates. - To
authoring-model-cards: droperror_reportconfusion matrices and per-label F1 straight into the model card's quantitative-analysis section. - Pairs with
building-gold-corpus(supplies the fixtures) andauditing-subgroup-fairness(slices the same run by demographic group).
Edge cases & gotchas
- Token F1 lies; report span F1. Always use the span metrics
(
compute_exact_span_f1/compute_relaxed_span_f1), not token accuracy. - Overlapping/nested gold spans need a documented matching rule. OpenMed's m
よくある質問
単語単位で採点しますか?
いいえ。エンティティのスパン全体で採点します。複数語の臨床用語では、単語単位だと境界の誤りが隠れてしまうためです。
自分の正解コーパスが必要ですか?
はい。注釈付きのコーパスは利用者が用意します。スキル自体はデータを持ちません。
厳密と部分の違いは?
厳密は境界が正確で、正しいラベルであることを求めます。部分は正しいラベルで重なっていれば数えます。
詳細
作者による元の説明
Score an OpenMed clinical or biomedical NER model against a user-supplied gold corpus with entity-level precision, recall, and F1, then break errors down per label. Use when the user wants a seqeval-style scorecard, strict vs partial (relaxed) span matching, a per-label confusion matrix, false-negative / false-positive examples, or to debug why a model misses entities. Trigger on \"evaluate NER\", \"entity-level F1\", \"seqeval\", \"precision recall F1\", \"confusion matrix\", \"error analysis\", \"strict vs partial match\", or \"score against gold\" in an OpenMed context. The gold corpus is u
repo: maziyarpanahi/openmed
人気
- GitHubのスター
- 5.8k
- ランキング
- #14676
- ライセンス
- 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、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。