Agent Skillsmaziyarpanahi/openmed › running-zeroshot-ner

running-zeroshot-ner

GitHub

用于在临床或生物医学文本中进行零样本命名实体识别,支持运行时自定义标签且无需微调。通过OpenMed封装GLiNER模型,提供CLI和Python API,适用于无标注数据或动态标签场景。

skills/running-zeroshot-ner/SKILL.md maziyarpanahi/openmed

Trigger Scenarios

用户需要提取自定义或非标准实体的标签 用户没有标注数据无法进行模型微调 用户询问openmed zero、gliner相关依赖或推理命令

Install

npx skills add maziyarpanahi/openmed --skill running-zeroshot-ner -g -y
More Options

Use without installing

npx skills use maziyarpanahi/openmed@running-zeroshot-ner

指定 Agent (Claude Code)

npx skills add maziyarpanahi/openmed --skill running-zeroshot-ner -a claude-code -g -y

安装 repo 全部 skill

npx skills add maziyarpanahi/openmed --all -g -y

预览 repo 内 skill

npx skills add maziyarpanahi/openmed --list

SKILL.md

Frontmatter
{
    "name": "running-zeroshot-ner",
    "license": "Apache-2.0",
    "metadata": {
        "pairs": "adjacent",
        "project": "OpenMed",
        "version": "1.0",
        "category": "openmed-core"
    },
    "description": "Extract arbitrary, custom entity types from clinical or biomedical text with no fine-tuning using OpenMed's GLiNER \/ GLiNER2 zero-shot support. Use when the user wants to define their own labels on the fly (e.g. Drug, Symptom, Device, Procedure), has no labelled data or a label set not covered by a fine-tuned model, or asks about openmed zero deps\/index\/infer, the gliner extra, or GLiNER. Pairs adjacent to extracting-clinical-entities (use that for high-accuracy fixed-schema NER) and loading-openmed-models."
}

Running Zero-Shot NER

Zero-shot NER lets you extract entity types you name at inference time — no training, no labelled data. OpenMed wraps GLiNER (v1) and GLiNER2 behind a small index + inference layer, exposed via the openmed zero CLI and the openmed.ner Python API. It runs on-device.

When to use

  • Your label set is custom or evolving ("Device", "Implant", "Allergen") and no fine-tuned OpenMed model emits exactly those labels.
  • You have no labelled data to fine-tune with.
  • You need a quick prototype or a one-off extraction over an unusual schema.

When to prefer a fine-tuned model instead (extracting-clinical-entities): for a fixed, well-supported schema (diseases, drugs, anatomy), a fine-tuned OpenMed model is more accurate and faster than zero-shot. Zero-shot trades some accuracy for total label flexibility — use it for coverage of new types, then graduate to a fine-tuned model once the schema stabilises.

Install

pip install "openmed[gliner]"   # pulls GLiNER (and GLiNER2 if a recent gliner is installed)
openmed zero deps               # diagnostic: prints "GLiNER v1: ok" / "GLiNER v2: ok"

openmed zero deps only checks availability — it does not install anything.

The two-step workflow: index, then infer

GLiNER checkpoints live as local model directories. OpenMed resolves them by a short model_id via an index.json, so you build the index once and run inference many times.

  1. openmed zero index <models_dir> — scan a directory of downloaded GLiNER / GLiNER2 checkpoints and write index.json (model ids, family, domains, paths).
  2. openmed zero infer "<text>" --model-id <id> — run extraction against a model from the index, with labels you supply.
# 1) Build the index over your local models (writes <models_dir>/index.json)
openmed zero index /models/gliner --output /models/gliner/index.json

# 2) Run zero-shot NER with your OWN labels (comma-separated)
openmed zero infer "Patient on insulin glargine via an insulin pump for type 1 diabetes." \
  --model-id gliner-biomedical \
  --labels "Drug,Device,Disease" \
  --threshold 0.5 \
  --index-path /models/gliner/index.json

Output is JSON: each entity has text, start, end, label, and score.

CLI flags:

  • zero infer: positional text; --model-id/-m (required, an id from the index), --labels/-l (comma-separated custom labels), --domain/-d (label preset hint), --threshold/-c (default 0.5), --index-path/-i.
  • zero index: positional models_dir; --output/-o, --pretty/--compact.

If you omit --labels, OpenMed falls back to the --domain defaults (or generic defaults). Passing explicit --labels is what makes it truly zero-shot.

Python API

The same flow in code via openmed.ner:

from openmed.ner import infer, NerRequest

request = NerRequest(
    model_id="gliner-biomedical",          # id from your index.json
    text="Started on insulin glargine via an insulin pump for type 1 diabetes.",
    labels=["Drug", "Device", "Disease"],  # your custom labels — no fine-tuning
    threshold=0.5,
)
response = infer(request, index_path="/models/gliner/index.json")

for ent in response.entities:
    print(f"{ent.label:8} {ent.text!r:30} {ent.score:.2f} [{ent.start}:{ent.end}]")

NerRequest fields: model_id, text, labels (None ⇒ domain/default labels), domain, threshold. infer(...) returns a NerResponse whose .entities are Entity objects with .text, .start, .end, .label, .score.

Build / load the index from Python too:

from openmed.ner import build_index, write_index, load_index, is_gliner_available

if is_gliner_available():
    index = build_index("/models/gliner")
    write_index(index, "/models/gliner/index.json")
    index = load_index("/models/gliner/index.json")

Helpful label utilities:

from openmed.ner import get_default_labels, available_domains
available_domains()              # domains with built-in label presets
get_default_labels("clinical")   # default labels for a domain hint

Writing good labels

Zero-shot quality hinges on label phrasing. Prefer natural, specific noun phrases:

  • Good: ["Drug", "Medical Device", "Disease", "Symptom", "Procedure"]
  • Weak: ["X", "thing", "misc"]

Tune threshold to trade recall for precision. Start at 0.5 and raise it if you see spurious spans.

Hand-off to / from OpenMed

  • From loading-openmed-models: zero-shot uses local GLiNER checkpoints rather than the OpenMed registry; download them once, then point zero index at the directory.
  • To extracting-clinical-entities: once your label schema stabilises and a fine-tuned OpenMed model covers it, switch to openmed.analyze_text for higher accuracy and speed. The output shape (label + offsets + score) is parallel, so downstream code changes little.
  • To de-identification: run openmed.deidentify before zero-shot NER in a PHI workflow, then extract entities from the redacted text.

Edge cases & gotchas

  • zero infer needs an index. Run zero index <models_dir> first, or pass a valid --index-path; the --model-id must exist in that index.
  • zero deps doesn't install. It reports status only — install with pip install "openmed[gliner]".
  • GLiNER2 needs a recent gliner (≈0.3.0+) and a GLiNER2/Fastino checkpoint; openmed zero deps shows whether v2 is available.
  • Accuracy vs. flexibility. Zero-shot is for coverage of new/custom types, not for squeezing out maximum F1 on a standard schema.
  • Permissive licensing & local-first. Use permissively licensed GLiNER checkpoints; keep everything on-device and out of PHI logs.

Standards & references

Version History

  • f213557 Current 2026-07-23 00:46

Same Skill Collection

skills/benchmark-pii-recall/SKILL.md
skills/building-with-openmed/SKILL.md
skills/deidentify-a-dataset/SKILL.md
skills/extract-clinical-entities-to-fhir/SKILL.md
skills/loading-openmed-models/SKILL.md
skills/pick-a-pii-model/SKILL.md
skills/annotating-variants/SKILL.md
skills/assembling-fhir-bundles/SKILL.md
skills/auditing-deid-leakage/SKILL.md
skills/auditing-deidentification-runs/SKILL.md
skills/auditing-part11-trails/SKILL.md
skills/auditing-safe-harbor-checklist/SKILL.md
skills/auditing-subgroup-fairness/SKILL.md
skills/authoring-model-cards/SKILL.md
skills/batch-processing-clinical-text/SKILL.md
skills/benchmarking-clinical-ner/SKILL.md
skills/bridging-presidio-and-spacy/SKILL.md
skills/building-gold-corpus/SKILL.md
skills/building-patient-timelines/SKILL.md
skills/checking-hipaa-compliance/SKILL.md
skills/choosing-openmed-models/SKILL.md
skills/coding-hcc-risk-adjustment/SKILL.md
skills/coding-icd10/SKILL.md
skills/computing-ecqms/SKILL.md
skills/configuring-privacy-policies/SKILL.md
skills/defining-cohort-phenotypes/SKILL.md
skills/deidentifying-clinical-text/SKILL.md
skills/deidentifying-multilingual-text/SKILL.md
skills/deploying-openmed-mcp/SKILL.md
skills/detecting-pv-signals/SKILL.md
skills/enforcing-nophi-logging/SKILL.md
skills/etl-to-omop-cdm/SKILL.md
skills/evaluating-with-leakage-gates/SKILL.md
skills/exporting-bulk-fhir/SKILL.md
skills/exporting-to-fhir/SKILL.md
skills/extracting-clinical-entities/SKILL.md
skills/extracting-dicom-metadata/SKILL.md
skills/extracting-lab-tables/SKILL.md
skills/extracting-pii-entities/SKILL.md
skills/extracting-sdoh/SKILL.md
skills/fetching-fhir-resources/SKILL.md
skills/gating-deid-leakage/SKILL.md
skills/generating-synthea-data/SKILL.md
skills/generating-synthetic-surrogates/SKILL.md
skills/ingesting-clinical-documents/SKILL.md
skills/linking-umls-concepts/SKILL.md
skills/mapping-loinc/SKILL.md
skills/mapping-to-snomed/SKILL.md
skills/mining-pubmed-literature/SKILL.md
skills/normalizing-rxnorm/SKILL.md

Metadata

Files
0
Version
de90aba
Hash
f8ee59e6
Indexed
2026-07-23 00:46

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-04 03:16
浙ICP备14020137号-1 $Гость$