shaikhsalman/zabaanai-pakistan-multilingual
12
šµš° ZabaanAI - Pakistan Multilingual Language Model
An open-source, CPU-friendly AI model for Pakistan's major languages
š Supported Languages
šļø Base Model: google/mt5-small
We chose mT5-small over XLM-R and mBERT because it's the only architecture that natively supports all required tasks:
*Encoder-decoder achieves 47% lower first-token latency and 4.7x higher throughput on CPU vs decoder-only (Microsoft 2025).
šÆ Supported Tasks
All tasks use mT5's unified text-to-text format:
š Repository Structure
āāā 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ā” Quick Start
1. Install Dependencies
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]2. Collect Datasets
python scripts/01_collect_datasets.py3. Clean & Merge
python scripts/02_clean_text.py4. Extend Tokenizer
python scripts/03_train_tokenizer.py5. Prepare Training Data
python scripts/04_prepare_training_data.py6. Start CPU Training
python scripts/05_train_cpu.py --max_steps 50000 --batch_size 2 --lora_r 647. Fine-Tune for Tasks (GPU recommended)
python scripts/06_finetune_lora.py --task translation --batch_size 8
python scripts/06_finetune_lora.py --task sentiment --batch_size 88. Deploy
python scripts/09_deploy_space.py --username your-username --space_name zabaanai-demoš§ CPU Training Configuration
Training time: ~70 hours for 50K steps on 8-core CPU, or ~3 hours on T4 GPU.
šÆ Task Fine-Tuning
Translation
python scripts/06_finetune_lora.py --task translation
# Datasets: Humair332/Vast-Urdu (10M pairs), Kashmiri-English, Pashto-EnglishSentiment Analysis
python scripts/06_finetune_lora.py --task sentiment
# Datasets: community-datasets/roman_urdu, urdu_sentiment_corpusSummarization
python scripts/06_finetune_lora.py --task summarization
# Datasets: News articles with headlines as pseudo-summariesQuestion Answering
python scripts/06_finetune_lora.py --task qa
# Datasets: Sindhi encyclopedia, generated Q&A pairsChatbot / Conversational AI
python scripts/06_finetune_lora.py --task chatbot
# Datasets: Urdu-Instruct, Sindhi SFT, Pashto Alpacaš Deployment Options
š Data Mixture for Pretraining
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)š¤ Tokenizer
mT5's native tokenizer already covers all Pakistan scripts with 250,000 tokens + byte fallback. We extended it with 52 Pakistan-specific tokens:
- Cities:
ŁŲ§ŪŁŲ±,کراŚŪ,Ų§Ų³ŁŲ§Ł Ų¢ŲØŲ§ŲÆ,پؓاŁŲ±,Ś©ŁŲ¦Ł¹Ū - Names:
Ł ŲŁ ŲÆ,Ų¹ŁŪ,ŁŲ§Ų·Ł Ū - Institutions:
Ų³Ł¾Ų±ŪŁ Ś©ŁŲ±Ł¹,ŁŪŲ“ŁŁ اس٠بŁŪ - Roman Urdu:
bhai,yaar,theek
Vocabulary size: 250,141 (was 250,100)
š Evaluation
python scripts/07_evaluate.py --model_path training/checkpoints/final --task translation
# Metrics: BLEU (translation), ROUGE (summarization), Perplexity (generation)š¾ Quantization for Production
# 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 8bitBenefits: 60-70% smaller model, 2-3x faster inference on CPU.
š¤ Contributing
We welcome contributions! Priority areas:
- More datasets for Saraiki, Hindko, Brahui
- Better evaluation benchmarks
- Fine-tuned task-specific adapters
- Documentation translations
š License
Apache 2.0 (same as mT5 base model)
š Acknowledgments
- Google Research for mT5
- ZamAI for Pashto datasets
- aakashMeghwar01 for Sindhi corpus
- Humair332 for Vast-Urdu parallel corpus
- Omarrran for Kashmiri datasets
- community-datasets for Roman Urdu sentiment data
š Citation
@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 šµš°
