A LoRA adapter fine-tuned on top of Qwen3-4B for medical question answering. The model acts as an expert medical doctor, providing diagnosis guidance and treatment advice in response to patient questions.
Disclaimer: This model is for educational and research purposes only. It is not a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare provider.
1from transformers import TextStreamer
23SYSTEM_PROMPT =(4"You are an expert medical doctor. "5"Answer the patient's question with a clear diagnosis and treatment advice."6)78defask(question:str):9 text = tokenizer.apply_chat_template([10{"role":"system","content": SYSTEM_PROMPT},11{"role":"user","content": question},12], tokenize=False, add_generation_prompt=True)1314 inputs = tokenizer(text, return_tensors="pt").to(device)15with torch.no_grad():16 model.generate(17**inputs,18 max_new_tokens =512,19 temperature =0.7,20 do_sample =True,21 streamer = TextStreamer(tokenizer, skip_prompt=True),22)2324ask("I have had a fever of 39°C, sore throat, and fatigue for 3 days. What should I do?")25ask("I am a 45-year-old male with high blood pressure. Can I take ibuprofen?")
Fields used: instruction / input (question) and output (doctor response)
5,000 samples used for this run
Procedure
Supervised fine-tuning (SFT) using the Qwen3 instruct chat template:
<|im_start|>system
You are an expert medical doctor...<|im_end|>
<|im_start|>user
{patient question}<|im_end|>
<|im_start|>assistant
{doctor response}<|im_end|>
Hyperparameters
Parameter
Value
Epochs
1
Batch size (per device)
2
Gradient accumulation
4 (effective batch = 8)
Learning rate
2e-4
LR scheduler
cosine
Warmup steps
10
Optimizer
adamw_8bit
Weight decay
0.01
Max sequence length
2048
Precision
fp16
Hardware
GPU: NVIDIA Tesla T4 (16 GB)
Platform: Kaggle (free tier)
Framework: Unsloth + TRL SFTTrainer
Limitations & Risks
Not a medical device. Outputs are not validated by clinical experts and must not be used for actual diagnosis or treatment decisions.
Hallucination. Like all LLMs, the model can produce plausible-sounding but incorrect medical information.
English only. Trained exclusively on English-language data.
Narrow coverage. Trained on general GP-style Q&A; may perform poorly on specialist domains (oncology, rare diseases, paediatrics, etc.).
No patient history. The model has no memory across turns and no access to lab results or imaging.
Citation
If you use this model, please cite the base model and dataset: