A
QLoRA fine-tuned adapter for
google/medgemma-4b-it that predicts ICD-10-CM diagnosis codes from clinical notes. Focused on
Chapter 6: Diseases of the Nervous System (G00-G99) — 665 billable codes.
An earlier V1 model trained on simpler template-based data achieved 38% exact match and 88% category match on a smaller 50-example eval set — demonstrating that evaluation difficulty scales with dataset diversity.
1{
2 "peft_type": "LORA",
3 "r": 32,
4 "lora_alpha": 64,
5 "lora_dropout": 0.05,
6 "bias": "none",
7 "task_type": "CAUSAL_LM",
8 "target_modules": [
9 "q_proj", "k_proj", "v_proj", "o_proj",
10 "gate_proj", "up_proj", "down_proj"
11 ]
12}
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3from peft import PeftModel
4
5# Load base model with 4-bit quantization
6bnb_config = BitsAndBytesConfig(
7 load_in_4bit=True,
8 bnb_4bit_quant_type="nf4",
9 bnb_4bit_use_double_quant=True,
10 bnb_4bit_compute_dtype=torch.bfloat16,
11)
12
13base_model = AutoModelForCausalLM.from_pretrained(
14 "google/medgemma-4b-it",
15 quantization_config=bnb_config,
16 device_map="auto",
17 torch_dtype=torch.bfloat16,
18)
19
20tokenizer = AutoTokenizer.from_pretrained("google/medgemma-4b-it")
21
22# Load the LoRA adapter
23model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/medgemma-icd10-lora-v2")
24model.eval()
25
26# Predict ICD-10 code from a clinical note
27clinical_note = """
2868-year-old male presenting with 2-year history of progressive right-hand
29resting tremor. Reports difficulty with fine motor tasks. Examination reveals
304-5 Hz pill-rolling tremor, cogwheel rigidity bilateral upper extremities,
31bradykinesia on finger tapping. Gait shows reduced arm swing and mild shuffling.
32"""
33
34messages = [
35 {"role": "user", "content": f"Given the following clinical note, predict the ICD-10-CM diagnosis code:\n\n{clinical_note}"}
36]
37
38input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
39input_ids = input_ids.to(model.device)
40
41with torch.no_grad():
42 output = model.generate(input_ids, max_new_tokens=50, temperature=0.1, do_sample=True)
43
44response = tokenizer.decode(output[0][input_ids.shape[1]:], skip_special_tokens=True)
45print(response)
46# Example output: "ICD-10-CM: G20.A1 - Parkinson disease, without fluctuations"
See the
Gradio app for the complete implementation.
Trained on the
MedGemma ICD-10 Clinical Notes Dataset — 3,325 synthetic clinical notes generated by MedGemma-4B-IT (self-distillation).
1@misc{medgemma_icd10_finetuning,
2 title={Fine-Tuning MedGemma-4B for ICD-10 Diagnosis Coding},
3 author={singhak-abbvie},
4 year={2026}
5}