Downloads · 30 days
0
dicksonsarpong9/twi-qwen2.5-0.5b-instruct
twi-qwen2.5-0.5b-instruct is a text generation model from dicksonsarpong9. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
A Qwen2.5-0.5B-Instruct model fine-tuned on over 1.2 million Twi text examples for instruction-following and text generation in Twi (Akan), a language spoken by over 11 million people in Ghana.
Downloads · 30 days
0
Access
Public
Updated Apr 22, 2026
Repo size
—
Likes
0
Public
Click a slice to open those files.
.py13.1 KB · 56%
From the Hugging Face model README
twi-qwen2.5-0.5b-instructA Qwen2.5-0.5B-Instruct model fine-tuned on over 1.2 million Twi text examples for instruction-following and text generation in Twi (Akan), a language spoken by over 11 million people in Ghana.
Twi (also known as Akan Twi or Asante Twi) is one of the most widely spoken languages in Ghana, yet it remains severely underrepresented in modern NLP. Most large language models have little to no understanding of Twi, making them unreliable for Ghanaian users who want to interact in their native language.
This project aims to change that by fine-tuning a capable small language model specifically on Twi data, creating a foundation for Twi-language AI applications.
We selected Qwen/Qwen2.5-0.5B-Instruct as our base model for several reasons:
We combined two high-quality Twi datasets from the Ghana NLP Community:
| Dataset | Size | Description |
|---|---|---|
| pristine-twi-english | ~999,497 examples | Diverse Twi text spanning narratives, dialogues, monologues, and stories covering Ghanaian culture, politics, sports, and daily life |
| twi-english-paragraph-dataset_news | ~256,797 examples | Twi news paragraphs covering current events, politics, sports, entertainment, and social issues in Ghana |
Combined total: ~1,255,641 examples (1,192,858 train / 62,783 eval after a 95/5 split)
Each example was converted into a conversational format compatible with SFT training:
{
"messages": [
{"role": "user", "content": "Kyerɛ biribi fa Twi kasa ho."},
{"role": "assistant", "content": "<twi text from dataset>"}
]
}
We filtered out examples shorter than 20 characters to ensure quality.
We used TRL's SFTTrainer (Supervised Fine-Tuning) with the following configuration:
| Hyperparameter | Value |
|---|---|
| Method | Full SFT (Supervised Fine-Tuning) |
| Epochs | 3 |
| Batch size | 4 per device |
| Gradient accumulation | 4 steps (effective batch = 16) |
| Max sequence length | 1024 tokens |
| Learning rate | 2e-5 |
| LR scheduler | Cosine |
| Warmup steps | 500 |
| Weight decay | 0.01 |
| Precision | bf16 |
| Gradient checkpointing | Enabled |
| Hardware | NVIDIA A10G (24GB VRAM) |
| Training time | ~6-8 hours |
Dataset Diversity: By combining narrative, dialogue, monologue, storyful, and news text, the model learns diverse Twi language patterns — from formal news reporting to casual conversation.
Memory Optimization: Gradient checkpointing and bf16 precision allowed us to train the full model (not LoRA) on a single A10G GPU while maintaining a reasonable batch size.
Evaluation: We held out 5% of the data for validation, with eval runs every 200 steps and checkpointing every 400 steps. The best checkpoint (lowest eval loss) is automatically selected.
from transformers import pipeline
pipe = pipeline(
"text-generation",
model="dicksonsarpong9/twi-qwen2.5-0.5b-instruct",
device_map="auto"
)
messages = [{"role": "user", "content": "Kyerɛ me Ghana ho asɛm."}]
response = pipe(messages, max_new_tokens=512, temperature=0.7, do_sample=True)
print(response[0]["generated_text"][-1]["content"])
from transformers import AutoTokenizer, AutoModelForCausalLM
model_id = "dicksonsarpong9/twi-qwen2.5-0.5b-instruct"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True, device_map="auto")
# Format as conversation
messages = [{"role": "user", "content": "Ka biribi fa aduane a Ghanafoɔ di ho."}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True,
top_p=0.9,
repetition_penalty=1.1,
)
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:], skip_special_tokens=True)
print(response)
Save the inference script and run:
# Install dependencies
pip install transformers torch accelerate
# Run examples
python inference_twi.py
# Single prompt
python inference_twi.py --prompt "Ɛdeɛn nti na adesua ho hia?"
# Interactive mode
python inference_twi.py --interactive
| Twi Prompt | English Translation |
|---|---|
Kyerɛ me Ghana ho asɛm. | Tell me about Ghana. |
Ɛdeɛn ne Twi kasa no mu nsɛm a ɛhia? | What are important things in the Twi language? |
Ka biribi fa aduane a Ghanafoɔ di ho. | Say something about Ghanaian food. |
Kyerɛ me ɔkwan a yɛbɛfa so asua Twi kasa. | Show me how to learn Twi. |
Ɛdeɛn nti na adesua ho hia? | Why is education important? |
This model was made possible by the incredible work of the Ghana NLP Community, who have been building open-source NLP resources for Ghanaian languages. Their datasets represent a significant effort in documenting and digitizing Twi text across multiple domains.
| Component | Tool |
|---|---|
| Base model | Qwen/Qwen2.5-0.5B-Instruct |
| Training library | TRL (SFTTrainer) |
| Experiment tracking | Trackio |
| Infrastructure | Hugging Face Jobs (A10G GPU) |
| Dataset library | 🤗 Datasets |
This model is released under the Apache 2.0 license, following the base Qwen2.5 model license.
If you use this model, please cite:
@misc{twi-qwen2.5-0.5b-instruct,
author = {Dickson Sarpong},
title = {Twi Fine-Tuned Qwen2.5-0.5B-Instruct},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/dicksonsarpong9/twi-qwen2.5-0.5b-instruct}
}
Yɛn kasa yɛ kɛseɛ. Our language is great. 🇬🇭