Downloads · 30 days
5
21% of all-time downloads
shaikhsalman/zabaanai-pakistan-multilingual
zabaanai-pakistan-multilingual is a machine learning model from shaikhsalman. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
An open-source, CPU-friendly AI model for Pakistan's major languages
Downloads · 30 days
5
21% of all-time downloads
All-time downloads
24
Public
Repo size
—
Likes
1
Public
Click a slice to open those files.
.py85.1 KB · 63%
From the Hugging Face model README
An open-source, CPU-friendly AI model for Pakistan's major languages
| Language | Script | Coverage |
|---|---|---|
| Urdu | Arabic (Nastaliq) | ✅ News, poetry, social media |
| Punjabi (Shahmukhi) | Arabic | ✅ News, literature, transliteration |
| Sindhi | Arabic | ✅ Large corpus (505M tokens) |
| Saraiki | Arabic | ⚠️ Augmented from related languages |
| Balochi | Arabic | ✅ Small curated datasets |
| Pashto | Arabic | ✅ ZamAI corpus, textbooks, news |
| Hindko | Arabic | ⚠️ Augmented from related languages |
| Brahui | Arabic | ⚠️ Bridged from Balochi |
| Kashmiri | Arabic | ✅ Dedicated corpora + news |
| English | Latin | ✅ Wikipedia + parallel corpora |
| Roman Urdu | Latin | ✅ Social media, code-mixed |
google/mt5-smallWe chose mT5-small over XLM-R and mBERT because it's the only architecture that natively supports all required tasks:
| Requirement | mT5-small ✅ | XLM-R ❌ | mBERT ❌ |
|---|---|---|---|
| Text Generation | ✅ Native seq2seq | Encoder-only | Encoder-only |
| Translation | ✅ Native | Can't generate | Can't generate |
| Summarization | ✅ Native | Can't generate | Can't generate |
| Chatbot/QA | ✅ Native | Can't generate | Can't generate |
| Sentiment | ✅ Text-to-text | Native | Native |
| CPU Efficiency | ✅ 47% lower latency* | Good | Good |
*Encoder-decoder achieves 47% lower first-token latency and 4.7x higher throughput on CPU vs decoder-only (Microsoft 2025).
All tasks use mT5's unified text-to-text format:
| Task | Input Format | Example Output |
|---|---|---|
| Text Generation | generate in Urdu: {prompt} | "پاکستان ایک خوبصورت ملک ہے..." |
| Translation | translate English to Urdu: {text} | "پاکستان ایک خوبصورت ملک ہے" |
| Summarization | summarize: {long_text} | "Short summary..." |
| Sentiment | sentiment: {text} | "positive" / "negative" / "neutral" |
| QA | question: {Q} context: {C} | "Answer text..." |
| Chatbot | conversation: user: {msg} assistant: | "Response text..." |
├── scripts/
│ ├── 01_collect_datasets.py # Download 35+ HF datasets
│ ├── 02_clean_text.py # Clean, deduplicate, normalize
│ ├── 03_train_tokenizer.py # Extend mT5 tokenizer
│ ├── 04_prepare_training_data.py # T5 span corruption prep
│ ├── 05_train_cpu.py # CPU-optimized LoRA pretraining
│ ├── 06_finetune_lora.py # LoRA fine-tuning (5 tasks)
│ ├── 07_evaluate.py # BLEU, ROUGE, perplexity
│ ├── 08_quantize.py # ONNX INT8 / 8-bit quantization
│ └── 09_deploy_space.py # HF Space deployment
├── docs/
│ ├── 01_DATASET_COLLECTION.md # Full dataset sourcing guide
│ ├── 02_TOKENIZER_GUIDE.md # Tokenizer improvement strategy
│ ├── 03_TRAINING_GUIDE.md # CPU training configuration
│ ├── 04_FINETUNING_GUIDE.md # LoRA fine-tuning recipes
│ └── 05_DEPLOYMENT_GUIDE.md # 5 deployment options
├── deployment/
│ ├── app.py # Gradio web app (6 tasks)
│ ├── api_server.py # FastAPI REST API
│ ├── Dockerfile # Docker container
│ └── requirements.txt # All dependencies
├── notebooks/
│ └── 01_explore_datasets.ipynb # Dataset visualization
├── tokenizer/ # Extended tokenizer (250,141 vocab)
├── config.yaml # Central configuration
├── setup.py # Environment setup
├── QUICKSTART.md # 10-step quick start
└── README.md # This file
pip install transformers datasets tokenizers accelerate peft sentencepiece
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install protobuf tiktoken gradio optimum[onnxruntime]
python scripts/01_collect_datasets.py
python scripts/02_clean_text.py
python scripts/03_train_tokenizer.py
python scripts/04_prepare_training_data.py
python scripts/05_train_cpu.py --max_steps 50000 --batch_size 2 --lora_r 64
python scripts/06_finetune_lora.py --task translation --batch_size 8
python scripts/06_finetune_lora.py --task sentiment --batch_size 8
python scripts/09_deploy_space.py --username your-username --space_name zabaanai-demo
| Setting | Value | Why |
|---|---|---|
| Base Model | google/mt5-small | 300M params, 250k vocab, seq2seq |
| LoRA Rank | 64 | ~15% of params trainable (~45M) |
| Batch Size | 2 | Low for CPU RAM |
| Gradient Accumulation | 32 | Effective batch = 64 |
| Learning Rate | 2e-4 | Higher LR works with LoRA |
| Max Steps | 50,000 | Minimum for meaningful adaptation |
| Warmup | 500 steps | 1% of total |
| Scheduler | Cosine | Smooth decay |
| Checkpointing | Every 2,000 steps | Auto-resume supported |
| Precision | FP32 | CPU-safe (no fp16/bf16) |
| Gradient Checkpointing | Enabled | 40-50% memory savings |
Training time: ~70 hours for 50K steps on 8-core CPU, or ~3 hours on T4 GPU.
python scripts/06_finetune_lora.py --task translation
# Datasets: Humair332/Vast-Urdu (10M pairs), Kashmiri-English, Pashto-English
python scripts/06_finetune_lora.py --task sentiment
# Datasets: community-datasets/roman_urdu, urdu_sentiment_corpus
python scripts/06_finetune_lora.py --task summarization
# Datasets: News articles with headlines as pseudo-summaries
python scripts/06_finetune_lora.py --task qa
# Datasets: Sindhi encyclopedia, generated Q&A pairs
python scripts/06_finetune_lora.py --task chatbot
# Datasets: Urdu-Instruct, Sindhi SFT, Pashto Alpaca
| Option | Best For | Setup | Cost |
|---|---|---|---|
| Hugging Face Spaces | Public demo | 2 minutes | Free / Paid GPU |
| Local CPU Server | Privacy, on-premise | 10 minutes | Free |
| Docker Container | Scalable cloud | 15 minutes | Varies |
| FastAPI API | Production microservices | 10 minutes | Varies |
| ONNX Quantized | Edge/embedded | 5 minutes | Free |
Urdu: 35% (news, poetry, social media, Wikipedia)
Sindhi: 20% (large corpus available)
Pashto: 15% (ZamAI corpora)
Punjabi: 10% (news, transliteration)
Roman Urdu: 8% (social media, tweets)
English: 7% (prevent catastrophic forgetting)
Kashmiri: 3% (smaller corpus)
Balochi: 1.5% (very limited data)
Saraiki/Hindko/Brahui: 0.5% (augmented from related)
mT5's native tokenizer already covers all Pakistan scripts with 250,000 tokens + byte fallback. We extended it with 52 Pakistan-specific tokens:
لاہور, کراچی, اسلام آباد, پشاور, کوئٹہمحمد, علی, فاطمہسپریم کورٹ, نیشنل اسمبلیbhai, yaar, theekVocabulary size: 250,141 (was 250,100)
python scripts/07_evaluate.py --model_path training/checkpoints/final --task translation
# Metrics: BLEU (translation), ROUGE (summarization), Perplexity (generation)
# ONNX INT8 (recommended for CPU)
python scripts/08_quantize.py --model_path training/checkpoints/final --method onnx
# 8-bit (for GPU)
python scripts/08_quantize.py --model_path training/checkpoints/final --method 8bit
Benefits: 60-70% smaller model, 2-3x faster inference on CPU.
We welcome contributions! Priority areas:
Apache 2.0 (same as mT5 base model)
@software{zabaanai2025,
title = {ZabaanAI: Pakistan Multilingual Language Model},
author = {Open Source Contributors},
year = {2025},
url = {https://huggingface.co/shaikhsalman/zabaanai-pakistan-multilingual}
}
Built with ❤️ for Pakistan's languages 🇵🇰