Instructions to use Namirah07/OpenBioLLM-G-ICD10 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Namirah07/OpenBioLLM-G-ICD10 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("aaditya/Llama3-OpenBioLLM-8B") model = PeftModel.from_pretrained(base_model, "Namirah07/OpenBioLLM-G-ICD10") - Transformers
How to use Namirah07/OpenBioLLM-G-ICD10 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Namirah07/OpenBioLLM-G-ICD10")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Namirah07/OpenBioLLM-G-ICD10", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Namirah07/OpenBioLLM-G-ICD10 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Namirah07/OpenBioLLM-G-ICD10" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Namirah07/OpenBioLLM-G-ICD10", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Namirah07/OpenBioLLM-G-ICD10
- SGLang
How to use Namirah07/OpenBioLLM-G-ICD10 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 "Namirah07/OpenBioLLM-G-ICD10" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Namirah07/OpenBioLLM-G-ICD10", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "Namirah07/OpenBioLLM-G-ICD10" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Namirah07/OpenBioLLM-G-ICD10", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Namirah07/OpenBioLLM-G-ICD10 with Docker Model Runner:
docker model run hf.co/Namirah07/OpenBioLLM-G-ICD10
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,189 +1,62 @@
|
|
| 1 |
---
|
| 2 |
-
language: en
|
| 3 |
-
license: mit
|
| 4 |
-
tags:
|
| 5 |
-
- medical
|
| 6 |
-
- icd-10
|
| 7 |
-
- clinical-nlp
|
| 8 |
-
- mimic-iv
|
| 9 |
-
- llama
|
| 10 |
-
- lora
|
| 11 |
-
- generative
|
| 12 |
-
- sft
|
| 13 |
-
- text-generation
|
| 14 |
base_model: aaditya/Llama3-OpenBioLLM-8B
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
pipeline_tag: text-generation
|
| 18 |
---
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
Trained as part of the Master's thesis:
|
| 23 |
-
**"Enhancing Automated ICD-10 Medical Coding with Large Language Models"**
|
| 24 |
-
California State University, Sacramento
|
| 25 |
-
Author: Namirah Imtieaz Shaik
|
| 26 |
-
Advisor: Dr. Haiquan Chen
|
| 27 |
-
|
| 28 |
-
---
|
| 29 |
-
|
| 30 |
-
## Model Description
|
| 31 |
-
|
| 32 |
-
OpenBioLLM-G is a generative ICD-10 medical coding model built on top of
|
| 33 |
-
Llama3-OpenBioLLM-8B. Unlike the discriminative version (OpenBioLLM-D),
|
| 34 |
-
it generates the ICD-10 code autoregressively as a text string by completing
|
| 35 |
-
a structured clinical prompt.
|
| 36 |
-
|
| 37 |
-
**Architecture:**
|
| 38 |
-
- Backbone: aaditya/Llama3-OpenBioLLM-8B (full causal LM with generation head)
|
| 39 |
-
- LoRA: r=16, alpha=32, task_type=CAUSAL_LM
|
| 40 |
-
- Training method: Supervised Fine-Tuning (SFT) with TRL SFTTrainer
|
| 41 |
-
- Quantization: QLoRA 4-bit NF4 during training to fit 8B model on single GPU
|
| 42 |
-
|
| 43 |
-
**Key Design Choices:**
|
| 44 |
-
- Tail-only supervision: loss computed only on the last 16 ICD completion tokens,
|
| 45 |
-
not on the system prompt or clinical note
|
| 46 |
-
- Head+tail note cropping: 40% from note start, 60% from note end
|
| 47 |
-
- Constrained decoding at inference: prefix trie forces valid ICD codes only
|
| 48 |
-
|
| 49 |
-
**Prompt Format:**
|
| 50 |
-
|
| 51 |
-
[SYSTEM]
|
| 52 |
-
You are a medical coding assistant. Given a clinical note, you output
|
| 53 |
-
the most accurate ICD-10 code. Respond with only the ICD-10 code,
|
| 54 |
-
no extra text.
|
| 55 |
-
[/SYSTEM]
|
| 56 |
-
[USER]
|
| 57 |
-
<discharge note cropped to fit 512 token budget>
|
| 58 |
-
[/USER]
|
| 59 |
-
[ICD]
|
| 60 |
-
ICD-10 code: <model generates here>
|
| 61 |
-
|
| 62 |
-
**Training Details:**
|
| 63 |
-
- Dataset: MIMIC-IV discharge summaries
|
| 64 |
-
- Train / Val / Test: 16,540 / 2,068 / 2,068 examples
|
| 65 |
-
- Optimizer: AdamW with cosine LR schedule and 5% warmup
|
| 66 |
-
- Epochs: 3 with early stopping on macro F1
|
| 67 |
-
|
| 68 |
-
---
|
| 69 |
-
|
| 70 |
-
## Results
|
| 71 |
-
|
| 72 |
-
| Metric | Score |
|
| 73 |
-
|---|---|
|
| 74 |
-
| Micro F1 | 0.7896 |
|
| 75 |
-
| ROC-AUC (Weighted OVR) | 0.8897 |
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
rather than real softmax class probabilities, making it less directly comparable
|
| 82 |
-
to the discriminative model ROC-AUC scores.
|
| 83 |
-
|
| 84 |
-
---
|
| 85 |
-
|
| 86 |
-
## How to Load and Use
|
| 87 |
|
| 88 |
```python
|
| 89 |
-
from transformers import
|
| 90 |
-
from peft import PeftModel
|
| 91 |
-
import torch
|
| 92 |
-
|
| 93 |
-
# Step 1 - Load base model
|
| 94 |
-
base_model = AutoModelForCausalLM.from_pretrained(
|
| 95 |
-
"aaditya/Llama3-OpenBioLLM-8B",
|
| 96 |
-
torch_dtype=torch.float16,
|
| 97 |
-
device_map="auto",
|
| 98 |
-
)
|
| 99 |
-
|
| 100 |
-
# Step 2 - Attach LoRA adapter
|
| 101 |
-
model = PeftModel.from_pretrained(base_model, "Namirah07/OpenBioLLM-G-ICD10")
|
| 102 |
-
model.eval()
|
| 103 |
-
|
| 104 |
-
# Step 3 - Load tokenizer
|
| 105 |
-
tokenizer = AutoTokenizer.from_pretrained("Namirah07/OpenBioLLM-G-ICD10")
|
| 106 |
-
if tokenizer.pad_token is None:
|
| 107 |
-
tokenizer.pad_token = tokenizer.eos_token
|
| 108 |
-
|
| 109 |
-
# Step 4 - Build prompt and generate
|
| 110 |
-
note = "Patient admitted with chest pain and shortness of breath..."
|
| 111 |
-
|
| 112 |
-
prompt = (
|
| 113 |
-
"[SYSTEM]\n"
|
| 114 |
-
"You are a medical coding assistant. Given a clinical note, you output "
|
| 115 |
-
"the most accurate ICD-10 code. Respond with only the ICD-10 code, "
|
| 116 |
-
"no extra text.\n"
|
| 117 |
-
"[/SYSTEM]\n"
|
| 118 |
-
"[USER]\n"
|
| 119 |
-
+ note +
|
| 120 |
-
"\n[/USER]\n"
|
| 121 |
-
"[ICD]\n"
|
| 122 |
-
"ICD-10 code: "
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
-
inputs = tokenizer(
|
| 126 |
-
prompt,
|
| 127 |
-
return_tensors="pt",
|
| 128 |
-
truncation=True,
|
| 129 |
-
max_length=512,
|
| 130 |
-
).to(model.device)
|
| 131 |
-
|
| 132 |
-
with torch.no_grad():
|
| 133 |
-
output = model.generate(
|
| 134 |
-
**inputs,
|
| 135 |
-
max_new_tokens=8,
|
| 136 |
-
do_sample=False,
|
| 137 |
-
pad_token_id=tokenizer.pad_token_id,
|
| 138 |
-
eos_token_id=tokenizer.eos_token_id,
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
input_len = inputs["input_ids"].shape[1]
|
| 142 |
-
generated = tokenizer.decode(
|
| 143 |
-
output[0, input_len:],
|
| 144 |
-
skip_special_tokens=True
|
| 145 |
-
).strip()
|
| 146 |
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
| 148 |
```
|
| 149 |
|
| 150 |
-
|
| 151 |
-
see the full evaluation script in the GitHub repository below.
|
| 152 |
|
| 153 |
-
|
| 154 |
|
| 155 |
-
## Dataset
|
| 156 |
|
| 157 |
-
|
| 158 |
-
Access requires a PhysioNet credentialed account and data use agreement.
|
| 159 |
-
https://physionet.org/content/mimiciv/
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
|
| 166 |
-
and the Gradio explainability demo:
|
| 167 |
-
https://github.com/Namirah07/Enhancing-Automated-ICD-Medical-Coding-with-Large-Language-Models
|
| 168 |
|
| 169 |
-
---
|
| 170 |
|
| 171 |
-
## Citation
|
| 172 |
|
|
|
|
|
|
|
| 173 |
```bibtex
|
| 174 |
-
@
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
| 180 |
}
|
| 181 |
-
```
|
| 182 |
-
|
| 183 |
-
---
|
| 184 |
-
|
| 185 |
-
## License
|
| 186 |
-
|
| 187 |
-
MIT License.
|
| 188 |
-
The base model (Llama3-OpenBioLLM-8B) is subject to its own license on HuggingFace.
|
| 189 |
-
The MIMIC-IV dataset requires a PhysioNet data use agreement.
|
|
|
|
| 1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
base_model: aaditya/Llama3-OpenBioLLM-8B
|
| 3 |
+
library_name: peft
|
| 4 |
+
model_name: openbiollm_sft_sfttrainer
|
| 5 |
+
tags:
|
| 6 |
+
- base_model:adapter:aaditya/Llama3-OpenBioLLM-8B
|
| 7 |
+
- lora
|
| 8 |
+
- sft
|
| 9 |
+
- transformers
|
| 10 |
+
- trl
|
| 11 |
+
licence: license
|
| 12 |
pipeline_tag: text-generation
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# Model Card for openbiollm_sft_sfttrainer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
This model is a fine-tuned version of [aaditya/Llama3-OpenBioLLM-8B](https://huggingface.co/aaditya/Llama3-OpenBioLLM-8B).
|
| 18 |
+
It has been trained using [TRL](https://github.com/huggingface/trl).
|
| 19 |
|
| 20 |
+
## Quick start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
```python
|
| 23 |
+
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
|
| 26 |
+
generator = pipeline("text-generation", model="None", device="cuda")
|
| 27 |
+
output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]
|
| 28 |
+
print(output["generated_text"])
|
| 29 |
```
|
| 30 |
|
| 31 |
+
## Training procedure
|
|
|
|
| 32 |
|
| 33 |
+
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
+
This model was trained with SFT.
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
### Framework versions
|
| 39 |
|
| 40 |
+
- PEFT 0.18.1
|
| 41 |
+
- TRL: 0.26.2
|
| 42 |
+
- Transformers: 4.57.5
|
| 43 |
+
- Pytorch: 2.6.0+cu124
|
| 44 |
+
- Datasets: 4.4.2
|
| 45 |
+
- Tokenizers: 0.22.1
|
| 46 |
|
| 47 |
+
## Citations
|
|
|
|
|
|
|
| 48 |
|
|
|
|
| 49 |
|
|
|
|
| 50 |
|
| 51 |
+
Cite TRL as:
|
| 52 |
+
|
| 53 |
```bibtex
|
| 54 |
+
@misc{vonwerra2022trl,
|
| 55 |
+
title = {{TRL: Transformer Reinforcement Learning}},
|
| 56 |
+
author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
|
| 57 |
+
year = 2020,
|
| 58 |
+
journal = {GitHub repository},
|
| 59 |
+
publisher = {GitHub},
|
| 60 |
+
howpublished = {\url{https://github.com/huggingface/trl}}
|
| 61 |
}
|
| 62 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|