loading-openmed-models
できること
このスキルは、OpenMedの臨床モデルを、一度だけダウンロードし、効率よく再利用し、オフラインで実行する方法を示します。多くの分析を実行し、モデルの読み込みを繰り返したくない開発者向けです。
使う場面
- ✓多くのNERの呼び出しを行うので、モデルを一度だけ読み込みたいとき。
- ✓モデルをキャッシュする場所や、CPUとGPUのどちらで動かすかを制御したいとき。
- ✓ロックダウンされた環境やオフラインの環境で、一度のダウンロードの後にモデルを動かす必要があるとき。
スキルのリンク
https://github.com/maziyarpanahi/openmed/blob/master/skills/loading-openmed-models/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“OpenMedの臨床モデルを一度だけ読み込み、プロジェクトのフォルダーにキャッシュし、安全なサーバー上でオフラインで動かしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、レジストリのキーやローカルのディレクトリのパスなど、モデル名の形式を選び、モデルを一度キャッシュにダウンロードして、呼び出しをまたいで読み込んだモデルを再利用します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Loading OpenMed Models
OpenMed models download once from the Hugging Face Hub into a local cache, then run fully on-device — no network, no telemetry. This skill covers how to load a model, reuse it across many calls without reloading weights, point at a local copy, and run offline.
When to use
- You are about to run NER repeatedly and want to load the model once.
- You need to control where weights are cached (
cache_dir) or force CPU/GPU. - You must run offline in a locked-down or air-gapped environment.
- You are choosing between a registry key, a full HF id, or a local directory.
For which model to load, see choosing-openmed-models. To actually run it, see
extracting-clinical-entities.
Install
pip install "openmed[hf]" # adds Hugging Face transformers + hub download
The three ways to name a model
analyze_text, extract_pii, load_model, and ModelLoader.load_model all
accept the same model_name in three forms:
| Form | Example | Notes |
|---|---|---|
| Registry key | "disease_detection_superclinical" |
Short, resolved via the bundled registry. |
| Full HF id | "OpenMed/OpenMed-NER-DiseaseDetect-BigMed-278M" |
Anything org/name; downloaded from the Hub. |
| Local path | "/models/my-openmed-ner" |
An existing directory; loaded with local_files_only=True. |
A bare name without / is prefixed with the default org (OpenMed). An existing
local path is detected automatically and never hits the network.
Quick start: load and reuse a loader
The single most important pattern — build one ModelLoader, pass it everywhere.
The loader caches models, tokenizers, and pipelines in memory, so the second call
is instant.
import openmed
from openmed import ModelLoader, OpenMedConfig
# One loader, reused across calls. Weights load on the first call only.
loader = ModelLoader()
notes = [
"Patient prescribed 500 mg metformin for type 2 diabetes.",
"History of myocardial infarction; started on atorvastatin.",
]
for note in notes:
result = openmed.analyze_text(
note,
model_name="disease_detection_superclinical",
loader=loader, # <-- reuse; no reload on subsequent calls
output_format="dict",
)
print(result.entities)
Without loader=, each analyze_text call constructs a fresh ModelLoader. The
underlying Hugging Face cache still prevents re-downloads, but you pay to
re-instantiate the pipeline — avoid that in loops and services.
Load weights directly
When you want the raw model/tokenizer (e.g. to inspect config or build a custom pipeline):
from openmed import load_model
bundle = load_model("disease_detection_superclinical")
model = bundle["model"]
tokenizer = bundle["tokenizer"]
config = bundle["config"]
load_model(model_name, config=None, **kwargs) is a thin convenience wrapper that
builds a ModelLoader and calls loader.load_model(...). For reuse, prefer
constructing the loader yourself:
loader = ModelLoader()
bundle = loader.load_model("disease_detection_superclinical")
# Second call returns the cached bundle (no reload):
bundle2 = loader.load_model("disease_detection_superclinical")
# Force a fresh load if you replaced files on disk:
fresh = loader.load_model("disease_detection_superclinical", force_reload=True)
Configure the cache, device, and org
OpenMedConfig is a dataclass. Pass it to ModelLoader(config=...).
from openmed import ModelLoader, OpenMedConfig
config = OpenMedConfig(
cache_dir="/data/openmed-cache", # default: ~/.cache/openmed
device="cpu", # None = auto-detect
default_org="OpenMed", # prepended to bare model names
hf_token=None, # or set env HF_TOKEN for private repos
)
loader = ModelLoader(config)
Relevant OpenMedConfig fields: cache_dir, device, default_org, hf_token,
timeout (default 300s), backend (None auto / "hf" / "mlx"), log_level.
hf_token falls back to the HF_TOKEN environment variable.
First-run download, then fully offline
- First run (online): the model is fetched from the Hub into
cache_dir. - Every run after: transformers serves from cache with no network call.
To guarantee no network access (air-gapped, CI, PHI environments), set the standard Hugging Face offline switch before importing:
export HF_HUB_OFFLINE=1
export TRANSFORMERS_O
よくある質問
実行時にインターネット接続は必要ですか?
いいえ。一度のダウンロードの後は、モデルは完全に端末上で動きます。
どのモデル名の形式を受け付けますか?
レジストリのキー、完全なHugging FaceのID、またはローカルのディレクトリのパスを受け付けます。
追加のインストールは必要ですか?
はい。モデルのダウンロードのサポートは、Hugging Faceの拡張が提供します。
詳細
作者による元の説明
Load OpenMed clinical/biomedical NER models from the Hugging Face Hub or a local path and reuse them efficiently across calls. Use when the user wants to load an OpenMed model, control the model cache, run fully offline after a one-time download, reuse a ModelLoader to avoid reloading, set a cache_dir or device, or pick between a registry key, a full Hugging Face id, and a local directory. Pairs with choosing-openmed-models (pick the model) and extracting-clinical-entities (run it).
repo: maziyarpanahi/openmed
人気
- GitHubのスター
- 5.8k
- ランキング
- #14710
- ライセンス
- 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、カード番号、メール、日付など)をスキャンし、残っていれば公開を止めます。