Text Generation
Transformers
Safetensors
GGUF
English
gemma4
image-text-to-text
healthcare
clinical-decision-support
ncd
diabetes
hypertension
medical
unsloth
lora
conversational
Instructions to use samwell/ncd-gemma4-e4b-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use samwell/ncd-gemma4-e4b-lora with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="samwell/ncd-gemma4-e4b-lora") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("samwell/ncd-gemma4-e4b-lora") model = AutoModelForMultimodalLM.from_pretrained("samwell/ncd-gemma4-e4b-lora", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use samwell/ncd-gemma4-e4b-lora with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M # Run inference directly in the terminal: llama cli -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M # Run inference directly in the terminal: llama cli -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Use Docker
docker model run hf.co/samwell/ncd-gemma4-e4b-lora:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use samwell/ncd-gemma4-e4b-lora with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "samwell/ncd-gemma4-e4b-lora" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "samwell/ncd-gemma4-e4b-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/samwell/ncd-gemma4-e4b-lora:Q4_K_M
- SGLang
How to use samwell/ncd-gemma4-e4b-lora 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 "samwell/ncd-gemma4-e4b-lora" \ --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": "samwell/ncd-gemma4-e4b-lora", "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 "samwell/ncd-gemma4-e4b-lora" \ --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": "samwell/ncd-gemma4-e4b-lora", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use samwell/ncd-gemma4-e4b-lora with Ollama:
ollama run hf.co/samwell/ncd-gemma4-e4b-lora:Q4_K_M
- Unsloth Studio
How to use samwell/ncd-gemma4-e4b-lora with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for samwell/ncd-gemma4-e4b-lora to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for samwell/ncd-gemma4-e4b-lora to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for samwell/ncd-gemma4-e4b-lora to start chatting
- Pi
How to use samwell/ncd-gemma4-e4b-lora with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "samwell/ncd-gemma4-e4b-lora:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use samwell/ncd-gemma4-e4b-lora with Docker Model Runner:
docker model run hf.co/samwell/ncd-gemma4-e4b-lora:Q4_K_M
- Lemonade
How to use samwell/ncd-gemma4-e4b-lora with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull samwell/ncd-gemma4-e4b-lora:Q4_K_M
Run and chat with the model
lemonade run user.ncd-gemma4-e4b-lora-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use samwell/ncd-gemma4-e4b-lora with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default samwell/ncd-gemma4-e4b-lora:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use samwell/ncd-gemma4-e4b-lora with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf samwell/ncd-gemma4-e4b-lora:Q4_K_M
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "samwell/ncd-gemma4-e4b-lora:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,22 +1,209 @@
|
|
| 1 |
---
|
|
|
|
| 2 |
base_model: google/gemma-4-E4B-it
|
| 3 |
tags:
|
| 4 |
-
-
|
| 5 |
-
-
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
language:
|
| 11 |
-
- en
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
- **
|
| 17 |
-
- **License:** apache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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: gemma
|
| 3 |
base_model: google/gemma-4-E4B-it
|
| 4 |
tags:
|
| 5 |
+
- healthcare
|
| 6 |
+
- clinical-decision-support
|
| 7 |
+
- ncd
|
| 8 |
+
- diabetes
|
| 9 |
+
- hypertension
|
| 10 |
+
- medical
|
| 11 |
+
- unsloth
|
| 12 |
+
- lora
|
| 13 |
+
- gguf
|
| 14 |
+
datasets:
|
| 15 |
+
- samwell/synthea-ncd-instructions
|
| 16 |
language:
|
| 17 |
+
- en
|
| 18 |
+
pipeline_tag: text-generation
|
| 19 |
+
library_name: transformers
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# NCD Risk Assessment Model (Gemma 4 E4B Fine-tuned)
|
| 23 |
|
| 24 |
+
A fine-tuned Gemma 4 E4B model for predicting **Non-Communicable Disease (NCD) risk** - specifically Type 2 Diabetes and Hypertension - from patient clinical data.
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
## Model Description
|
| 27 |
|
| 28 |
+
This model was fine-tuned on 49,214 synthetic patient records to provide clinical decision support for NCD screening in resource-limited settings, particularly designed for deployment in Ghana and similar healthcare contexts.
|
| 29 |
+
|
| 30 |
+
| Attribute | Value |
|
| 31 |
+
|-----------|-------|
|
| 32 |
+
| Base Model | `google/gemma-4-E4B-it` |
|
| 33 |
+
| Fine-tuning Method | QLoRA (4-bit) with Unsloth |
|
| 34 |
+
| LoRA Rank | 32 |
|
| 35 |
+
| Training Data | 39,371 examples |
|
| 36 |
+
| Final Loss | 0.1842 |
|
| 37 |
+
| Training Time | 100 minutes (H200 GPU) |
|
| 38 |
+
|
| 39 |
+
## Intended Use
|
| 40 |
+
|
| 41 |
+
**Primary Use Case:** Clinical Decision Support (CDS) for NCD risk screening
|
| 42 |
+
|
| 43 |
+
**Target Users:**
|
| 44 |
+
- Healthcare workers in primary care settings
|
| 45 |
+
- Community health workers conducting NCD screenings
|
| 46 |
+
- EHR systems (e.g., OpenMRS/HopeOS) for automated risk assessment
|
| 47 |
+
|
| 48 |
+
**Input:** Patient demographics, vitals, and lab values
|
| 49 |
+
**Output:** Structured risk assessment with clinical reasoning
|
| 50 |
+
|
| 51 |
+
## Model Files
|
| 52 |
+
|
| 53 |
+
| File | Format | Size | Use Case |
|
| 54 |
+
|------|--------|------|----------|
|
| 55 |
+
| `adapter_model.safetensors` | LoRA | ~340MB | Fine-tuning, merging |
|
| 56 |
+
| `ncd-gemma4-q4_k_m.gguf` | GGUF | ~2.5GB | Local inference (llama.cpp, Ollama) |
|
| 57 |
+
|
| 58 |
+
## How to Use
|
| 59 |
+
|
| 60 |
+
### With Transformers + PEFT (LoRA)
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 64 |
+
from peft import PeftModel
|
| 65 |
+
|
| 66 |
+
# Load base model
|
| 67 |
+
base_model = AutoModelForCausalLM.from_pretrained("google/gemma-4-E4B-it")
|
| 68 |
+
tokenizer = AutoTokenizer.from_pretrained("google/gemma-4-E4B-it")
|
| 69 |
+
|
| 70 |
+
# Load LoRA adapter
|
| 71 |
+
model = PeftModel.from_pretrained(base_model, "samwell/ncd-gemma4-e4b-lora")
|
| 72 |
+
|
| 73 |
+
# Inference
|
| 74 |
+
prompt = """Based on the following patient record, assess the risk of Type 2 diabetes and hypertension.
|
| 75 |
+
|
| 76 |
+
Patient: 55yo Male
|
| 77 |
+
Vitals: BP 152/94 mmHg, BMI 31.2
|
| 78 |
+
Labs: Glucose 126 mg/dL, HbA1c 6.4%
|
| 79 |
+
Active conditions: Prediabetes"""
|
| 80 |
+
|
| 81 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
| 82 |
+
outputs = model.generate(**inputs, max_new_tokens=512)
|
| 83 |
+
print(tokenizer.decode(outputs[0]))
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### With llama.cpp (GGUF)
|
| 87 |
+
|
| 88 |
+
```bash
|
| 89 |
+
# Download GGUF
|
| 90 |
+
huggingface-cli download samwell/ncd-gemma4-e4b-lora ncd-gemma4-q4_k_m.gguf
|
| 91 |
+
|
| 92 |
+
# Run inference
|
| 93 |
+
./llama-cli -m ncd-gemma4-q4_k_m.gguf -p "Patient: 45yo Female, BP 140/90..."
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
### With Ollama
|
| 97 |
+
|
| 98 |
+
```bash
|
| 99 |
+
# Create model
|
| 100 |
+
echo 'FROM ./ncd-gemma4-q4_k_m.gguf' > Modelfile
|
| 101 |
+
ollama create ncd-cds -f Modelfile
|
| 102 |
+
|
| 103 |
+
# Run
|
| 104 |
+
ollama run ncd-cds "Patient: 45yo Female, BP 140/90..."
|
| 105 |
+
```
|
| 106 |
+
|
| 107 |
+
## Example Output
|
| 108 |
+
|
| 109 |
+
**Input:**
|
| 110 |
+
```
|
| 111 |
+
Patient: 55yo Male
|
| 112 |
+
Vitals: BP 152/94 mmHg, BMI 31.2
|
| 113 |
+
Labs: Glucose 126 mg/dL, HbA1c 6.4%
|
| 114 |
+
Active conditions: Prediabetes
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
**Output:**
|
| 118 |
+
```
|
| 119 |
+
## Risk Assessment
|
| 120 |
+
|
| 121 |
+
**Type 2 Diabetes: MODERATE**
|
| 122 |
+
- HbA1c 6.4% (prediabetes range 5.7-6.4%)
|
| 123 |
+
- BMI 31.2 (obese)
|
| 124 |
+
- Age 55 years (≥45 increases risk)
|
| 125 |
+
|
| 126 |
+
**Hypertension: HIGH**
|
| 127 |
+
- BP 152/94 mmHg (Stage 2 Hypertension)
|
| 128 |
+
- Systolic ≥140 or Diastolic ≥90 confirms diagnosis
|
| 129 |
+
|
| 130 |
+
## Recommendations
|
| 131 |
+
|
| 132 |
+
1. **Lifestyle modifications**: Weight loss, DASH diet, sodium reduction
|
| 133 |
+
2. **Blood pressure monitoring**: Home BP monitoring recommended
|
| 134 |
+
3. **Lab follow-up**: Repeat HbA1c in 3 months
|
| 135 |
+
4. **Consider referral**: If BP remains elevated, initiate antihypertensive therapy
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## Training Details
|
| 139 |
+
|
| 140 |
+
### Dataset
|
| 141 |
+
|
| 142 |
+
- **Source:** Synthea synthetic patient generator
|
| 143 |
+
- **Size:** 49,214 examples (39,371 train / 4,921 val / 4,922 test)
|
| 144 |
+
- **Format:** Instruction-tuning (instruction/input/output)
|
| 145 |
+
- **Dataset:** [`samwell/synthea-ncd-instructions`](https://huggingface.co/datasets/samwell/synthea-ncd-instructions)
|
| 146 |
+
|
| 147 |
+
### Training Configuration
|
| 148 |
+
|
| 149 |
+
```python
|
| 150 |
+
# Model
|
| 151 |
+
MODEL_NAME = "google/gemma-4-E4B-it"
|
| 152 |
+
MAX_SEQ_LENGTH = 2048
|
| 153 |
+
LOAD_IN_4BIT = True # QLoRA
|
| 154 |
+
|
| 155 |
+
# LoRA
|
| 156 |
+
LORA_R = 32
|
| 157 |
+
LORA_ALPHA = 32
|
| 158 |
+
TARGET_MODULES = ["q_proj", "k_proj", "v_proj", "o_proj",
|
| 159 |
+
"gate_proj", "up_proj", "down_proj"]
|
| 160 |
+
|
| 161 |
+
# Training
|
| 162 |
+
BATCH_SIZE = 8
|
| 163 |
+
GRADIENT_ACCUMULATION = 2 # Effective batch = 16
|
| 164 |
+
LEARNING_RATE = 2e-4
|
| 165 |
+
NUM_EPOCHS = 3
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
### Training Curve
|
| 169 |
+
|
| 170 |
+
- Initial loss: 1.71
|
| 171 |
+
- Final loss: 0.1842
|
| 172 |
+
- Training time: 100 minutes on NVIDIA H200 (80GB)
|
| 173 |
+
|
| 174 |
+
## Limitations
|
| 175 |
+
|
| 176 |
+
1. **Synthetic data only:** Trained on Synthea-generated data, not real patient records
|
| 177 |
+
2. **US demographics:** Synthea defaults to US population demographics
|
| 178 |
+
3. **Limited NCDs:** Currently only assesses diabetes and hypertension
|
| 179 |
+
4. **Not a diagnostic tool:** Intended for screening support, not clinical diagnosis
|
| 180 |
+
5. **Requires clinical validation:** Must be validated by healthcare professionals before clinical use
|
| 181 |
+
|
| 182 |
+
## Ethical Considerations
|
| 183 |
+
|
| 184 |
+
- **Not FDA/CE approved** for clinical diagnosis
|
| 185 |
+
- Should be used as **decision support**, not replacement for clinical judgment
|
| 186 |
+
- Predictions should be **reviewed by qualified healthcare providers**
|
| 187 |
+
- Model may reflect biases in training data
|
| 188 |
+
|
| 189 |
+
## Citation
|
| 190 |
+
|
| 191 |
+
```bibtex
|
| 192 |
+
@misc{ncd-gemma4-2026,
|
| 193 |
+
author = {HopeOS Team},
|
| 194 |
+
title = {NCD Risk Assessment Model: Fine-tuned Gemma 4 for Diabetes and Hypertension Prediction},
|
| 195 |
+
year = {2026},
|
| 196 |
+
publisher = {HuggingFace},
|
| 197 |
+
url = {https://huggingface.co/samwell/ncd-gemma4-e4b-lora}
|
| 198 |
+
}
|
| 199 |
+
```
|
| 200 |
+
|
| 201 |
+
## Related Resources
|
| 202 |
+
|
| 203 |
+
- **Dataset:** [samwell/synthea-ncd-instructions](https://huggingface.co/datasets/samwell/synthea-ncd-instructions)
|
| 204 |
+
- **Base Model:** [google/gemma-4-E4B-it](https://huggingface.co/google/gemma-4-E4B-it)
|
| 205 |
+
- **Training Library:** [Unsloth](https://github.com/unslothai/unsloth)
|
| 206 |
+
|
| 207 |
+
## License
|
| 208 |
+
|
| 209 |
+
This model is released under the [Gemma license](https://ai.google.dev/gemma/terms).
|