File size: 6,764 Bytes
bd0301c fe6588d bd0301c fe6588d bd0301c fe6588d bd0301c fe6588d bd0301c fe6588d 1ca8d60 fe6588d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | ---
base_model: unsloth/gemma-3-4b-it-unsloth-bnb-4bit
tags:
- text-generation-inference
- transformers
- unsloth
- gemma3
- medical
- clinical-nlp
- soap-notes
license: apache-2.0
language:
- en
---
# SOAP_SFT_V1 — Medical SOAP Note Generator
**SOAP_SFT_V1** is a fine-tuned version of [Gemma 3 4B Instruct](https://huggingface.co/unsloth/gemma-3-4b-it-unsloth-bnb-4bit), trained to generate structured clinical **SOAP notes** (Subjective, Objective, Assessment, Plan) from doctor–patient dialogues.
Trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Hugging Face's TRL library on an H100 GPU.
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
---
## Model Details
| Property | Value |
|---|---|
| **Developed by** | Edifon |
| **Base model** | `unsloth/gemma-3-4b-it-unsloth-bnb-4bit` |
| **Model type** | Causal Language Model (fine-tuned) |
| **Language** | English |
| **License** | Apache 2.0 |
| **Fine-tuning method** | Supervised Fine-Tuning (SFT) with LoRA |
| **Training hardware** | Google Colab H100 |
---
## Intended Use
This model is designed to assist healthcare professionals and clinical NLP researchers by automatically converting clinical consultation transcripts into structured SOAP notes.
**SOAP format:**
- **S (Subjective):** Patient-reported symptoms, history, and complaints
- **O (Objective):** Observable/measurable clinical findings and planned investigations
- **A (Assessment):** Differential diagnosis and clinical reasoning
- **P (Plan):** Treatment plan, referrals, and follow-up instructions
> ⚠️ **Disclaimer:** This model is intended as a research and assistive tool only. It is **not** a substitute for professional medical judgment or a licensed clinician's evaluation.
---
## Training Details
### Dataset
- **Dataset:** [`syafiqassegaf/soap-dataset`](https://www.kaggle.com/datasets/syafiqassegaf/soap-dataset) (Kaggle)
- **Total examples:** 9,250
- **Train / Eval split:** 90% / 10% → 8,325 train | 925 eval
- **Features:** `dialogue`, `soap`, `prompt`, `messages`
### LoRA Configuration
| Parameter | Value |
|---|---|
| Rank (`r`) | 8 |
| Alpha (`lora_alpha`) | 8 |
| Dropout | 0 |
| Bias | none |
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
| Trainable parameters | 16,394,240 / 4,316,473,712 (**0.38%**) |
| Vision layers finetuned | No |
| Language layers finetuned | Yes |
### Training Hyperparameters
| Parameter | Value |
|---|---|
| Epochs | 5 |
| Per-device batch size | 2 |
| Gradient accumulation steps | 4 (effective batch size = 8) |
| Learning rate | 2e-5 |
| LR scheduler | Linear |
| Optimizer | AdamW 8-bit |
| Weight decay | 0.001 |
| Warmup steps | 5 |
| Max sequence length | 2048 |
| Seed | 3407 |
| Total steps | 5,205 |
Training used `train_on_responses_only` — only model responses were used in the loss computation, not the user instructions.
---
## How to Use
### With `transformers` (Standard)
```python
from transformers import AutoProcessor, AutoModelForImageTextToText
processor = AutoProcessor.from_pretrained("Edifon/SOAP_SFT_V1")
model = AutoModelForImageTextToText.from_pretrained("Edifon/SOAP_SFT_V1", device_map="auto")
messages = [
{
"role": "system",
"content": [{"type": "text", "text": (
"You are an expert medical professor assisting in the creation of medically accurate SOAP summaries. "
"Please ensure the response follows the structured format: S:, O:, A:, P: without using markdown or special formatting."
)}],
},
{
"role": "user",
"content": [{"type": "text", "text": """Create a medical SOAP summary of this dialogue.
### Dialogue:
Doctor: Hello, what brings you in today?
Patient: I've been having severe headaches for the past few weeks...
[rest of dialogue]
"""}],
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
from transformers import TextStreamer
_ = model.generate(
**inputs,
max_new_tokens=2048,
streamer=TextStreamer(processor, skip_prompt=True),
)
```
### With Unsloth (Faster Inference)
```python
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="Edifon/SOAP_SFT_V1",
max_seq_length=2048,
load_in_4bit=True,
)
FastModel.for_inference(model)
```
---
## Example Output
**Input dialogue (excerpt):**
> Patient reports photopsia in the left eye for ten days, including flashes of light and a dark spot on the nasal side. Had influenza-like symptoms two weeks prior. No history of eye disease.
**Model output:**
```
S: Patient reports experiencing photopsia in the left eye for ten days, describing flashes of light
and a dark spot on the nasal side. History of influenza-like symptoms two weeks prior.
No prior eye disease, operations, or treatments.
O: Patient presented with photopsia and a dark spot in the left eye. Comprehensive eye examination
planned (visual acuity, slit-lamp, fundus examination).
A: Differential includes post-infectious transient optic neuropathy or acute ocular involvement
secondary to influenza. Absence of prior eye disease supports opportunistic onset.
P: Order comprehensive eye examination. Schedule follow-up to review results and determine
treatment or referral plan. Encourage prompt completion of planned examination.
```
---
## Training Curve
| Metric | Value |
|---|---|
| Initial loss (step 100) | 0.941 |
| Final loss (step 5200) | 0.482 |
| Total reduction | ~48.8% |
The model converged stably over 5 epochs / 5,205 steps. Loss dropped sharply in the first ~300 steps as the model learned the SOAP output format, then decayed gradually through step ~2,000, before plateauing in the 0.48–0.52 range for the final two epochs with no significant overfitting observed.

---
## Limitations
- Trained exclusively on English-language dialogues
- Performance may degrade on highly specialized subspecialty consultations underrepresented in the training data
- Should not be used for clinical decision-making without expert oversight
- Outputs may occasionally include disclaimers or formatting inconsistencies
---
## Citation
If you use this model in your research, please cite the base model and dataset:
```bibtex
@misc{soap_sft_v1,
author = {Edifon},
title = {SOAP\_SFT\_V1: Medical SOAP Note Generator},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/Edifon/SOAP_SFT_V1}
}
``` |