Downloads · 30 days
6
7% of all-time downloads
boweiiismyname/trialmatch-gemma4
trialmatch-gemma4 is a text generation model from boweiiismyname. Use it when you need the model to write or continue text. It is set up for peft.
LoRA fine-tune of Gemma 4 E4B for clinical trial eligibility pre-screening. Given a patient profile and a trial's eligibility criteria, the model returns a structured 5-field verdict used inside TrialMatch — a fully o…
Downloads · 30 days
6
7% of all-time downloads
All-time downloads
90
Public
Parameters
4.3B
8.9 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors8.7 GB · 100%
From the Hugging Face model README
LoRA fine-tune of Gemma 4 E4B for clinical trial eligibility pre-screening. Given a patient profile and a trial's eligibility criteria, the model returns a structured 5-field verdict used inside TrialMatch — a fully offline, CPU-only clinical trial matching app.
trialmatch-gemma4 is a LoRA adapter trained on top of unsloth/gemma-4-E4B-it-unsloth-bnb-4bit. It is fine-tuned for a single task: reading a structured patient profile + clinical reasoning summary + trial eligibility criteria text and returning a structured eligibility verdict.
The model outputs exactly five fields:
VERDICT: MATCH | PARTIAL | NO
CONFIDENCE: 0–100
REASON: one plain-English sentence
DISQUALIFIERS: exact criterion text, or NONE
NEXT STEP: what the patient should do next
unsloth/gemma-4-E4B-it-unsloth-bnb-4bitLoad the LoRA adapter on top of Gemma 4 E4B and pass a patient profile + eligibility criteria to get a structured MATCH/PARTIAL/NO verdict. See How to Get Started below.
Integrated into TrialMatch as the eligibility matching step. The app extracts a 13-field patient profile from a PDF, searches a local trial database, and passes each trial through this model to produce verdicts displayed in the Gradio UI.
PARTIAL cases are the hardest to distinguish (both misclassifications in the benchmark were PARTIAL ground-truth labels).Use exclusively as a pre-screening aid. Any positive result must be reviewed by a licensed physician before a patient contacts a trial site.
from peft import PeftModel
from transformers import AutoTokenizer, AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained(
"unsloth/gemma-4-E4B-it-unsloth-bnb-4bit",
load_in_4bit=True,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained("boweiiismyname/trialmatch-gemma4")
model = PeftModel.from_pretrained(base_model, "boweiiismyname/trialmatch-gemma4")
prompt = """You are a clinical trial eligibility screener.
PATIENT PROFILE:
{patient_profile}
CLINICAL REASONING:
{clinical_reasoning}
ELIGIBILITY CRITERIA:
{eligibility_criteria}
Return exactly:
VERDICT: MATCH|PARTIAL|NO
CONFIDENCE: 0-100
REASON: one sentence
DISQUALIFIERS: criterion text or NONE
NEXT STEP: what to do next"""
inputs = tokenizer(text=prompt.format(
patient_profile="...",
clinical_reasoning="...",
eligibility_criteria="...",
), return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=120, do_sample=False)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
120+ synthetic patient profiles generated by Gemma 4 for 60 real recruiting trials sourced from ClinicalTrials.gov. Each profile was run through the base TrialMatch matcher to produce a ground-truth label. Profiles were split roughly 50/50 MATCH-leaning and NO-leaning to prevent class imbalance. Stored as training_data.jsonl.
finetune_vision_layers=False)20 held-out examples from training_data.jsonl, sampled with random.seed(99) (different from training split).
Exact-match accuracy on VERDICT field (MATCH / PARTIAL / NO). Confidence score is model-reported (0–100).
| Metric | Fine-tuned Gemma 4 E4B |
|---|---|
| Accuracy | 90.0% (18 / 20) |
| Avg confidence score | 96.5 / 100 |
| Correct MATCH verdicts | 3 / 3 (100%) |
| Avg response time (T4 GPU) | 25.9s / example |
Both misclassifications were PARTIAL ground-truth — the most ambiguous category. All 3 true MATCH cases were correctly identified, which is the critical metric for a pre-screening tool (missing a match costs a patient trial access).
LoRA adapters (r=16) applied to language attention and MLP layers of Gemma 4 E4B. Vision layers are frozen — the adapter is text-only. Base model loaded in 4-bit NF4 quantisation via bitsandbytes.
unsloth (FastVisionModel)trl (SFTTrainer + SFTConfig)peft 0.19.1transformersBowei — built as part of the Gemma 4 Good Hackathon submission.
Open an issue on Boweii22/TrialMatch.