Downloads · 30 days
13
4% of all-time downloads
imran785/medical-triage-qwen-3b-trained
medical-triage-qwen-3b-trained is a reinforcement learning model from imran785. Use it for the reinforcement learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as apache-2.0.
Teaching LLMs to think like doctors through Reinforcement Learning
Downloads · 30 days
13
4% of all-time downloads
All-time downloads
290
Public
Parameters
3.1B
6.2 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors6.2 GB · 100%
From the Hugging Face model README
Teaching LLMs to think like doctors through Reinforcement Learning
Most LLMs today are trained to be helpful conversational assistants. In a medical triage room, being chatty can cost lives.
A real doctor needs to:
Current LLMs fail at all three.
Give a base LLM a patient complaint and it responds with:
"I'm sorry you're feeling this way. Chest pain can be serious. You should see a doctor. Would you like a list of symptoms to watch for?"
This project uses Reinforcement Learning to transform a general-purpose LLM into a Triage Agent that understands the Value of Information — learning exactly which question to ask next and when to stop.
Built on the OpenEnv framework, the environment simulates a hospital triage room with real patient cases.
reset() → New patient arrives with chief complaint
Agent sees: "I have chest pain and shortness of breath"
step() → Agent takes one of 3 actions:
ask_symptom: fever → "yes, 102F"
order_test: chest_xray → "right lower lobe infiltrate"
give_diagnosis: pneumonia → episode ends → reward computed
state() → Returns current known symptoms, tests ordered, actions taken
| Action | What It Does | Cost |
|---|---|---|
ask_symptom | Queries a symptom from the patient | Free |
order_test | Orders a medical test | 1-5 points deducted |
give_diagnosis | Submits final diagnosis and ends episode | Triggers scoring |
diagnosis_correct: +10 Did the agent get the right answer?
efficiency_score: +5 Did it avoid expensive unnecessary tests?
speed_score: +3 Did it decide within few actions?
process_score: +5 Did it ask smart relevant symptoms?
TOTAL MAX: +23
BASELINE (random): -4
The environment is designed so agents cannot exploit the reward:
give_diagnosis before taking at least 2 actionsWe use composable rubrics instead of a single reward signal. This is deliberate — multiple independent reward functions are harder to game and teach specific behaviors:
Single reward (0/1): Model learns to guess correctly
but does not care HOW it gets there
Our 4-component rubric: Model learns to gather evidence first,
avoid expensive tests,
be fast AND accurate simultaneously
The Urgency Bonus rewards identifying life-threatening conditions (heart attack, meningitis) in fewer steps — teaching the agent to prioritize high-risk patients exactly as real triage does.
The Hallucination Penalty (-10) fires when an agent orders a test that does not exist in the patient's available tests — directly penalizing medical hallucination, one of the most dangerous LLM failure modes.
.png)
| Feature | Base Model (Untrained) | Trained RL Agent |
|---|---|---|
| Avg Reward | -4.0 | +5.7 (rolling avg) |
| Peak Reward | -1.0 | +19.0 (near maximum of 23) |
| Bad Actions per Episode | 5 | 0 |
| Symptoms Asked | 0-2 (random) | 4-5 (systematic) |
| Diagnosis Accuracy | 0% | ~20% |
| Output Style | Conversational paragraphs | Structured thinking + actions |
| Decision Making | Hesitant, generic advice | Decisive, evidence-based |
| Cost Awareness | Random test ordering | Prioritizes high-impact tests first |
Behavioral change is the strongest evidence:
BEFORE (Episode 0):
Patient: "I have chest pain and shortness of breath with fever"
Agent: [bad action] → [bad action] → [guess: anxiety]
Result: reward -4, 5 invalid actions, 0 symptoms asked
AFTER (Episode 185):
Patient: "I have chest pain and shortness of breath with fever"
Agent: ask_symptom: cough → "productive cough 3 days"
ask_symptom: fever → "yes, 102F"
ask_symptom: shortness_of_breath → "worse on exertion"
order_test: chest_xray → "right lower lobe infiltrate"
give_diagnosis: pneumonia ✓ CORRECT
Result: reward +19, 0 invalid actions, 4 relevant symptoms asked
Quantitative improvements:
The green spikes represent perfect diagnoses where the agent identified the correct condition through systematic investigation. The rolling average staying above zero throughout training confirms the model genuinely learned the task rather than getting lucky.
Base Model Response:
"I'm sorry you're feeling this. Chest pain is serious.
You should go to the ER or call a doctor immediately.
Would you like a list of symptoms to watch for?"
Result: FAIL — wasted critical time with conversation.
No diagnosis. No tests. No action.
Trained RL Agent Response:
<thinking>
Patient presents with chest pain. Need to rule out
cardiac event. Check radiation pattern and associated symptoms.
</thinking>
<action>ask_symptom: radiation_to_arm</action>
Result: "yes, left arm pain"
<thinking>
Left arm radiation + chest pain = high MI probability.
Order EKG immediately.
</thinking>
<action>order_test: ecg</action>
Result: "ST elevation detected"
<action>give_diagnosis: heart_attack</action>
Result: CORRECT — identified life-threatening condition
in 3 steps. Reward: +19
Environment: OpenEnv framework (FastAPI + Docker)
Model: Qwen2.5-3B-Instruct (LoRA fine-tuned, rank 16)
Training: GRPO-style reward weighted policy gradient
Efficiency: Unsloth 4-bit quantization
Platform: Google Colab T4 GPU
Episodes: 200 training episodes
VRAM Management on Free T4:
Implemented aggressive memory management to run RL training on a 15.6GB T4 GPU with a 3B parameter model:
Prompt Engineering:
Uses a ChatML-based reasoning loop with strict regex parsing:
# Agent outputs structured actions
<thinking>
Patient has fever and productive cough. Check for infiltrates.
</thinking>
<action>order_test: chest_xray</action>
# Parser extracts action deterministically
parse_action(response) → {"action_type": "order_test",
"query": "chest_xray"}
Reward Normalization:
GRPO-style reward normalization across episode groups prevents gradient explosion and stabilizes training on noisy RL signals.
from medical_triage_client import MedicalTriageClient
client = MedicalTriageClient(
url="https://imran785-medical-triage-rl-env.hf.space"
)
# Start episode
obs = client.reset()
print(obs["presented_complaint"])
# → "I have chest pain and feel short of breath with fever."
# Ask a symptom
result = client.step({
"action_type": "ask_symptom",
"query": "fever"
})
print(result["message"])
# → "yes, 102F"
# Order a test
result = client.step({
"action_type": "order_test",
"query": "chest_xray"
})
print(result["message"])
# → "right lower lobe infiltrate"
# Give diagnosis
result = client.step({
"action_type": "give_diagnosis",
"query": "pneumonia"
})
print(result["reward"])
# → 19.0
| Resource | Link |
|---|---|
| 🌐 Live Environment (HF Space) | imran785/medical-triage-rl-env |
| 🤖 Trained Model (HF Hub) | imran785/medical-triage-qwen-3b |
| 📓 Training Notebook (Colab) | Open in Colab |
Medical diagnosis errors affect millions of patients annually. LLMs are increasingly used in healthcare contexts but fail at systematic clinical reasoning — they either over-explain or under-investigate.
This environment demonstrates that RL training can teach an LLM a fundamentally new capability: evidence-based sequential reasoning under cost constraints — the core skill of medical triage.
A researcher could write a paper about this environment because:
Team Mohammed Scaler X Meta Hackathon 2026
Built with OpenEnv · Unsloth · HuggingFace TRL · Qwen2.5