ClinicDx V1 is a fine-tuned multimodal clinical decision support (CDS) model based on google/medgemma-4b-it. It is trained to generate structured, evidence-grounded clinical assessments from patient presentations, integrating a retrieval-augmented knowledge base (KB) pipeline and an audio input pathway for voice-driven clinical observation extraction.
ClinicDx is an open-source trimodal inference system for edge clinical AI — combining a medical ASR encoder, a learned audio projector, and a fine-tuned 4B clinical LLM in a single llama.cpp binary, deployable fully offline on consumer hardware. For research contributions, open problems, and comparison to prior work, see RESEARCH.md on GitHub.
This repository contains all four artifacts needed to run the full system with llama-server:
File
Size
Description
clinicdx-v1-q8.gguf
3.9 GB
ClinicDx V1 language model (Q8_0 quantisation)
medasr-encoder.gguf
401 MB
MedASR Conformer encoder (frozen, 105M params)
audio-projector-v3-best.gguf
46 MB
AudioProjector v3 — best checkpoint (step 40000, val LM 0.1042)
who_knowledge_vec_v2.mv2
1.1 GB
WHO/MSF knowledge base v2.1 (27,860 chunks, BM25 + semantic hybrid)
Knowledge Base
The who_knowledge_vec_v2.mv2 index contains 27,860 chunks from WHO and MSF clinical guidelines, built via a Docling + HybridChunker pipeline with safety keyword detection for life-threatening conditions.
The retrieval pipeline uses hybrid search (BM25 + EmbedGemma 300M semantic, merged via Reciprocal Rank Fusion) followed by a 4-slot clinical intent reranker that extracts condition, severity, population, and task from each query and rescores hits with multiplicative penalties (×0.12 for off-condition, ×0.35 for severity mismatch, ×0.30 for wrong population) and additive boosts for slot alignment. The reranker covers 30+ clinical conditions with inclusion/exclusion patterns and condition-specific overrides.
During CDS inference, the model controls its own retrieval via a multi-turn ReAct loop — emitting <KB_QUERY> tags that the middleware resolves against this index and injects as <KB_RESULT> context, for up to 5 retrieval turns per request.
Model Description
ClinicDx V1 is a LoRA-fine-tuned and fully merged version of MedGemma 4B Instruct. It was trained with input masking (only model output turns are trained; user and KB turns are masked) on a quality-filtered dataset of 27,592 clinical conversations augmented with KB retrieval.
The model generates structured 6-section responses with inline citations sourced from retrieved knowledge base content.
LoRA adapters: Merged into base weights — no adapter files needed at inference
Vision tower: Present (inherited from MedGemma base, frozen, not used in CDS or Scribe)
Audio projector: Included in this repository as audio-projector-v3-best.gguf
Audio Projector & Voice Input
The ClinicDx production server combines this model with a MedASR encoder and a lightweight AudioProjector to enable voice-to-CDS inference. The architecture mirrors how Gemma3 integrates vision — a frozen encoder feeds a trainable projector whose output is injected into the LLM's embedding sequence.
Full System Architecture
Patient audio (16kHz mono WAV)
|
v
MedASR Conformer Encoder (frozen, 105M params)
Mel spectrogram (128 bins, hop=160, n_fft=512)
Natural log + 1e-5 clamp normalisation
-> 17-layer Conformer encoder, 512 hidden dim
-> [B, T_enc, 512] (T_enc ≈ audio_seconds × 50)
|
v
AudioProjector v3 (trainable, 11,806,720 params)
Frame stacking k=4: [B, T_enc, 512] -> [B, T_enc/4, 2048]
Linear(2048 → 2560, bias=False)
RMSNorm(2560)
GELU
Linear(2560 → 2560, bias=False)
LayerNorm(2560) [ln_final — added in v3]
Pad (learned padding embedding) or truncate to 64 tokens
-> [B, 64, 2560] (MedGemma embedding space)
|
v
ClinicDx V1 Language Model (4.3B params)
<image_soft_token> × 64 placeholders in the text sequence
are replaced with projected audio embeddings via masked_scatter
(reuses Gemma3's image token injection mechanism)
|
v
Structured medical observations (key: value format)
AudioProjector Architecture Detail
The Gemma3AudioProjector is the only trainable component during audio projector training. It is a 2-layer MLP with frame stacking and a final LayerNorm:
Step 40,000 produced the best generalisation (lowest val LM loss). Training continued for an additional 15,000 steps but did not improve val LM loss, indicating overfitting onset. The audio-projector-v3-best.gguf file contains the weights from this step.
Loss functions:
L_lm — Cross-entropy on target output tokens (main loss)
L_contrastive — Cosine similarity between projected audio embeddings
and concept text embeddings (single-phrase clips only)
L_total = L_lm + 0.1 × L_contrastive
Audio Token Details
The audio pathway reuses Gemma3's existing image token injection mechanism. The audio soft token (<image_soft_token>, ID 262144) is repurposed as the audio placeholder. No new tokens are added to the vocabulary.
Token
ID
Purpose
<start_of_image>
255,999
Begin-of-audio delimiter (reused for audio)
<end_of_image>
256,000
End-of-audio delimiter (reused for audio)
<image_soft_token>
262,144
Audio embedding placeholder (×64 per clip)
The system prompt uses <start_of_audio> / <end_of_audio> as human-readable markers in the text, while the tokenised form uses the image token IDs above for embedding injection.
Running with llama-server (GGUF — Recommended)
The fastest deployment path uses the three GGUF files in this repository with a CUDA-enabled llama-server build that includes --medasr-encoder and --audio-proj support.
Prerequisites
NVIDIA GPU with ≥8 GB VRAM (≥12 GB recommended for full Q8 + encoder + projector)
llama-server built with CUDA and MedASR/audio-projector support
ffmpeg available on the host (for audio transcoding to 16kHz PCM-16 WAV)
Note:--parallel 1 is required. The audio extraction endpoint (/v1/audio/extract) performs a blocking llama_decode on the shared context; parallel slots cause assertion failures.
Audio Inference (via REST API)
bash
1# Transcode browser audio to required format first2ffmpeg -i input.webm -ar 16000 -ac 1 -c:a pcm_s16le output.wav
34# Send to the audio extraction endpoint5curl -X POST http://localhost:8180/v1/audio/extract \6 -H "Content-Type: audio/wav"\7 --data-binary @output.wav
The endpoint returns structured key: value observations matching the clinical manifest provided in the system prompt.
Clinical decision support for trained healthcare professionals
Structured differential diagnosis generation
Evidence-grounded treatment planning with KB citations
Voice-driven clinical observation extraction in low-resource clinical settings
Not intended for direct patient-facing use or autonomous clinical decision making
Limitations and Open Problems
No formal clinical validation. Accuracy metrics (86.25% CDS, 84% Scribe key accuracy) are measured on held-out synthetic data, not on real clinical encounters. A prospective evaluation with practicing clinicians is the highest-priority gap.
English only. All CDS outputs, Scribe extraction, and KB retrieval operate in English. Multilingual support (Swahili, Amharic, Hausa, Yoruba) is not yet implemented.
Audio token norm mismatch. Projected audio token norms are 360-620x larger than text token norms in the LLM embedding space. The current mitigation uses adaptive norm alignment loss, but this remains an active area of investigation.
Synthetic training data. Trained on curated synthetic/augmented clinical data — real-world performance may vary.
KB-dependent for best results. Knowledge base integration requires the ClinicDx retrieval pipeline; standalone use generates structure but without live KB citations.
Audio projector trained on synthetic speech. Accuracy on natural conversational speech, accented English, or noisy clinical environments may be lower.
Q8 quantization chosen empirically. Q8_0 was selected over Q4 variants because lower quantization degraded structured output behavior (THINK block coherence, KB query emission) more than perplexity. No systematic ablation study has been conducted.
No ARM / low-power benchmarks. Validated on x86_64 with NVIDIA GPUs and CPU-only mode. Latency on ARM edge devices is unknown.
The model may produce plausible-sounding but incorrect clinical information — always verify with a qualified clinician.
License
This model is released under the Gemma Terms of Use. Use is subject to those terms.