Text Generation
Transformers
Safetensors
English
phi3
Merge
mergekit
medical
clinical
conversational
text-generation-inference
Instructions to use microsoft/MediPhi-MedCode with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/MediPhi-MedCode with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="microsoft/MediPhi-MedCode") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("microsoft/MediPhi-MedCode") model = AutoModelForCausalLM.from_pretrained("microsoft/MediPhi-MedCode") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use microsoft/MediPhi-MedCode with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/MediPhi-MedCode" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/MediPhi-MedCode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/microsoft/MediPhi-MedCode
- SGLang
How to use microsoft/MediPhi-MedCode with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "microsoft/MediPhi-MedCode" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/MediPhi-MedCode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "microsoft/MediPhi-MedCode" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/MediPhi-MedCode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use microsoft/MediPhi-MedCode with Docker Model Runner:
docker model run hf.co/microsoft/MediPhi-MedCode
Update README.md
Browse files
README.md
CHANGED
|
@@ -193,14 +193,34 @@ This project may contain trademarks or logos for projects, products, or services
|
|
| 193 |
|
| 194 |
## Citation
|
| 195 |
|
| 196 |
-
@
|
| 197 |
-
title=
|
| 198 |
-
author=
|
| 199 |
-
|
| 200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
}
|
| 202 |
|
| 203 |
-
|
| 204 |
## Model Card Authors
|
| 205 |
|
| 206 |
Jean-Philippe Corbeil
|
|
|
|
| 193 |
|
| 194 |
## Citation
|
| 195 |
|
| 196 |
+
@inproceedings{corbeil-etal-2025-modular,
|
| 197 |
+
title = "A Modular Approach for Clinical {SLM}s Driven by Synthetic Data with Pre-Instruction Tuning, Model Merging, and Clinical-Tasks Alignment",
|
| 198 |
+
author = "Corbeil, Jean-Philippe and
|
| 199 |
+
Dada, Amin and
|
| 200 |
+
Attendu, Jean-Michel and
|
| 201 |
+
Ben Abacha, Asma and
|
| 202 |
+
Sordoni, Alessandro and
|
| 203 |
+
Caccia, Lucas and
|
| 204 |
+
Beaulieu, Francois and
|
| 205 |
+
Lin, Thomas and
|
| 206 |
+
Kleesiek, Jens and
|
| 207 |
+
Vozila, Paul",
|
| 208 |
+
editor = "Che, Wanxiang and
|
| 209 |
+
Nabende, Joyce and
|
| 210 |
+
Shutova, Ekaterina and
|
| 211 |
+
Pilehvar, Mohammad Taher",
|
| 212 |
+
booktitle = "Proceedings of the 63rd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers)",
|
| 213 |
+
month = jul,
|
| 214 |
+
year = "2025",
|
| 215 |
+
address = "Vienna, Austria",
|
| 216 |
+
publisher = "Association for Computational Linguistics",
|
| 217 |
+
url = "https://aclanthology.org/2025.acl-long.950/",
|
| 218 |
+
doi = "10.18653/v1/2025.acl-long.950",
|
| 219 |
+
pages = "19352--19374",
|
| 220 |
+
ISBN = "979-8-89176-251-0",
|
| 221 |
+
abstract = "High computation costs and latency of large language models such as GPT-4 have limited their deployment in clinical settings. Small language models (SLMs) offer a cost-effective alternative, but their limited capacity requires biomedical domain adaptation, which remains challenging. An additional bottleneck is the unavailability and high sensitivity of clinical data. To address these challenges, we propose a novel framework for adapting SLMs into high-performing clinical models. We introduce the MediPhi collection of 3.8B-parameter SLMs developed with our novel framework: pre-instruction tuning of experts on relevant medical and clinical corpora (PMC, Medical Guideline, MedWiki, etc.), model merging, and clinical-tasks alignment. To cover most clinical tasks, we extended the CLUE benchmark to CLUE+, doubling its size. Our expert models deliver relative improvements on this benchmark over the base model without any task-specific fine-tuning: 64.3{\%} on medical entities, 49.5{\%} on radiology reports, and 44{\%} on ICD-10 coding (outperforming GPT-4-0125 by 14{\%}). We unify the expert models into MediPhi via model merging, preserving gains across benchmarks. Furthermore, we built the MediFlow collection, a synthetic dataset of 2.5 million high-quality instructions on 14 medical NLP tasks, 98 fine-grained document types, and JSON format support. Alignment of MediPhi using supervised fine-tuning and direct preference optimization achieves further gains of 18.9{\%} on average."
|
| 222 |
}
|
| 223 |
|
|
|
|
| 224 |
## Model Card Authors
|
| 225 |
|
| 226 |
Jean-Philippe Corbeil
|