Instructions to use ml-intern-explorers/gemma-4-e2b-arabic-english-vision with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ml-intern-explorers/gemma-4-e2b-arabic-english-vision with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ml-intern-explorers/gemma-4-e2b-arabic-english-vision") 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("ml-intern-explorers/gemma-4-e2b-arabic-english-vision") model = AutoModelForImageTextToText.from_pretrained("ml-intern-explorers/gemma-4-e2b-arabic-english-vision") 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
- vLLM
How to use ml-intern-explorers/gemma-4-e2b-arabic-english-vision with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ml-intern-explorers/gemma-4-e2b-arabic-english-vision" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ml-intern-explorers/gemma-4-e2b-arabic-english-vision", "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/ml-intern-explorers/gemma-4-e2b-arabic-english-vision
- SGLang
How to use ml-intern-explorers/gemma-4-e2b-arabic-english-vision 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 "ml-intern-explorers/gemma-4-e2b-arabic-english-vision" \ --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": "ml-intern-explorers/gemma-4-e2b-arabic-english-vision", "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 "ml-intern-explorers/gemma-4-e2b-arabic-english-vision" \ --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": "ml-intern-explorers/gemma-4-e2b-arabic-english-vision", "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" } } ] } ] }' - Docker Model Runner
How to use ml-intern-explorers/gemma-4-e2b-arabic-english-vision with Docker Model Runner:
docker model run hf.co/ml-intern-explorers/gemma-4-e2b-arabic-english-vision
Gemma 4 E2B — Arabic + English Vision (Pruned)
A pruned version of google/gemma-4-e2b-it optimized for Arabic and English vision-language tasks. Unnecessary language tokens and the audio encoder have been removed, resulting in a smaller and more efficient model while retaining full vision and text generation capabilities.
What was done
| Component | Original | Pruned |
|---|---|---|
| Vocabulary | 262,144 tokens | 209,836 tokens (Arabic + English + special) |
| Vision encoder | ✅ 16 layers | ✅ KEPT |
| Audio encoder | ✅ 12 layers | ❌ Removed |
| Decoder layers | 35 layers | 35 layers (untouched) |
| PLE tables | 262,144 × 256 × 35 | 209,836 × 256 × 35 |
| Total size (bf16) | 10.2 GB | 8.5 GB |
| Size reduction | — | 17% |
Token breakdown
- Arabic tokens kept: 8,460
- English/Latin tokens kept: 201,096
- Special tokens: 24
- Byte fallbacks: 256
- Total kept: 209,836 (80.0% of original)
- Dropped: 52,308 (CJK, Cyrillic, Devanagari, Thai, etc.)
Why this exists
Gemma 4's Per-Layer Embedding (PLE) architecture stores a separate embedding table for each of its 35 decoder layers. With 262K vocab, that's 4.7 GB of PLE tables alone (53% of the model). By pruning to Arabic+English only, we cut this to ~3.8 GB.
The vision encoder is kept intact for image understanding tasks.
Benchmark: Arabic text recognition (zero-shot, no fine-tuning)
Evaluated on loay/ar_stage1_probe — 100 samples, seed=42:
| Model | Params | VRAM | CER ↓ | Exact Match |
|---|---|---|---|---|
| This model (pruned) | 4.25B | 8.5 GB | 0.1168 | 23/100 |
| google/gemma-4-e2b-it (original) | 5.10B | 10.2 GB | 0.1168 | 23/100 |
Identical output on all 100 samples — pruning is lossless for Arabic+English tasks.
Intended use
- Arabic + English vision-language tasks
- Document understanding
- Fine-tuning base for bilingual Arabic/English applications
- Any task where CJK/Cyrillic/Indic language support is not needed
Usage
from transformers import AutoModelForImageTextToText, AutoProcessor
model = AutoModelForImageTextToText.from_pretrained(
"ml-agent-explorers/gemma-4-e2b-arabic-english-vision",
dtype="bfloat16",
device_map="auto",
)
processor = AutoProcessor.from_pretrained(
"ml-agent-explorers/gemma-4-e2b-arabic-english-vision"
)
Base model
- Downloads last month
- 113