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 건강 기록을 EHR로 보낼 수 있도록 하나의 트랜잭션 Bundle로 묶고, 내부 참조를 올바르게 연결하도록 에이전트를 돕습니다.
auditing-deid-leakage
5.8k비식별화된 임상 텍스트에 남은 SSN, 카드 번호, 이메일, 날짜 같은 식별자를 검사하고, 남은 것이 있으면 공개를 막도록 돕습니다.