Instructions to use mahmoudalrefaey/clarivis-r1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mahmoudalrefaey/clarivis-r1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="mahmoudalrefaey/clarivis-r1") 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, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("mahmoudalrefaey/clarivis-r1") model = AutoModelForImageTextToText.from_pretrained("mahmoudalrefaey/clarivis-r1") 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
- vLLM
How to use mahmoudalrefaey/clarivis-r1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mahmoudalrefaey/clarivis-r1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mahmoudalrefaey/clarivis-r1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/mahmoudalrefaey/clarivis-r1
- SGLang
How to use mahmoudalrefaey/clarivis-r1 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 "mahmoudalrefaey/clarivis-r1" \ --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": "mahmoudalrefaey/clarivis-r1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "mahmoudalrefaey/clarivis-r1" \ --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": "mahmoudalrefaey/clarivis-r1", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Unsloth Studio
How to use mahmoudalrefaey/clarivis-r1 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 mahmoudalrefaey/clarivis-r1 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 mahmoudalrefaey/clarivis-r1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for mahmoudalrefaey/clarivis-r1 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="mahmoudalrefaey/clarivis-r1", max_seq_length=2048, ) - Docker Model Runner
How to use mahmoudalrefaey/clarivis-r1 with Docker Model Runner:
docker model run hf.co/mahmoudalrefaey/clarivis-r1
📊 Clarivis-R1
Chart Reasoning Vision-Language Model
Structured chain-of-thought reasoning over complex chart images
🧠 Overview
Clarivis-R1 is a vision-language model fine-tuned specifically for complex chart reasoning. Given a chart image and an analytical question, the model produces a fully transparent response with an explicit chain-of-thought trace followed by a concise final answer — structured as:
<think> ... step-by-step reasoning ... </think>
<answer> ... final answer ... </answer>
Built on google/gemma-4-E2B-it and trained on 300,000 chart reasoning samples from IBM Granite's ChartNet dataset, Clarivis-R1 targets use cases where interpretability matters: document intelligence, chart QA, RAG pipelines, and agentic workflows.
📈 Benchmark Results
| Benchmark | Split | Metric | Score |
|---|---|---|---|
| ChartQA | test (2,500 samples) | Relaxed Accuracy ±5% | 51.64% |
Evaluated using greedy decoding (
do_sample=False,max_new_tokens=1024). Relaxed accuracy allows ±5% tolerance for numerical answers — the standard ChartQA evaluation protocol.
💡 Example Output
Chart: Bar chart — Netflix content ratings by type (Movies vs TV Shows)
Question:
"Which rating category has the most balanced distribution between Movies and TV Shows?"
Response:
<think>
The question asks for the rating category where the number of Movies and
TV Shows are most balanced — i.e., where counts are closest to each other.
From the chart:
- TV-MA: Movies ≈ 2050, TV Shows ≈ 1150 → difference ≈ 900
- TV-14: Movies ≈ 1430, TV Shows ≈ 700 → difference ≈ 730
- TV-PG: Movies ≈ 540, TV Shows ≈ 320 → difference ≈ 220
- TV-Y7: Movies ≈ 150, TV Shows ≈ 200 → difference ≈ 50 ✓
- TVY: Movies ≈ 130, TV Shows ≈ 170 → difference ≈ 40
The smallest absolute difference belongs to TVY and TV-Y7.
Considering both absolute difference and visual proximity, TV-Y7
is the most balanced category.
</think>
<answer>
TV-Y7
</answer>
🏋️ Training Details
Base Model
google/gemma-4-E2B-it — 2B parameters, 4-bit quantized via Unsloth
Dataset
| Property | Value |
|---|---|
| Source | ibm-granite/ChartNet (reasoning split) |
| Size | 300,000 samples |
| Format | (chart image, complex question, full reasoning chain) triplets |
| Chart types | Bar, stacked bar, line, bubble, scatter, grouped bar, area, and more |
| Answer format | <think>...</think><answer>...</answer> |
LoRA Configuration
r = 32
lora_alpha = 32
lora_dropout = 0.05
target_modules = "all-linear"
bias = "none"
# All layer types fine-tuned:
finetune_vision_layers = True
finetune_language_layers = True
finetune_attention_modules = True
finetune_mlp_modules = True
Training Configuration
per_device_train_batch_size = 1
gradient_accumulation_steps = 4 # effective batch size = 4
learning_rate = 2e-5
lr_scheduler_type = "cosine"
warmup_ratio = 0.03
num_train_epochs = 1
max_seq_length = 2048
optim = "adamw_torch"
max_grad_norm = 0.5
weight_decay = 0.001
dataloader_num_workers = 0 # required for PIL image safety
Infrastructure
| Property | Value |
|---|---|
| Platform | AWS SageMaker (single GPU) |
| Framework | Unsloth + HuggingFace TRL |
| Total steps | ~72,750 / 75,000 (97% of 1 epoch) |
| Training time | ~5 days |
| Trainable params | 57,360,384 / 5,161,657,888 (1.11%) |
Loss Curve
| Step | Training Loss |
|---|---|
| 100 | 2.39 |
| 5,000 | 0.43 |
| 14,000 | 0.39 |
| 24,000 | 0.376 |
| 44,000 | 0.361 |
| 72,750 | ~0.35 |
🚀 Quick Start
Installation
pip install unsloth transformers torch pillow
Inference
from PIL import Image
from transformers import TextStreamer
# ── Input ────────────────────────────────────────────────────────────────────
from unsloth import FastVisionModel
from PIL import Image
from transformers import TextStreamer
# ── Load model ───────────────────────────────────────────────────────────────
model, processor = FastVisionModel.from_pretrained(
model_name="mahmoudalrefaey/clarivis-r1",
load_in_4bit=True,
)
FastVisionModel.for_inference(model)
# ── Input ────────────────────────────────────────────────────────────────────
image = Image.open("your_chart.png").convert("RGB")
instruction = "Your question here."
messages = [
{
"role": "user",
"content": [{"type": "image"}, {"type": "text", "text": instruction}],
}
]
# ── Tokenize ─────────────────────────────────────────────────────────────────
input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(
image,
input_text,
add_special_tokens=False,
return_tensors="pt",
).to("cuda")
# ── Generate ─────────────────────────────────────────────────────────────────
text_streamer = TextStreamer(processor, skip_prompt=True)
result = model.generate(
**inputs,
streamer=text_streamer,
max_new_tokens=2048,
use_cache=True,
do_sample=False,
)
⚠️ Important: Always use
do_sample=Falsefor chart reasoning tasks. Do not passtemperature=0.0— it raises aValueError. Usedo_sample=Falsefor greedy (deterministic) decoding instead.
✅ Intended Use
| Use Case | Status |
|---|---|
| Chart question answering | ✅ Supported |
| Structured reasoning traces | ✅ Supported |
| RAG pipelines over chart documents | ✅ Supported |
| Document intelligence | ✅ Supported |
| Agentic workflows | ✅ Supported |
| Precise small-value bar reading | ⚠️ May hallucinate |
| Stacked segment decomposition | ⚠️ Limited at 2B scale |
⚠️ Limitations
- Stacked bar decomposition: Precisely isolating individual colored segments in stacked charts is challenging at the 2B parameter scale — total bar heights are read more reliably than individual segments
- Small value precision: Values in the single-digit to ~20 range on crowded axes may be approximated or hallucinated
- Single epoch training: Each sample was seen exactly once during training
- Out-of-domain charts: Performance may degrade on chart styles not well-represented in ChartNet (e.g. Sankey diagrams, radar charts)
📄 Citation
If you use Clarivis-R1 in your research or build on it, please cite:
@misc{clarivis-r1-2025,
author = {Mahmoud Alrefaey},
title = {Clarivis-R1: Chart Reasoning Vision-Language Model},
year = {2025},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/mahmoudalrefaey/clarivis-r1}},
}
📜 License
This model is built on Gemma 4 and is subject to the Gemma Terms of Use. Please review the license terms before any commercial use.
🙏 Acknowledgements
| 📦 Dataset | IBM Granite — ChartNet |
| ⚡ Training | Unsloth — 2x faster fine-tuning |
| 🤗 Framework | HuggingFace TRL — SFTTrainer |
| 🧱 Base Model | Google Gemma 4 |
- Downloads last month
- 67