Views
No views yet
Research use only. Not intended for clinical decision-making or patient care.
unlikely_but_serious field is the core research contribution of this model.
It operationalises the clinical safety principle that low-probability, high-severity
diagnoses must be actively considered regardless of base rate.| Parameter | Value |
|---|---|
| Base model | Qwen2.5-0.5B-Instruct |
| Method | QLoRA (4-bit NF4) |
| LoRA rank | 8 |
| LoRA alpha | 16 |
| Training examples | 200 (from 250-example curated dataset) |
| Clinical domains | 10 |
| Epochs | 3 |
| Hardware | NVIDIA GTX 1650 4GB |
| Training time | ~32 minutes |
| Schema adherence (test set) | 56% (vs 4% base model) |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
3from peft import PeftModel
4BASE_MODEL = "Qwen/Qwen2.5-0.5B-Instruct"
5ADAPTER_PATH = "heuristixai/HAI-DiffDx-0.5B"
6bnb_config = BitsAndBytesConfig(
7load_in_4bit=True,
8bnb_4bit_quant_type="nf4",
9bnb_4bit_compute_dtype=torch.float16,
10bnb_4bit_use_double_quant=True
11)
12tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL, trust_remote_code=True)
13base_model = AutoModelForCausalLM.from_pretrained(
14BASE_MODEL,
15quantization_config=bnb_config,
16device_map="auto",
17trust_remote_code=True
18)
19model = PeftModel.from_pretrained(base_model, ADAPTER_PATH)
20model.eval()
21SYSTEM_PROMPT = """You are a clinical reasoning assistant trained to generate
22structured
23differential diagnoses. Given a symptom description, output a JSON object with exactly
24five fields: symptoms, most_likely, possible (a list of exactly 2 entries),
25unlikely_but_serious, and recommended_workup. Be specific, clinically grounded, and
26always consider the most dangerous diagnosis that must not be missed."""
27symptom = "Your symptom description here."
28prompt =
29f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n<|im_start|>user\n{symptom}<|im
30_end|>\n<|im_start|>assistant\n"
31inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
32with torch.no_grad():
33outputs = model.generate(
34**inputs,
35max_new_tokens=600,
36temperature=0.1,
37do_sample=True,
38pad_token_id=tokenizer.eos_token_id,
39repetition_penalty=1.1
40)
41response = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:],
42skip_special_tokens=True)
43print(response)1{
2 "symptoms": "A 67-year-old woman with hypertension presents with sudden onset severe headache described as the worst of her life, associated with neck stiffness and photophobia. She vomited twice. No fever.",
3 "most_likely": "Bacterial meningitis - fever, neck stiffness, and photophobia with acute headache in an older adult raises concern for meningeal infection.",
4 "possible": [
5 "Hypertensive emergency - severe headache with known hypertension warrants blood pressure evaluation and assessment for end-organ damage",
6 "Migraine with meningismus - severe headache with photophobia and neck stiffness can occur in complex migraine, though first-ever presentation requires exclusion of serious causes"
7 ],
8 "unlikely_but_serious": "Subarachnoid haemorrhage - sudden onset worst-ever headache is the classic sentinel presentation of SAH; a normal CT does not exclude it and lumbar puncture for xanthochromia is mandatory if clinical suspicion remains.",
9 "recommended_workup": "Urgent non-contrast CT head followed by lumbar puncture if CT is negative, blood pressure measurement, and urgent neurology review."| Model | Schema Adherence |
|---|---|
| Baseline (no fine-tune) | 4% (1/25) |
| Version A (full schema) | 56% (14/25) |
| Ablation B (no unlikely_serious) | 52% (13/25) |
| Ablation C (no workup) | 36% (9/25) |
1@techreport{tareen2026diffdx,
2 title = {Structured Clinical Differential Reasoning in Small Language Models: A Four-Tier Schema Approach via QLoRA Fine-Tuning},
3 author = {Tareen, Gibran Khan and Nawaz, Mir Farhan},
4 year = {2026},
5 institution = {HeuristixAI Research},
6 url = {https://huggingface.co/heuristixai/HAI-DiffDx-0.5B}