Spaces:
Running
Download pkg/README.md from parsa-hke/stroke-copilot: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/spaces/parsa-hke/stroke-copilot/resolve/main/pkg/README.md
- Command line
-
hf download hf://spaces/parsa-hke/stroke-copilot/pkg/README.md
-
curl -L -o README.md https://huggingface.co/spaces/parsa-hke/stroke-copilot/resolve/main/pkg/README.md
Stroke Decision Copilot
MAAI 901 (Deep Learning for Visual Data) and MAAI 902 (NLP & LLMs) group project, MSc Applied AI, University of Wollongong in Dubai.
Vision models read the stroke CT (haemorrhage on plain CT; core and penumbra on CT perfusion). A language model reasons over those findings, a triage note and a rulebook written in our own words from the 2026 AHA/ASA guideline and the DAWN and DEFUSE-3 trials. A verifier then checks every claim in its rationale against its sources. The research output is a hallucination-rate comparison across six language models on a clinical decision task with known inputs, and how imaging errors carry through to treatment decisions.
Research prototype β not for clinical use.
- Live demo: huggingface.co/spaces/parsa-hke/stroke-copilot: the pipeline story, a case explorer where every claim links to its source, the results as charts, and a scenario builder that runs the reasoner and the verifier live.
- Plan and decisions: STROKE_COPILOT_PLAN.md (Β§2 lists every fixed decision). Progress: CHANGELOG.md.
How it fits together
plain CT βββΊ Vision B (haemorrhage) βββ
ββββΊ vision_output.json βββ
CT perfusion βββΊ Vision A (core/penumbra) β βΌ
triage note ββββββββββββββββββββββββββββββββββββββββββΊ NLP A: reasoner βββΊ recommendation.json
guideline rulebook (whole) ββββββββββββββββββββββββββββ β
βΌ
NLP B: verifier βββΊ every claim traced or flagged
The vision and NLP sides meet only at the contract, schemas/vision_output.json.
Results at a glance
Development results are on 129 ISLES'24 cases (five folds, each case scored by the model that did not train on it) and on RSNA validation. Held-out results are on 20 ISLES'24 cases opened once, after the analyses were fixed in advance (docs/PHASE4_PREREGISTRATION.md).
| Component | Result |
|---|---|
| Vision A (nnU-Net 3d_fullres) | Dice 0.215 Β± 0.046 against the rCBF < 30% threshold's 0.111 Β± 0.031 (paired +0.104 [+0.078, +0.133]); absolute volume error 23.5 against 25.2 mL, not a clear difference. Held-out: Dice 0.18 (five-fold ensemble). |
| Vision B (ResNet-50, RSNA) | Test split, opened once: scan AUC 0.9805 [0.974, 0.986], sensitivity 0.962, specificity 0.885 at the chosen threshold, ECE 0.015. On ISLES'24 it flags 68 of 129 presumed bleed-free scans, a domain shift traced to brain tissue, not the skull base (Grad-CAM and SHAP). |
| Hallucination rate (with the rulebook; 5 fixtures, 150 scenarios, 20 real cases per model; verifier rates, upper bounds) | Sonnet 5.5 4.0%, Qwen3.5-27B 5.0%, Gemma 3 27B 17.1%, MedGemma 27B 17.7%, Gemma 3 4B 40.6%, Gemma 3 4B LoRA-tuned 13.3%. |
| Rulebook effect | Giving the whole rulebook cuts false-content claims by 8 to 15 percentage points for every model. |
| Verifier validity | Seeded errors: recall β₯ 0.80 on every sub-type, 1% false flags. 100 human-labelled claims: verifierβhuman agreement 0.61; humans confirmed 18 of its 54 flags; humanβhuman ΞΊ 0.27. |
| End to end, held-out (predicted vision) | Decisions right: Sonnet 22/23, Gemma 3 27B 22/23, MedGemma 21/21, Qwen 13/13 (9 format failures), tuned 4B 21/23, base 4B 3/23. Sonnet's one wrong decision came from a false bleed flag the verifier could not see. |
Phase 5 additions (report only, after the freeze; all run by 20 Nov 2026 except the clinicians' answers): exact Shapley values of the rule engine's inputs (the occlusion site and the clock decide most treatments; the core volume rarely does), of Vision A's input channels, Vision B's CT windows and the small reasoners' inputs (the base Gemma 3 4B recommends thrombolysis whatever it is told; the tuned one follows the clock as the rules do), pixel attributions beside Grad-CAM, a surrogate of the verifier's flags, token attributions of the retriever, 35 Student's t-tests beside the bootstrap results, a subgroup analysis, a retrieval re-test, an ONNX export, a re-judging of the 100 human-labelled claims by a non-Claude judge (GPT-6 Luna: 3 of 100 verdicts changed, agreement with the humans 0.62 against Haiku's 0.61), a BiomedCLIP comparison (frozen BiomedCLIP: scan AUC 0.90 as a linear probe and 0.75 zero-shot, against the ResNet-50's 0.98), and a clinician review pack. Summaries for the reports: docs/PHASE5_HANDOVER.md.
Quick start
pip install git+https://github.com/parsa-hke/strokecopilot.git
For local development and the tests (no data needed, under a minute):
pip install -e ".[dev]"
pytest
The extras group what each part needs: isles and rsna (data and vision), retrieval, llm (Anthropic and OpenAI-compatible clients), space (the demo server), finetune, and analysis (SHAP, surrogates and t-tests).
Reproduce the hallucination table without an API key. The replay bundle holds the saved answers and verifier caches for the fixtures and the 150 synthetic scenarios (no patient data). Download replay_bundle.tar.gz from the release of the submission tag, then:
python -m strokecopilot.pipeline.replay run --bundle replay_bundle.tar.gz
It checks the bundle's sha256, rescores every model and arm offline from the cached verdicts, checks each rate against the reported one, and prints the table.
Check a vision output against the contract:
from strokecopilot.contract import load_vision_output
out = load_vision_output("fixtures/fx02_thrombectomy_large_mismatch.json")
Data
Nothing under data/ or runs/ is committed, and no data or model weights are distributed. ISLES'24 (Zenodo record 17652035, CC BY-NC-SA 4.0) and the RSNA Intracranial Haemorrhage data (Kaggle, competition rules) must be obtained from their sources; the team kept them on a shared Google Drive and, for RSNA, on Kaggle only. The guideline and trial texts stay with their publishers: the reasoner sees only our own-words rulebook (corpus/RULEBOOK.md). Terms: docs/DATA_USE.md.
Notebooks
Thin: each calls the package. Colab notebooks open with the badge; Kaggle notebooks are uploaded to Kaggle with the RSNA datasets attached.
Repository layout
src/strokecopilot/ holds all logic: data/, vision/, contract/, nlp/ (corpus, notes, reasoner, verifier), pipeline/ (runs, comparisons, held-out analysis, replay), demo/ (the Space) and analysis/ (Phase 5). schemas/ holds the contracts, fixtures/ the hand-written test cases, corpus/ the rulebook, prompts/ every prompt version, docs/ the decisions' working papers, and tests/ runs without data. Full layout: plan Β§3.
Licence and citation
Code: MIT. Data and model weights are not covered and not distributed (see above). Please cite with CITATION.cff, and cite ISLES'24 (arXiv:2408.11142, arXiv:2408.10966) and RSNA ICH (Flanders et al., Radiol Artif Intell 2020) when you use their data.