Run this model with HF Jobs
Run Alfaxad/gemma2-2b-swahili-it on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/Alfaxad/gemma2-2b-swahili-it. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Alfaxad/gemma2-2b-swahili-it on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/Alfaxad/gemma2-2b-swahili-it. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/Alfaxad/gemma2-2b-swahili-it. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use Alfaxad/gemma2-2b-swahili-it with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Alfaxad/gemma2-2b-swahili-it with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Alfaxad/gemma2-2b-swahili-it") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Alfaxad/gemma2-2b-swahili-it") model = AutoModelForCausalLM.from_pretrained("Alfaxad/gemma2-2b-swahili-it", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Alfaxad/gemma2-2b-swahili-it with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Alfaxad/gemma2-2b-swahili-it" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Alfaxad/gemma2-2b-swahili-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Alfaxad/gemma2-2b-swahili-it
- SGLang
How to use Alfaxad/gemma2-2b-swahili-it 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 "Alfaxad/gemma2-2b-swahili-it" \ --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": "Alfaxad/gemma2-2b-swahili-it", "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 "Alfaxad/gemma2-2b-swahili-it" \ --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": "Alfaxad/gemma2-2b-swahili-it", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Alfaxad/gemma2-2b-swahili-it with Docker Model Runner:
docker model run hf.co/Alfaxad/gemma2-2b-swahili-it
Gemma2-2B-Swahili-IT
Gemma2-2B-Swahili-IT is a lightweight, efficient open variant of Google's Gemma2-2B-IT model, fine-tuned for natural Swahili language understanding and generation. This model provides a resource-efficient option for Swahili language tasks while maintaining strong performance.
Model Details
- Developer: Alfaxad Eyembe
- Base Model: google/gemma-2-2b-it
- Model Type: Decoder-only transformer
- Language(s): Swahili
- License: Apache 2.0
- Finetuning Approach: Low-Rank Adaptation (LoRA)
Training Data
The model was fine-tuned on a comprehensive dataset containing:
- 67,017 instruction-response pairs
- 16,273,709 total tokens
- Average 242.83 tokens per example
- High-quality, naturally-written Swahili content
Performance
Massive Multitask Language Understanding (MMLU) - Swahili
- Base Model: 31.58% accuracy
- Fine-tuned Model: 38.60% accuracy
- Improvement: +7.02%
Sentiment Analysis
- Base Model: 84.85% accuracy
- Fine-tuned Model: 86.00% accuracy
- Improvement: +1.15%
- Response Validity: 100%
Intended Use
This model is designed for:
- Basic Swahili text generation
- Question answering
- Sentiment analysis
- Simple creative writing
- General instruction following in Swahili
- Resource-constrained environments
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("alfaxadeyembe/gemma2-2b-swahili-it")
model = AutoModelForCausalLM.from_pretrained(
"alfaxadeyembe/gemma2-2b-swahili-it",
device_map="auto",
torch_dtype=torch.bfloat16
)
# Always set to eval mode for inference
model.eval()
# Example usage
prompt = "Eleza dhana ya uchumi wa kidijitali na umuhimu wake katika ulimwengu wa leo."
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=500,
do_sample=True,
temperature=0.7,
top_p=0.95
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
Training Details
- Fine-tuning Method: LoRA
- Training Steps: 400
- Batch Size: 2
- Gradient Accumulation Steps: 32
- Learning Rate: 2e-4
- Training Time: ~8 hours on A100 GPU
Key Features
- Lightweight and efficient (2B parameters)
- Suitable for resource-constrained environments
- Good performance on basic language tasks
- Fast inference speed
- Low memory footprint
Advantages
Resource Efficiency:
- Small model size (2B parameters)
- Lower memory requirements
- Faster inference time
- Suitable for deployment on less powerful hardware
Task Performance:
- Strong sentiment analysis capabilities
- Decent MMLU performance
- Good instruction following
- Natural Swahili generation
Limitations
- Simpler responses compared to 9B/27B variants
Citation
@misc{gemma2-2b-swahili-it,
author = {Alfaxad Eyembe},
title = {Gemma2-2B-Swahili-IT: A Lightweight Swahili Variant of Gemma2-2B-IT},
year = {2025},
publisher = {Hugging Face},
journal = {Hugging Face Model Hub},
}
Contact
For questions or feedback, please reach out through:
- HuggingFace: @alfaxadeyembe
- Twitter: @alfxad
- Downloads last month
- 27
