--- license: apache-2.0 base_model: google/gemma-4-E4B-it language: - en - fr - rw library_name: gguf pipeline_tag: text-generation tags: - clinical-nlp - information-extraction - structured-output - json - gguf - lora - gemma4 --- # medx-gemma4-e4b A fine-tune of [Gemma 4 E4B-it](https://huggingface.co/google/gemma-4-E4B-it) that reads one clinical note and returns the facts as a single flat JSON object. The schema goes in the system prompt: the default schema has 44 fields (demographics, vitals, social history, symptoms, history, medications, labs, assessment), and a deployer can rename fields, take a subset, add typed custom fields or ask for nulls without retraining. Notes may be in English, French, Kinyarwanda or a mix. The model answers directly, with thinking off. **Research model, not a medical device.** It was trained on model-generated notes whose labels no clinician has reviewed. Do not use its output for clinical decisions without human verification. ## Files | File | What it is | |---|---| | `medx-gemma4-e4b.Q8_0.gguf` | The shipped model, merged and quantized to Q8_0 for llama.cpp (8.0 GB) | | `medx-gemma4-e4b.BF16-mmproj.gguf` | Vision projector exported with it; not needed for text-only extraction | | `adapters/run2_brand/` | LoRA adapter (rank 32, alpha 32) for `google/gemma-4-E4B-it`: stage 1, 30,000 English rows with brand-name drug mentions | | `adapters/topup/` | LoRA adapter (rank 32, alpha 32) for the **merged stage-1 model**: stage 2, 7,980 rows of French, Kinyarwanda, long English dictations and fresh English notes | To rebuild the model in Transformers: load `google/gemma-4-E4B-it`, apply `adapters/run2_brand`, merge it, then apply `adapters/topup` and merge again. The GGUF is the result of exactly that. ## Usage (llama.cpp) ```bash llama-server -m medx-gemma4-e4b.Q8_0.gguf -c 8192 --jinja \ --chat-template-kwargs '{"enable_thinking": false}' --temp 0 ``` Send the schema as the system message and the note as the user message. Thinking must stay off: the model was trained without reasoning and the chat template otherwise opens a thought channel. Use greedy decoding. ## Evaluation Micro-F1 over gold facts on six held-out sets (no note or schema in them was trained on). Real is 150 de-identified MTSamples transcriptions; the other five sets are model-generated. Labels come from model annotators with model adjudication. | Set | Notes | Micro-F1 | Precision | Recall | |---|---|---|---|---| | Synthetic (English, default schema) | 987 | 0.945 | 0.947 | 0.943 | | Hard cases (English) | 250 | 0.939 | 0.942 | 0.936 | | Real transcriptions (English) | 150 | 0.734 | 0.768 | 0.702 | | Custom held-out schemas (English) | 1,000 | 0.950 | 0.948 | 0.952 | | French, held-out schemas | 300 | 0.928 | 0.927 | 0.929 | | Kinyarwanda, held-out schemas | 300 | 0.910 | 0.906 | 0.915 | Every output on these sets was valid JSON. Scores are from greedy decoding of the bf16 weights; the Q8_0 GGUF was not scored separately. ## Training Unsloth 16-bit LoRA on all attention and MLP projections of the language layers, answer-only loss, 8-bit AdamW, cosine schedule, effective batch 32, context 4,096, one NVIDIA GB10 (DGX Spark). Stage 1: one epoch on 30,000 rows, learning rate 1e-4, with half of the generic drug mentions in each note rewritten as brand names. Stage 2: one epoch on 7,980 rows at 5e-5, starting from the merged stage-1 model. Every training note was generated from a seeded specification and kept only if each gold fact had a verbatim quote in the note and every number was reproducible from it; a second model extracted the facts blind and a third adjudicated disagreements. ## Limitations - No clinician has reviewed the training or evaluation labels. - Real-note accuracy (0.734) is far below accuracy on generated notes; the real set has only 150 English notes from one public source, and no real French or Kinyarwanda notes have been scored. - The model can map brand names to the wrong generic drug. - A larger successor (Qwen3.6-35B-A3B fine-tune) scores higher on every set above.