Instructions to use boweiiismyname/trialmatch-gemma4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use boweiiismyname/trialmatch-gemma4 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/gemma-4-E4B-it-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "boweiiismyname/trialmatch-gemma4") - Transformers
How to use boweiiismyname/trialmatch-gemma4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="boweiiismyname/trialmatch-gemma4") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("boweiiismyname/trialmatch-gemma4", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use boweiiismyname/trialmatch-gemma4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "boweiiismyname/trialmatch-gemma4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "boweiiismyname/trialmatch-gemma4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/boweiiismyname/trialmatch-gemma4
- SGLang
How to use boweiiismyname/trialmatch-gemma4 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "boweiiismyname/trialmatch-gemma4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "boweiiismyname/trialmatch-gemma4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "boweiiismyname/trialmatch-gemma4" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "boweiiismyname/trialmatch-gemma4", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use boweiiismyname/trialmatch-gemma4 with Docker Model Runner:
docker model run hf.co/boweiiismyname/trialmatch-gemma4
trialmatch-gemma4
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.
Model Details
Model Description
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
- Developed by: Bowei (@boweiiismyname)
- Model type: Causal LM — LoRA adapter (text-only fine-tune on a multimodal base)
- Language(s): English
- License: Apache 2.0
- Finetuned from:
unsloth/gemma-4-E4B-it-unsloth-bnb-4bit
Model Sources
- Repository: Boweii22/TrialMatch
- Demo: TrialMatch runs fully offline — see the repo for setup instructions
Uses
Direct Use
Load 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.
Downstream Use
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.
Out-of-Scope Use
- Not a medical device. This model does not provide medical advice, diagnosis, or treatment decisions.
- Not suitable for final enrollment decisions — it is a pre-screening tool only.
- Not suitable for conditions or trial types not represented in the training data.
Bias, Risks, and Limitations
- Training data was synthetically generated using Gemma 4 — the model may reflect biases in that generation process.
PARTIALcases are the hardest to distinguish (both misclassifications in the benchmark werePARTIALground-truth labels).- The model has not been validated against real patient records or regulatory enrollment criteria.
- Eligibility criteria text is truncated to 1500 characters — very long criteria sections may lose information.
Recommendations
Use exclusively as a pre-screening aid. Any positive result must be reviewed by a licensed physician before a patient contacts a trial site.
How to Get Started with the Model
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))
Training Details
Training Data
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.
Training Procedure
Training Hyperparameters
- Training regime: bf16 mixed precision (T4 GPU)
- LoRA rank (r): 16
- LoRA alpha: 16
- Target modules: language layers only (
finetune_vision_layers=False) - Epochs: 3
- Batch size: 2 (effective 8 with gradient accumulation × 4)
- Learning rate: 2e-4, linear schedule with 5 warmup steps
- Optimizer: adamw_8bit
- Max sequence length: 2048
Speeds, Sizes, Times
- Hardware: Google Colab T4 GPU (free tier)
- Training time: ~1.5 hours
- Adapter size: ~50 MB (LoRA weights only)
Evaluation
Testing Data
20 held-out examples from training_data.jsonl, sampled with random.seed(99) (different from training split).
Metrics
Exact-match accuracy on VERDICT field (MATCH / PARTIAL / NO). Confidence score is model-reported (0–100).
Results
| 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).
Environmental Impact
- Hardware: NVIDIA T4 (Google Colab)
- Hours used: ~1.5 hours
- Cloud Provider: Google
- Compute Region: us-central1
Technical Specifications
Model Architecture
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.
Software
unsloth(FastVisionModel)trl(SFTTrainer + SFTConfig)peft 0.19.1transformers- Python 3.10, CUDA 12.x
Model Card Authors
Bowei — built as part of the Gemma 4 Good Hackathon submission.
Model Card Contact
Open an issue on Boweii22/TrialMatch.
Framework versions
- PEFT 0.19.1
- Downloads last month
- 2
Model tree for boweiiismyname/trialmatch-gemma4
Base model
google/gemma-4-E4B