xphil — Truth-Grounded Clinical Reasoning on the Edge
What Google's AMIE does in the cloud — offline, in Tamil, on a ₹8,000 phone.
xphil is a governed clinical-reasoning AI fine-tuned on Gemma 4 E4B (unsloth/gemma-4-E4B-it) via QDoRA (QLoRA + DoRA) using the Unsloth framework. It runs fully offline in Madurai Tamil on a ₹8,000 Android phone, measures vital signs from the phone camera via rPPG, and reasons over real clinical trajectories — without any LLM imagining patient data.
No LLM imagined any training data. xphil uses a 3-layer architecture:
L1 — Raw Truth: 11 real-human dataset families spanning cognitive decline trajectories, ICU clinical outcomes, orthopedic imaging, radiology, speech biomarkers, mental health, and Tamil language — all measured from real patients, not synthesized.
L2 — Structured Truth: Deterministic Python extractors produce unified capability JSON (cognition, reasoning, emotion, metacognition, medical, vitals, visual, auditory) — no LLM in this stage.
L3 — Grounded Generation: Teacher LLM translates L2 JSON into clinical language — forbidden to invent. Every claim must trace to a specific L2 field.
37,892 training samples (13,945 image + 23,947 text) through 5 quality gates:
1import torch
2from unsloth import FastVisionModel
34# Load adapter5model, processor = FastVisionModel.from_pretrained(6"philip11/xphil-gemma-4-E4B",7 dtype=torch.bfloat16,8 load_in_4bit=True,9)10FastVisionModel.for_inference(model)11tokenizer =getattr(processor,"tokenizer", processor)1213# IMPORTANT: do NOT include <|think|> in the system prompt.14# That token activates Gemma 4's native thinking channel and consumes15# the full token budget on planning rather than the clinical response.16SYSTEM =(17"You are xphil, a governed clinical reasoning AI. Every claim must trace to "18"the evidence provided. Respond in the user's language (Tamil/Tanglish/English). "19"Confidence as [min,max] always. Add ✅/⚠️/❌ per clinical claim. "20"End with: 'Not medical advice — consult a licensed professional.'"21)2223defask_xphil(question:str, image=None):24 user_content =[]25if image isnotNone:26 user_content.append({"type":"image","image": image})27 user_content.append({"type":"text","text": question})2829 messages =[30{"role":"system","content": SYSTEM},31{"role":"user","content": user_content if image else question},32]33 rendered = tokenizer.apply_chat_template(34 messages, tokenize=False, add_generation_prompt=True,35)3637if image isnotNone:38 inputs = processor(images=[image], text=rendered, return_tensors="pt").to("cuda")39else:40 inputs = tokenizer(text=rendered, return_tensors="pt").to("cuda")4142with torch.inference_mode():43 out = model.generate(44**inputs,45 max_new_tokens=512,46 do_sample=False,47 temperature=1.0, top_p=0.95, top_k=64,48 eos_token_id=tokenizer.eos_token_id,49 use_cache=True,50)51 new_toks = out[0][inputs["input_ids"].shape[1]:]52return tokenizer.decode(new_toks, skip_special_tokens=True).strip()5354# Text-only55print(ask_xphil(56"Patient 71F, moderate dementia, HMSE dropped from 14 to 11 in one week. "57"Fever 37.8C, refusing food. What is the most likely cause?"58))5960# With image (knee X-ray)61from PIL import Image
62img = Image.open("knee_xray.jpg").convert("RGB")63print(ask_xphil("What is the problem with this knee?", image=img))
Critical inference note: Do not pass enable_thinking=True/False to apply_chat_template and do not prepend <|think|> to the system prompt. The model's clinical reasoning is encoded in its weights — it responds directly with structured output.
Real Output Examples
Acute dementia deterioration (text):
Q: Patient 71F, moderate dementia, HMSE 14→11 in one week. Fever 37.8C, refusing food.
Unknown meds from another hospital. Most likely cause?
Confidence: [0.6,0.85]
✅ Most likely cause of acute deterioration: UTI (UTI is a common cause of
acute confusion in dementia patients).
✅ First step for caregiver: Check urine for signs of infection.
❌ Do not administer any medication without physician's order.
Not medical advice — consult a licensed professional.
Knee X-ray (image):
Q: What is the problem with this knee? I took this X-ray at a government hospital.
Confidence: [0.65,0.83]
✅ Image Type: X-ray
⚠️ Clinical Indication: Knee pain, suspected osteoarthritis or other joint issue.
❌ Cannot Diagnose: Definitive diagnosis requires clinical examination and history.
✅ Radiographic Findings:
· Joint space narrowing, particularly in the medial compartment.
· Osteophyte formation (bone spurs) at the joint margins.
· Subchondral sclerosis (increased density beneath the cartilage).
❌ Cannot Rule Out: Meniscal tear, osteonecrosis.
⚠️ Recommendation: Consult an Orthopedic Surgeon with this X-ray and symptom history.
Not medical advice — consult a licensed professional.
Brain MRI + caregiver question:
Q: My mother is 71, memory problems for 3 years. What does this brain scan show?
Confidence: [0.73,0.91]
✅ The brain scan shows significant white matter hyperintensities, particularly
in the periventricular and subcortical regions, consistent with small vessel
ischemic changes (microangiopathy).
⚠️ This pattern is highly suggestive of vascular dementia or Alzheimer's disease,
given the age and memory complaints.
❌ No clear evidence of large vessel disease or significant hippocampal atrophy
on this single scan.
Not medical advice — consult a licensed professional.
Benchmarks
Model
Size
MedQA
Offline
Tamil
₹0
₹8K Phone
xphil-E4B
4.5B
52.0%
✅
✅
✅
✅
MedGemma-4B
4B
64.4%
❌
❌
❌
❌
OpenBioLLM-70B
70B
78.2%
❌
❌
❌
❌
GPT-4o
~1.8T
~90%
❌
limited
❌
❌
Gemma 4 E4B base
4.5B
~52%
❌
❌
❌
❌
No frontier model achieves all five simultaneously — by architectural impossibility.
Intended Use
xphil is a caregiver-support and educational tool. It is designed to:
Help caregivers of dementia patients understand clinical trajectories
Provide evidence-grounded information in Tamil/Tanglish/English
Run offline in areas with no internet connectivity
Support informed conversations with licensed healthcare professionals
xphil is NOT a medical device and does NOT provide medical advice. Always consult a licensed healthcare professional for medical decisions.
Limitations
Training data is primarily from Western populations; Indian normative calibration is approximate
PUP compliance: Gemma Prohibited Use Policy §2.2/§3.3/§3.4/§3.6 adhered to
No patient data redistribution: All training data either public or used under DUA; raw data never redistributed
Attribution & License
Built on Gemma 4 E4B (unsloth/gemma-4-E4B-it).
Fine-tuned using Unsloth QDoRA stack.
Gemma is a trademark of Google LLC.
The adapter weights are released under Apache 2.0.
See Gemma Terms of Use for base model usage.
Citation
bibtex
1@misc{xphil2026,
2 title = {xphil: Truth-Grounded Reality Distillation for Edge Medical AI},
3 author = {Philip Simon Derock},
4 year = {2026},
5 note = {Kaggle × Google DeepMind Gemma 4 Good Hackathon submission.
6 Fine-tuned on Gemma 4 E4B via QDoRA using Unsloth.
7 Gemma is a trademark of Google LLC.}
8}