Instructions to use sarakhosravi/MedGuard-ShieldGemma-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use sarakhosravi/MedGuard-ShieldGemma-9B with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
MedGuard-ShieldGemma-9B
LoRA adapters for patient-conditioned medication guarding, trained on MedGuardBench. Given a structured patient profile and a proposed prescription, the model returns a safe/unsafe verdict and the 17 risk categories that justify it.
These are the selected checkpoints for each training arm, one per subfolder.
| Subfolder | Training arm | Acc | Rec | FPR | Mic | Mac | EM |
|---|---|---|---|---|---|---|---|
sft/ |
SFT | 91.2 | 96.8 | 14.9 | 74.9 | 68.9 | 67.1 |
cu/ |
Patient Profile Unrolling (CU) | 91.8 | 96.0 | 12.9 | 74.8 | 67.7 | 66.5 |
grpo/ |
Guided GRPO | 86.1 | 98.9 | 27.7 | 73.0 | 67.1 | 61.9 |
Metrics (%) are on the 729-row drug-disjoint MedGuardBench test split. Acc is verdict accuracy, Rec is unsafe recall, FPR is the false-positive rate on safe prescriptions, and Mic / Mac / EM are the 17-category micro-F1, macro-F1 and exact match.
- SFT: schema-aligned supervised fine-tuning.
- CU: Patient Profile Unrolling. One extra epoch from the SFT checkpoint in which the model first checks each patient-chart field against the drug's safety rules, then gives its verdict.
- Guided GRPO: GRPO with a verifiable safety reward and teacher-guided rollouts, starting from the merged SFT model.
Base model each adapter was trained on:
sft/:google/shieldgemma-9bcu/:google/shieldgemma-9bgrpo/:merged google/shieldgemma-9b + sft/
Usage
The SFT and CU adapters apply directly to the base model they were trained on (google/shieldgemma-9b; the original model is google/shieldgemma-9b).
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base = AutoModelForCausalLM.from_pretrained("google/shieldgemma-9b", device_map="auto")
tok = AutoTokenizer.from_pretrained("sarakhosravi/MedGuard-ShieldGemma-9B", subfolder="cu")
model = PeftModel.from_pretrained(base, "sarakhosravi/MedGuard-ShieldGemma-9B", subfolder="cu")
Guided GRPO
The grpo/ adapter was trained on top of the merged SFT model, so apply sft/ first:
base = AutoModelForCausalLM.from_pretrained("google/shieldgemma-9b", device_map="auto")
model = PeftModel.from_pretrained(base, "sarakhosravi/MedGuard-ShieldGemma-9B", subfolder="sft").merge_and_unload()
model = PeftModel.from_pretrained(model, "sarakhosravi/MedGuard-ShieldGemma-9B", subfolder="grpo")
Decode greedily (temperature 0). The CU arm writes a verification trace before its verdict, so allow at least 2,048 new tokens.
Intended use
Research on medication-safety guardrails only. These models are not medical devices and must not be used for clinical decisions.
- Downloads last month
- -
Model tree for sarakhosravi/MedGuard-ShieldGemma-9B
Base model
google/shieldgemma-9b