Instructions to use salihfurkaan/MedGate-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use salihfurkaan/MedGate-4B with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/Qwen3.5-4B") model = PeftModel.from_pretrained(base_model, "salihfurkaan/MedGate-4B") - jev-style
How to use salihfurkaan/MedGate-4B with jev-style:
pip install "jev-style[torch]"
from jev_style import JevStyle, noul, choice js = JevStyle.from_pretrained("salihfurkaan/MedGate-4B") out = js.decide("I was charged twice for one order.", { "billing": noul("This message is about billing."), "team": choice("Which team should handle it?", ["billing", "shipping", "tech"]), }) print(out["answers"]["team"]["choice"]) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Desktop
MedGate-4B
MedGate-4B is a Jev-style, non-autoregressive System 1 clinical decision and selective abstention gatekeeper.
In a single forward pass with zero output token generation, MedGate-4B scores diagnostic candidates, evaluates clinical evidence sufficiency (evidence_sufficient), and triggers human or System 2 escalation (needs_human_review) with calibrated probability estimates (ECE = 0.0098 in-domain).
Out-of-Distribution (OOD) Training and Evaluation Integrity
To ensure strict zero-shot evaluation integrity, zero rows from PubMedQA or MedQA-USMLE were included in training or calibration.
Stage 2 aligns the Stage 1 checkpoint (salihfurkaan/MedDecision-System1-3B) across three leak-free sources:
- Clinical Vignettes and Abstention (
salihfurkaan/meddecision-clinical-case-corpus): Selective abstention (needs_human_review,evidence_sufficient), triage urgency, and differential diagnosis selection. - Clinical Natural Language Inference (
MedNLI): Three-way clinical premise verification (entailment,contradiction,neutral) without biomedical abstract leakage. - Medical Board Exam QA (
MedMCQA): Cross-specialty biomedical reasoning across 21 clinical domains, deduplicated against all held-out test sets.
Benchmark Results
| Benchmark | Split / Regime | Stage 1 (MedDecision-System1-3B) |
MedGate-4B (Stage 2 OOD-Clean) |
|---|---|---|---|
meddecision-clinical-case-corpus |
In-Domain Test (n=984) |
94.46% (ECE: 0.0152) |
93.89% (Record: 89.23%, ECE: 0.0098) |
PubMedQA (Official Test) |
Zero-Shot OOD (n=500) |
71.20% (Macro-F1: 54.27%) |
75.20% (Macro-F1: 55.29%) |
MedQA-USMLE (4-Options) |
Zero-Shot OOD (n=1,273) |
Not evaluated | 69.91% (ECE: 0.0266) |
Note: On the official 500-question PubMedQA test split, MedGate-4B surpasses GPT-6 Luna (74.40%) completely zero-shot, with 0 PubMedQA training examples.
Quickstart
from unsloth import FastDecisionModel
model, tokenizer = FastDecisionModel.from_pretrained(
model_name="salihfurkaan/MedGate-4B",
max_seq_length=2048,
load_in_4bit=True,
)
FastDecisionModel.for_inference(model)
clinical_vignette = (
"A 64-year-old man with a 40-pack-year smoking history presents with progressive dysphagia "
"to solids over 3 months and 8 kg unintentional weight loss. Physical exam is unremarkable. "
"Upper endoscopy is scheduled."
)
rubric = {
"evidence_sufficient": {
"type": "noul",
"instructions": "Is the available clinical text sufficient to confirm a definitive diagnosis?",
},
"needs_human_review": {
"type": "noul",
"instructions": "Should this case be escalated for clinician or System 2 review before final diagnosis?",
},
"working_diagnosis": {
"type": "choice",
"instructions": "What is the primary suspected condition to rule out?",
"criteria": {
"esophageal_cancer": "Esophageal carcinoma",
"gerd": "Uncomplicated gastroesophageal reflux disease",
"achalasia": "Primary esophageal achalasia",
},
},
}
predictions = FastDecisionModel.predict(model, tokenizer, clinical_vignette, rubric)
for name, out in predictions.items():
probs = {k: round(v, 3) for k, v in out["probabilities"].items()}
print(f"{name}: answer={out['answer']} | probs={probs}")
Dual-Process Cascade with System 2 (Avicenna-8B-Base)
MedGate-4B is built to serve as the sub-100ms front-end gatekeeper in front of salihfurkaan/Avicenna-8B-Base. Cases where evidence_sufficient == True, needs_human_review == False, and decision confidence exceeds threshold (>= 0.85) resolve immediately in System 1, while uncertain or incomplete presentations escalate to Avicenna-8B-Base for multi-step System 2 clinical reasoning.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from unsloth import FastDecisionModel
sys1_model, sys1_tok = FastDecisionModel.from_pretrained(
model_name="salihfurkaan/MedGate-4B",
max_seq_length=2048,
load_in_4bit=True,
)
FastDecisionModel.for_inference(sys1_model)
sys2_tok = AutoTokenizer.from_pretrained("salihfurkaan/Avicenna-8B-Base")
sys2_model = AutoModelForCausalLM.from_pretrained(
"salihfurkaan/Avicenna-8B-Base",
torch_dtype=torch.float16,
device_map="auto",
)
def route_clinical_case(vignette: str, rubric: dict, confidence_threshold: float = 0.85):
sys1_out = FastDecisionModel.predict(sys1_model, sys1_tok, vignette, rubric)
needs_review = sys1_out["needs_human_review"]["answer"]
sufficient = sys1_out["evidence_sufficient"]["answer"]
dx_conf = max(sys1_out["working_diagnosis"]["probabilities"].values())
if sufficient and not needs_review and dx_conf >= confidence_threshold:
return {"route": "SYSTEM_1_MEDGATE_FAST", "decision": sys1_out}
prompt = (
f"Clinical Vignette:\n{vignette}\n\n"
f"System 1 Gate Flag: Evidence Sufficient={sufficient}, "
f"Working Diagnosis={sys1_out['working_diagnosis']['answer']} ({dx_conf:.2f}).\n"
"Perform a step-by-step clinical differential analysis and recommend next diagnostic steps:"
)
inputs = sys2_tok.apply_chat_template(
[{"role": "user", "content": prompt}],
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(sys2_model.device)
with torch.inference_mode():
outputs = sys2_model.generate(**inputs, max_new_tokens=512, temperature=0.3)
reasoning = sys2_tok.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
return {
"route": "SYSTEM_2_AVICENNA_ESCALATION",
"system1_gate": sys1_out,
"system2_reasoning": reasoning,
}
Limitations and Safety Disclaimer
- Research Use Only: This model is an academic research artifact for studying calibrated clinical decision routing and selective abstention. It is not a certified medical device and must never be used for autonomous clinical diagnosis or patient care.
- Bounded Rubric Dependency: Because
FastDecisionModelscores candidate options supplied at inference time, diagnostic accuracy depends on including relevant differentials in the inputcriteriadictionary. Always pair with human clinician oversight or a System 2 reasoning model whenneeds_human_reviewevaluates toTrue.
Citation
@misc{erik2026medgate4b,
author = {Salih Furkan Erik},
title = {MedGate-4B: Calibrated Jev-Style Discriminative System 1 Gatekeeper for Clinical Decision Support},
year = {2026},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/salihfurkaan/MedGate-4B}}
}
- Downloads last month
- 51
Datasets used to train salihfurkaan/MedGate-4B
presencesw/mednli
salihfurkaan/meddecision-clinical-case-corpus
Collection including salihfurkaan/MedGate-4B
Evaluation results
- Per-Decision Accuracy on salihfurkaan/meddecision-clinical-case-corpus (typed_decisions, test)test set self-reported0.939
- Full-Record Exact Match Accuracy on salihfurkaan/meddecision-clinical-case-corpus (typed_decisions, test)test set self-reported0.892
- Expected Calibration Error (ECE) on salihfurkaan/meddecision-clinical-case-corpus (typed_decisions, test)test set self-reported0.010
- Top-1 Accuracy (Zero-Shot OOD) on PubMedQA Official Test Split (n=500)test set self-reported0.752
- Macro-F1 on PubMedQA Official Test Split (n=500)test set self-reported0.553
- Top-1 Accuracy (Zero-Shot OOD) on MedQA-USMLE 4-Options Test Split (n=1,273)test set self-reported0.699
- Expected Calibration Error (ECE) on MedQA-USMLE 4-Options Test Split (n=1,273)test set self-reported0.027