File size: 4,141 Bytes
20d2e6b
 
 
 
3b5f767
 
 
 
 
 
 
 
 
 
 
 
 
 
20d2e6b
 
3b5f767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20d2e6b
3b5f767
20d2e6b
3b5f767
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20d2e6b
3b5f767
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
---
license: apache-2.0
language:
- en
base_model:
- unsloth/gemma-4-e4b-it-unsloth-bnb-4bit
tags:
- transformers
- safetensors
- gemma4
- image-text-to-text
- text-generation-inference
- unsloth
- conversational
- icd-coding
- clinical-nlp
- medical-ai
pipeline_tag: image-text-to-text
---

# πŸ₯ gemma4-e4b-icd-coding

A fine-tuned **Gemma 4 E4B** model for automatic **ICD code prediction** from clinical notes. Given a free-text clinical note, the model outputs the relevant ICD diagnosis codes β€” streamlining medical billing, documentation, and clinical analytics workflows.

---

## πŸ“Œ Model Overview

| Property | Details |
|---|---|
| **Base Model** | `unsloth/gemma-4-e4b-it-unsloth-bnb-4bit` |
| **Fine-tuned by** | [nikhil061307](https://huggingface.co/nikhil061307) |
| **Task** | Clinical Note β†’ ICD Code Prediction |
| **Language** | English |
| **License** | Apache 2.0 |
| **Training Framework** | [Unsloth](https://github.com/unslothai/unsloth) + HuggingFace TRL |

---

## πŸš€ What It Does

Given a clinical note like:

> *"Patient presents with persistent cough, fever, and bilateral infiltrates on chest X-ray. Diagnosed with community-acquired pneumonia."*

The model outputs the appropriate ICD-10 code(s), e.g.:

```
J18.9 - Pneumonia, unspecified organism
```

---

## πŸ’» Usage

### Installation

```bash
pip install unsloth transformers torch
```

### Inference

```python
from transformers import AutoTokenizer, AutoModelForImageTextToText
import torch

model_id = "nikhil061307/gemma4-e4b-icd-coding"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForImageTextToText.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype=torch.bfloat16,
)

clinical_note = """
Patient is a 65-year-old male with a history of type 2 diabetes presenting 
with polyuria, polydipsia, and HbA1c of 9.2%. Blood glucose fasting at 210 mg/dL.
"""

messages = [
    {
        "role": "user",
        "content": f"Predict the ICD-10 codes for the following clinical note:\n\n{clinical_note}"
    }
]

input_text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(input_text, return_tensors="pt").to(model.device)

with torch.no_grad():
    outputs = model.generate(
        **inputs,
        max_new_tokens=256,
        temperature=0.1,
        do_sample=True,
    )

response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
print(response)
```

---

## πŸ§ͺ Example Input / Output

**Input (Clinical Note):**
```
A 52-year-old woman presents with sharp chest pain radiating to the left arm,
diaphoresis, and shortness of breath. ECG shows ST elevation in leads II, III, aVF.
Troponin elevated. Impression: Acute inferior STEMI.
```

**Output (ICD Codes):**
```
I21.19 - ST elevation (STEMI) myocardial infarction involving other coronary artery
```

---

## βš™οΈ Training Details

- **Base model:** `unsloth/gemma-4-e4b-it-unsloth-bnb-4bit` (4-bit quantized)
- **Training speedup:** 2x faster training with [Unsloth](https://github.com/unslothai/unsloth)
- **Library:** HuggingFace TRL (SFTTrainer)
- **Quantization:** BnB 4-bit (inference efficient)

---

## ⚠️ Limitations & Disclaimer

- This model is intended for **research and assistive purposes only**.
- It is **not a substitute for professional medical coding** by certified coders (CPC/CCS).
- Always verify predicted ICD codes with qualified clinical staff before use in billing or official documentation.
- Model performance may vary across specialties, note styles, and rare diagnosis categories.

---

## πŸ“„ License

This model is released under the **Apache 2.0** license. See [LICENSE](https://www.apache.org/licenses/LICENSE-2.0) for details.

---

## πŸ™ Acknowledgements

- [Unsloth AI](https://github.com/unslothai/unsloth) β€” for the blazing fast fine-tuning framework
- [Google DeepMind](https://deepmind.google/) β€” for the Gemma model family
- [HuggingFace TRL](https://github.com/huggingface/trl) β€” for the SFT training utilities

---

*Made with ❀️ using [Unsloth](https://github.com/unslothai/unsloth)*