fix: correct training config (batch 2x8=16, LR 2e-5, epochs 5)
Browse files
README.md
CHANGED
|
@@ -1,11 +1,31 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
base_model: google/medgemma-4b-it
|
| 3 |
library_name: peft
|
| 4 |
pipeline_tag: text-generation
|
| 5 |
license: mit
|
| 6 |
language:
|
| 7 |
-
- en
|
| 8 |
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
- lora
|
| 10 |
- transformers
|
| 11 |
- medical
|
|
@@ -14,8 +34,9 @@ tags:
|
|
| 14 |
- medgemma
|
| 15 |
- hai-def
|
| 16 |
- medgemma-impact-challenge
|
| 17 |
-
|
| 18 |
-
-
|
|
|
|
| 19 |
---
|
| 20 |
|
| 21 |
# MedScribe SOAP LoRA — Concise Clinical Note Generation
|
|
@@ -34,25 +55,27 @@ default to.
|
|
| 34 |
|
| 35 |
**Example:**
|
| 36 |
|
| 37 |
-
| Input transcript
|
| 38 |
-
|-----------------|---|
|
| 39 |
-
| **Base MedGemma** | ~200 words, textbook prose, over-specified plan with 6-8 items
|
| 40 |
-
| **This adapter**
|
| 41 |
|
| 42 |
## Key Metrics
|
| 43 |
|
| 44 |
-
| Metric
|
| 45 |
-
|--------
|
| 46 |
-
| Avg word count
|
| 47 |
-
| Section completeness (S/O/A/P) | 85-95%
|
| 48 |
-
| Hallucinated findings
|
| 49 |
-
| WNL shortcuts
|
| 50 |
-
| Clinical style
|
| 51 |
-
| PLAN items
|
| 52 |
-
| Quality score
|
| 53 |
|
| 54 |
## Usage
|
| 55 |
|
|
|
|
|
|
|
| 56 |
```python
|
| 57 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 58 |
from peft import PeftModel
|
|
@@ -67,18 +90,18 @@ bnb_config = BitsAndBytesConfig(
|
|
| 67 |
)
|
| 68 |
|
| 69 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 70 |
-
|
| 71 |
quantization_config=bnb_config,
|
| 72 |
device_map="auto",
|
| 73 |
)
|
| 74 |
tokenizer = AutoTokenizer.from_pretrained("google/medgemma-4b-it")
|
| 75 |
|
| 76 |
# Load LoRA adapter
|
| 77 |
-
model = PeftModel.from_pretrained(base_model,
|
| 78 |
model.eval()
|
| 79 |
|
| 80 |
# Generate SOAP note
|
| 81 |
-
prompt =
|
| 82 |
text into a structured SOAP note.
|
| 83 |
|
| 84 |
MEDICAL TEXT:
|
|
@@ -96,12 +119,12 @@ SOAP NOTE:"""
|
|
| 96 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 97 |
with torch.inference_mode():
|
| 98 |
outputs = model.generate(
|
| 99 |
-
|
| 100 |
max_new_tokens=400,
|
| 101 |
min_new_tokens=150,
|
| 102 |
do_sample=False,
|
| 103 |
use_cache=True,
|
| 104 |
-
|
| 105 |
result = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 106 |
print(result)
|
| 107 |
```
|
|
@@ -114,36 +137,37 @@ print(result)
|
|
| 114 |
Dataset: [Tushar-9802/medscribe-soap-712](https://huggingface.co/datasets/Tushar-9802/medscribe-soap-712)
|
| 115 |
|
| 116 |
Each sample enforces:
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
| 121 |
|
| 122 |
### Training Configuration
|
| 123 |
|
| 124 |
-
| Parameter
|
| 125 |
-
|-----------|-------|
|
| 126 |
-
| Base model
|
| 127 |
-
| Method
|
| 128 |
-
| Rank
|
| 129 |
-
| Alpha
|
| 130 |
-
| Dropout
|
| 131 |
-
| Target modules
|
| 132 |
-
| Trainable parameters | ~4.2M (0.1% of 4B base)
|
| 133 |
-
| Batch size
|
| 134 |
-
| Learning rate
|
| 135 |
-
| Epochs
|
| 136 |
-
| Precision
|
| 137 |
-
| Quantization
|
| 138 |
-
| Hardware
|
| 139 |
|
| 140 |
### Training Results
|
| 141 |
|
| 142 |
-
| Metric
|
| 143 |
-
|--------|-------|
|
| 144 |
-
| Training loss
|
| 145 |
-
| Validation loss | 0.782
|
| 146 |
-
| Overfitting
|
| 147 |
|
| 148 |
## Anti-Hallucination Behavior
|
| 149 |
|
|
@@ -155,19 +179,19 @@ missing is far safer than a plausible-sounding fabrication.
|
|
| 155 |
|
| 156 |
## Intended Use
|
| 157 |
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
|
| 162 |
## Limitations
|
| 163 |
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
from real clinical encounters
|
| 168 |
-
|
| 169 |
approved by a licensed clinician before use in patient care
|
| 170 |
-
|
| 171 |
quantization
|
| 172 |
|
| 173 |
## Part Of
|
|
@@ -179,23 +203,25 @@ this fine-tuned MedGemma adapter (SOAP generation), and base MedGemma
|
|
| 179 |
|
| 180 |
## Framework Versions
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
|
| 187 |
## Citation
|
| 188 |
|
|
|
|
|
|
|
| 189 |
```bibtex
|
| 190 |
@misc{medscribe2026,
|
| 191 |
author = {Tushar},
|
| 192 |
title = {MedScribe: Concise Clinical Documentation via Fine-tuned MedGemma},
|
| 193 |
year = {2026},
|
| 194 |
publisher = {HuggingFace},
|
| 195 |
-
url = {https://huggingface.co/
|
| 196 |
}
|
| 197 |
```
|
| 198 |
|
| 199 |
## Contact
|
| 200 |
|
| 201 |
-
GitHub: [@Tushar-9802](https://github.com/Tushar-9802)
|
|
|
|
| 1 |
---
|
| 2 |
+
---
|
| 3 |
base_model: google/medgemma-4b-it
|
| 4 |
library_name: peft
|
| 5 |
pipeline_tag: text-generation
|
| 6 |
license: mit
|
| 7 |
language:
|
| 8 |
+
- en
|
| 9 |
tags:
|
| 10 |
+
- lora
|
| 11 |
+
- transformers
|
| 12 |
+
- medical
|
| 13 |
+
- clinical-documentation
|
| 14 |
+
- soap-notes
|
| 15 |
+
- medgemma
|
| 16 |
+
- hai-def
|
| 17 |
+
- medgemma-impact-challenge
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
---
|
| 21 |
+
base_model: google/medgemma-4b-it
|
| 22 |
+
library_name: peft
|
| 23 |
+
pipeline_tag: text-generation
|
| 24 |
+
license: mit
|
| 25 |
+
language:
|
| 26 |
+
|
| 27 |
+
- en
|
| 28 |
+
tags:
|
| 29 |
- lora
|
| 30 |
- transformers
|
| 31 |
- medical
|
|
|
|
| 34 |
- medgemma
|
| 35 |
- hai-def
|
| 36 |
- medgemma-impact-challenge
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
---
|
| 41 |
|
| 42 |
# MedScribe SOAP LoRA — Concise Clinical Note Generation
|
|
|
|
| 55 |
|
| 56 |
**Example:**
|
| 57 |
|
| 58 |
+
| Input transcript | "54-year-old female presenting with shortness of breath. CT chest shows filling defects in segmental branches of right lower lobe..." |
|
| 59 |
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
| 60 |
+
| **Base MedGemma** | ~200 words, textbook prose, over-specified plan with 6-8 items |
|
| 61 |
+
| **This adapter** | ~104 words, clinical shorthand ("54 yo F c/o SOB"), focused 2-4 item plan |
|
| 62 |
|
| 63 |
## Key Metrics
|
| 64 |
|
| 65 |
+
| Metric | Base MedGemma | With This Adapter |
|
| 66 |
+
| ------------------------------ | ---------------- | ----------------- |
|
| 67 |
+
| Avg word count | ~200+ | 104 |
|
| 68 |
+
| Section completeness (S/O/A/P) | 85-95% | 100% |
|
| 69 |
+
| Hallucinated findings | 5-10% | 0% |
|
| 70 |
+
| WNL shortcuts | Present | 0% |
|
| 71 |
+
| Clinical style | Textbook verbose | Shorthand |
|
| 72 |
+
| PLAN items | 4-8 | 2-4 (focused) |
|
| 73 |
+
| Quality score | — | 90/100 |
|
| 74 |
|
| 75 |
## Usage
|
| 76 |
|
| 77 |
+
python
|
| 78 |
+
|
| 79 |
```python
|
| 80 |
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
| 81 |
from peft import PeftModel
|
|
|
|
| 90 |
)
|
| 91 |
|
| 92 |
base_model = AutoModelForCausalLM.from_pretrained(
|
| 93 |
+
"google/medgemma-4b-it",
|
| 94 |
quantization_config=bnb_config,
|
| 95 |
device_map="auto",
|
| 96 |
)
|
| 97 |
tokenizer = AutoTokenizer.from_pretrained("google/medgemma-4b-it")
|
| 98 |
|
| 99 |
# Load LoRA adapter
|
| 100 |
+
model = PeftModel.from_pretrained(base_model,"Tushar-9802/medscribe-soap-lora")
|
| 101 |
model.eval()
|
| 102 |
|
| 103 |
# Generate SOAP note
|
| 104 |
+
prompt ="""You are a clinical documentation assistant. Convert the following medical
|
| 105 |
text into a structured SOAP note.
|
| 106 |
|
| 107 |
MEDICAL TEXT:
|
|
|
|
| 119 |
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 120 |
with torch.inference_mode():
|
| 121 |
outputs = model.generate(
|
| 122 |
+
**inputs,
|
| 123 |
max_new_tokens=400,
|
| 124 |
min_new_tokens=150,
|
| 125 |
do_sample=False,
|
| 126 |
use_cache=True,
|
| 127 |
+
)
|
| 128 |
result = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
|
| 129 |
print(result)
|
| 130 |
```
|
|
|
|
| 137 |
Dataset: [Tushar-9802/medscribe-soap-712](https://huggingface.co/datasets/Tushar-9802/medscribe-soap-712)
|
| 138 |
|
| 139 |
Each sample enforces:
|
| 140 |
+
|
| 141 |
+
* "Not documented in source" for any finding absent from the input transcript
|
| 142 |
+
* Zero WNL (Within Normal Limits) shortcuts — every finding explicitly stated
|
| 143 |
+
* Concise clinical shorthand style
|
| 144 |
+
* PLAN with specific, actionable items
|
| 145 |
|
| 146 |
### Training Configuration
|
| 147 |
|
| 148 |
+
| Parameter | Value |
|
| 149 |
+
| -------------------- | --------------------------------------------- |
|
| 150 |
+
| Base model | google/medgemma-4b-it |
|
| 151 |
+
| Method | LoRA |
|
| 152 |
+
| Rank | 16 |
|
| 153 |
+
| Alpha | 32 |
|
| 154 |
+
| Dropout | 0.1 |
|
| 155 |
+
| Target modules | All attention layers |
|
| 156 |
+
| Trainable parameters | ~4.2M (0.1% of 4B base) |
|
| 157 |
+
| Batch size | 2 (× 8 gradient accumulation = effective 16) |
|
| 158 |
+
| Learning rate | 2e-5 |
|
| 159 |
+
| Epochs | 5 (early stopping patience: 2) |
|
| 160 |
+
| Precision | BFloat16 |
|
| 161 |
+
| Quantization | 4-bit NF4 during training |
|
| 162 |
+
| Hardware | NVIDIA RTX 5070 Ti (16GB VRAM) |
|
| 163 |
|
| 164 |
### Training Results
|
| 165 |
|
| 166 |
+
| Metric | Value |
|
| 167 |
+
| --------------- | ------------------ |
|
| 168 |
+
| Training loss | 0.828 |
|
| 169 |
+
| Validation loss | 0.782 |
|
| 170 |
+
| Overfitting | None (val < train) |
|
| 171 |
|
| 172 |
## Anti-Hallucination Behavior
|
| 173 |
|
|
|
|
| 179 |
|
| 180 |
## Intended Use
|
| 181 |
|
| 182 |
+
* Converting medical encounter transcripts to structured SOAP notes
|
| 183 |
+
* Clinical documentation assistance (with physician review)
|
| 184 |
+
* Research and demonstration of efficient medical LLM fine-tuning
|
| 185 |
|
| 186 |
## Limitations
|
| 187 |
|
| 188 |
+
* **English only**
|
| 189 |
+
* **Research prototype** — not validated for clinical use in any jurisdiction
|
| 190 |
+
* **Synthetic training data** — 712 samples generated by GPT-4o Mini, not
|
| 191 |
from real clinical encounters
|
| 192 |
+
* **Requires physician review** — all generated notes must be reviewed and
|
| 193 |
approved by a licensed clinician before use in patient care
|
| 194 |
+
* **Inference speed** — ~25 seconds per note on RTX 5070 Ti with 4-bit
|
| 195 |
quantization
|
| 196 |
|
| 197 |
## Part Of
|
|
|
|
| 203 |
|
| 204 |
## Framework Versions
|
| 205 |
|
| 206 |
+
* PEFT 0.18.1
|
| 207 |
+
* Transformers 4.52+
|
| 208 |
+
* PyTorch 2.8+ (nightly for Blackwell/SM 12.0)
|
| 209 |
+
* bitsandbytes 0.45+
|
| 210 |
|
| 211 |
## Citation
|
| 212 |
|
| 213 |
+
bibtex
|
| 214 |
+
|
| 215 |
```bibtex
|
| 216 |
@misc{medscribe2026,
|
| 217 |
author = {Tushar},
|
| 218 |
title = {MedScribe: Concise Clinical Documentation via Fine-tuned MedGemma},
|
| 219 |
year = {2026},
|
| 220 |
publisher = {HuggingFace},
|
| 221 |
+
url = {https://huggingface.co/Tushar-9802/medscribe-soap-lora}
|
| 222 |
}
|
| 223 |
```
|
| 224 |
|
| 225 |
## Contact
|
| 226 |
|
| 227 |
+
GitHub: [@Tushar-9802](https://github.com/Tushar-9802)
|