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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- medical
|
| 5 |
+
- mcq
|
| 6 |
+
- question-answering
|
| 7 |
+
- classification
|
| 8 |
+
- qwen3
|
| 9 |
+
- medmcq
|
| 10 |
+
- stravoris
|
| 11 |
+
- pipeline
|
| 12 |
+
language:
|
| 13 |
+
- en
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
# MedMCQ — Three-Hop Pipeline (Usage Guide)
|
| 17 |
+
|
| 18 |
+
**MedMCQ** is an experiment in answering medical multiple-choice questions with a collection of small, narrow models instead of one large generalist. A raw MCQ is routed by a subject classifier, then refined by a per-subject topic classifier, then answered by a per-subject generator that returns the correct option and a brief clinical explanation. The full pipeline is 31 fine-tuned Qwen3 models — 1 router, 15 topic classifiers, 15 answer generators — all published under the [`stravoris`](https://huggingface.co/stravoris) org and grouped into the [MedMCQ Medical Models collection](https://huggingface.co/collections/stravoris/medmcq-medical-models). This repository is the landing page and runnable usage guide for that pipeline; it ships only a README and no weights.
|
| 19 |
+
|
| 20 |
+
## Architecture
|
| 21 |
+
|
| 22 |
+
```
|
| 23 |
+
┌──────────────────────────────────────┐
|
| 24 |
+
raw MCQ ───▶ │ Hop 1 — Subject classifier (0.6B) │ ─▶ subject
|
| 25 |
+
│ stravoris/medmcq-subject-classifier │ (e.g. "Pharmacology")
|
| 26 |
+
└──────────────────────────────────────┘
|
| 27 |
+
│
|
| 28 |
+
▼
|
| 29 |
+
┌──────────────────────────────────────┐
|
| 30 |
+
│ Hop 2 — Topic classifier (0.6B) │ ─▶ topic
|
| 31 |
+
│ stravoris/medmcq-<subject>-classifier│ (e.g. "Beta-blockers")
|
| 32 |
+
└──────────────────────────────────────┘
|
| 33 |
+
│
|
| 34 |
+
▼
|
| 35 |
+
┌──────────────────────────────────────┐
|
| 36 |
+
│ Hop 3 — Answer generator (1.7B) │ ─▶ answer + explanation
|
| 37 |
+
│ stravoris/medmcq-<subject> │
|
| 38 |
+
└──────────────────────────────────────┘
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
Each hop is a separate, narrow model. Hops 2 and 3 are picked by name based on what hop 1 returned.
|
| 42 |
+
|
| 43 |
+
## End-to-end example
|
| 44 |
+
|
| 45 |
+
The snippet below runs the full pipeline on a single MCQ. All three models run on CPU; no GPU is required.
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 49 |
+
|
| 50 |
+
ORG = "stravoris"
|
| 51 |
+
|
| 52 |
+
SUBJECT_TO_SLUG = {
|
| 53 |
+
"Anaesthesia": "anaesthesia",
|
| 54 |
+
"Anatomy": "anatomy",
|
| 55 |
+
"Biochemistry": "biochemistry",
|
| 56 |
+
"Cell Biology & Histology": "cell-biology",
|
| 57 |
+
"ENT": "ent",
|
| 58 |
+
"Genetics": "genetics",
|
| 59 |
+
"Microbiology": "microbiology",
|
| 60 |
+
"Obstetrics & Gynaecology": "obstetrics-gynaecology",
|
| 61 |
+
"Ophthalmology": "ophthalmology",
|
| 62 |
+
"Orthopaedics": "orthopaedics",
|
| 63 |
+
"Pathology": "pathology",
|
| 64 |
+
"Pharmacology": "pharmacology",
|
| 65 |
+
"Physiology": "physiology",
|
| 66 |
+
"Psychiatry": "psychiatry",
|
| 67 |
+
"Radiology": "radiology",
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def load(repo):
|
| 72 |
+
tok = AutoTokenizer.from_pretrained(repo)
|
| 73 |
+
mdl = AutoModelForCausalLM.from_pretrained(repo)
|
| 74 |
+
return tok, mdl
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def generate(tok, mdl, prompt, max_new_tokens):
|
| 78 |
+
inputs = tok(prompt, return_tensors="pt").to(mdl.device)
|
| 79 |
+
out = mdl.generate(**inputs, max_new_tokens=max_new_tokens, do_sample=False)
|
| 80 |
+
return tok.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True).strip()
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def resolve_subject(raw):
|
| 84 |
+
for label, slug in SUBJECT_TO_SLUG.items():
|
| 85 |
+
if raw.startswith(label):
|
| 86 |
+
return label, slug
|
| 87 |
+
raise ValueError(f"Unrecognised subject label from router: {raw!r}")
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
question = "Which artery supplies the head of the femur in adults?"
|
| 91 |
+
options = {
|
| 92 |
+
"A": "Obturator artery",
|
| 93 |
+
"B": "Medial circumflex femoral artery",
|
| 94 |
+
"C": "Lateral circumflex femoral artery",
|
| 95 |
+
"D": "Superior gluteal artery",
|
| 96 |
+
}
|
| 97 |
+
options_block = "\n".join(f"{k}) {v}" for k, v in options.items())
|
| 98 |
+
|
| 99 |
+
# Hop 1 — subject routing
|
| 100 |
+
sub_tok, sub_mdl = load(f"{ORG}/medmcq-subject-classifier-qwen3-0.6b")
|
| 101 |
+
sub_prompt = (
|
| 102 |
+
"Classify the following medical MCQ by subject.\n\n"
|
| 103 |
+
f"Question: {question}\n{options_block}\n\nSubject:"
|
| 104 |
+
)
|
| 105 |
+
subject_raw = generate(sub_tok, sub_mdl, sub_prompt, max_new_tokens=8)
|
| 106 |
+
subject, subject_slug = resolve_subject(subject_raw)
|
| 107 |
+
print(f"[hop 1] subject: {subject}")
|
| 108 |
+
|
| 109 |
+
# Hop 2 — topic classification within that subject
|
| 110 |
+
top_tok, top_mdl = load(f"{ORG}/medmcq-{subject_slug}-classifier-qwen3-0.6b")
|
| 111 |
+
top_prompt = (
|
| 112 |
+
f"Classify the following {subject} MCQ by topic.\n\n"
|
| 113 |
+
f"Question: {question}\n{options_block}\n\nTopic:"
|
| 114 |
+
)
|
| 115 |
+
topic = generate(top_tok, top_mdl, top_prompt, max_new_tokens=16)
|
| 116 |
+
print(f"[hop 2] topic: {topic}")
|
| 117 |
+
|
| 118 |
+
# Hop 3 — answer generation
|
| 119 |
+
gen_tok, gen_mdl = load(f"{ORG}/medmcq-{subject_slug}-qwen3-1.7b")
|
| 120 |
+
gen_prompt = (
|
| 121 |
+
"Answer the following medical question. Provide the correct option and a "
|
| 122 |
+
"brief explanation.\n\n"
|
| 123 |
+
f"Topic: {topic}\n\n"
|
| 124 |
+
f"Question: {question}\n\n"
|
| 125 |
+
f"Options:\n{options_block}"
|
| 126 |
+
)
|
| 127 |
+
answer = generate(gen_tok, gen_mdl, gen_prompt, max_new_tokens=256)
|
| 128 |
+
print(f"[hop 3] answer:\n{answer}")
|
| 129 |
+
```
|
| 130 |
+
|
| 131 |
+
The router returns one of the 15 subject labels listed below; the topic classifier and generator are selected from that label.
|
| 132 |
+
|
| 133 |
+
## All 31 models
|
| 134 |
+
|
| 135 |
+
### Hop 1 — Subject router (1 model)
|
| 136 |
+
|
| 137 |
+
| Subject | Base | Repo |
|
| 138 |
+
|---|---|---|
|
| 139 |
+
| (all 15 subjects) | Qwen3-0.6B | [stravoris/medmcq-subject-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-subject-classifier-qwen3-0.6b) |
|
| 140 |
+
|
| 141 |
+
### Hop 2 — Topic classifiers (15 models, Qwen3-0.6B)
|
| 142 |
+
|
| 143 |
+
| Subject | Repo |
|
| 144 |
+
|---|---|
|
| 145 |
+
| Anaesthesia | [stravoris/medmcq-anaesthesia-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-anaesthesia-classifier-qwen3-0.6b) |
|
| 146 |
+
| Anatomy | [stravoris/medmcq-anatomy-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-anatomy-classifier-qwen3-0.6b) |
|
| 147 |
+
| Biochemistry | [stravoris/medmcq-biochemistry-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-biochemistry-classifier-qwen3-0.6b) |
|
| 148 |
+
| Cell Biology & Histology | [stravoris/medmcq-cell-biology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-cell-biology-classifier-qwen3-0.6b) |
|
| 149 |
+
| ENT | [stravoris/medmcq-ent-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-ent-classifier-qwen3-0.6b) |
|
| 150 |
+
| Genetics | [stravoris/medmcq-genetics-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-genetics-classifier-qwen3-0.6b) |
|
| 151 |
+
| Microbiology | [stravoris/medmcq-microbiology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-microbiology-classifier-qwen3-0.6b) |
|
| 152 |
+
| Obstetrics & Gynaecology | [stravoris/medmcq-obstetrics-gynaecology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-obstetrics-gynaecology-classifier-qwen3-0.6b) |
|
| 153 |
+
| Ophthalmology | [stravoris/medmcq-ophthalmology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-ophthalmology-classifier-qwen3-0.6b) |
|
| 154 |
+
| Orthopaedics | [stravoris/medmcq-orthopaedics-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-orthopaedics-classifier-qwen3-0.6b) |
|
| 155 |
+
| Pathology | [stravoris/medmcq-pathology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-pathology-classifier-qwen3-0.6b) |
|
| 156 |
+
| Pharmacology | [stravoris/medmcq-pharmacology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-pharmacology-classifier-qwen3-0.6b) |
|
| 157 |
+
| Physiology | [stravoris/medmcq-physiology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-physiology-classifier-qwen3-0.6b) |
|
| 158 |
+
| Psychiatry | [stravoris/medmcq-psychiatry-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-psychiatry-classifier-qwen3-0.6b) |
|
| 159 |
+
| Radiology | [stravoris/medmcq-radiology-classifier-qwen3-0.6b](https://huggingface.co/stravoris/medmcq-radiology-classifier-qwen3-0.6b) |
|
| 160 |
+
|
| 161 |
+
### Hop 3 — Answer generators (15 models, Qwen3-1.7B)
|
| 162 |
+
|
| 163 |
+
| Subject | Repo |
|
| 164 |
+
|---|---|
|
| 165 |
+
| Anaesthesia | [stravoris/medmcq-anaesthesia-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-anaesthesia-qwen3-1.7b) |
|
| 166 |
+
| Anatomy | [stravoris/medmcq-anatomy-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-anatomy-qwen3-1.7b) |
|
| 167 |
+
| Biochemistry | [stravoris/medmcq-biochemistry-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-biochemistry-qwen3-1.7b) |
|
| 168 |
+
| Cell Biology & Histology | [stravoris/medmcq-cell-biology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-cell-biology-qwen3-1.7b) |
|
| 169 |
+
| ENT | [stravoris/medmcq-ent-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-ent-qwen3-1.7b) |
|
| 170 |
+
| Genetics | [stravoris/medmcq-genetics-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-genetics-qwen3-1.7b) |
|
| 171 |
+
| Microbiology | [stravoris/medmcq-microbiology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-microbiology-qwen3-1.7b) |
|
| 172 |
+
| Obstetrics & Gynaecology | [stravoris/medmcq-obstetrics-gynaecology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-obstetrics-gynaecology-qwen3-1.7b) |
|
| 173 |
+
| Ophthalmology | [stravoris/medmcq-ophthalmology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-ophthalmology-qwen3-1.7b) |
|
| 174 |
+
| Orthopaedics | [stravoris/medmcq-orthopaedics-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-orthopaedics-qwen3-1.7b) |
|
| 175 |
+
| Pathology | [stravoris/medmcq-pathology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-pathology-qwen3-1.7b) |
|
| 176 |
+
| Pharmacology | [stravoris/medmcq-pharmacology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-pharmacology-qwen3-1.7b) |
|
| 177 |
+
| Physiology | [stravoris/medmcq-physiology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-physiology-qwen3-1.7b) |
|
| 178 |
+
| Psychiatry | [stravoris/medmcq-psychiatry-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-psychiatry-qwen3-1.7b) |
|
| 179 |
+
| Radiology | [stravoris/medmcq-radiology-qwen3-1.7b](https://huggingface.co/stravoris/medmcq-radiology-qwen3-1.7b) |
|
| 180 |
+
|
| 181 |
+
## Collection and dataset
|
| 182 |
+
|
| 183 |
+
- **Collection** — [MedMCQ Medical Models](https://huggingface.co/collections/stravoris/medmcq-medical-models) (all 31 models grouped on the Hub).
|
| 184 |
+
- **Dataset** — [stravoris/medical-mcq-dataset](https://huggingface.co/datasets/stravoris/medical-mcq-dataset) (the single educational MCQ dataset every model was fine-tuned on; subject/topic slices feed the corresponding classifier and generator).
|
| 185 |
+
|
| 186 |
+
## Hardware
|
| 187 |
+
|
| 188 |
+
Every model in the pipeline runs on CPU; no GPU is required.
|
| 189 |
+
|
| 190 |
+
| Model class | Base | Approx. RAM |
|
| 191 |
+
|---|---|---|
|
| 192 |
+
| Subject classifier, topic classifiers | Qwen3-0.6B | ~2 GB |
|
| 193 |
+
| Answer generators | Qwen3-1.7B | ~4 GB |
|
| 194 |
+
|
| 195 |
+
A full three-hop call loads one 0.6B router, one 0.6B topic classifier, and one 1.7B generator — comfortably handled on a typical laptop. You can keep them resident in memory across calls, or load lazily based on the routed subject if RAM is tight.
|
| 196 |
+
|
| 197 |
+
## What this pipeline is not
|
| 198 |
+
|
| 199 |
+
These are **sample models for demonstration**, released as a public reference for the three-hop architecture. They have not been formally benchmarked and **must not** be used to make clinical decisions or provide medical advice. Returned answers and explanations may contain factual errors. A clinician should review every output before any educational use.
|
| 200 |
+
|
| 201 |
+
## License
|
| 202 |
+
|
| 203 |
+
Apache 2.0 across all 31 models and this guide. Base models ([`Qwen/Qwen3-0.6B`](https://huggingface.co/Qwen/Qwen3-0.6B) and [`Qwen/Qwen3-1.7B`](https://huggingface.co/Qwen/Qwen3-1.7B) from Alibaba's Qwen team) retain their original licenses too.
|