This project presents an end-to-end Urdu sentiment analysis system built by fine-tuning a multilingual transformer model on an Urdu dataset. It classifies Urdu text into Positive, Negative, and Neutral sentiments and is deployed as a real-time web application using Gradio and Hugging Face Spaces.
It demonstrates a complete NLP pipeline from
data preprocessing → model training → evaluation → deployment.
Urdu is a low-resource language in Natural Language Processing (NLP), with limited labeled datasets and pretrained models.
This creates challenges for building accurate sentiment analysis systems in real-world Urdu applications.
- Build a robust Urdu sentiment classification system
- Fine-tune a transformer-based model on Urdu dataset
- Develop an end-to-end deployable AI pipeline
- Enable real-time sentiment prediction through a web interface
- 🇵🇰 Focus on Urdu language NLP
- Fine-tuned mBERT transformer model
- Real-time inference with Gradio
- Deployed on Hugging Face Spaces
- Full NLP pipeline training + evaluation + deployment
Use a pretrained multilingual transformer:
👉 mBERT
Why mBERT?
- Supports Urdu language
- Strong performance on low-resource NLP tasks
- Pretrained on multilingual corpora
- Easy fine-tuning for classification tasks
- Source: HuggingFace Dataset Hub
- Dataset: Urdu Multi-Domain Classification
🔗 https://huggingface.co/datasets/umar178/UrduMultiDomainClassification
The dataset was cleaned and prepared using the following steps:
- Removed irrelevant columns:
topic,intent,binary - Filtered dataset to keep only 3 sentiment classes
- Removed low-frequency class
request - Ensured balanced class distribution
Urdu text was normalized using LughaatNLP.
- Removes noise and inconsistencies
- Standardizes Urdu spelling variations
- Improves tokenization quality
- Enhances model generalization
Raw Urdu Text
↓
Text Normalization (LughaatNLP)
↓
Tokenization (mBERT Tokenizer)
↓
Fine-tuned Transformer Model
↓
Sentiment Prediction (Positive / Negative / Neutral)
↓
Gradio Web Interface
- Python
- PyTorch
- Hugging Face Transformers
- Datasets Library
- Gradio UI
- Scikit-learn
- Model: mBERT multilingual BERT
- Task: Sentiment Classification
- Loss Function: CrossEntropyLoss
- Optimizer: AdamW
- Evaluation: Accuracy, Precision, Recall, F1-score
- Best model saved using Hugging Face Trainer
The model achieves strong performance on Urdu sentiment classification:
- Accuracy: 0.91
- F1 Score: 0.91
- Balanced performance across all classes
The model is deployed using:
- Gradio interface
- Hugging Face Spaces
It supports real-time prediction of Urdu text sentiment.
https://huggingface.co/spaces/arifa-batool/urdu-sentiment-classifier
✔ End-to-end NLP pipeline
✔ Low-resource language support Urdu
✔ Transformer-based fine-tuning
✔ Real-time web deployment
✔ Clean and interactive UI
This project demonstrates a complete end-to-end NLP system for Urdu sentiment analysis, covering:
- Fine-tuning transformer models for Urdu NLP
- Effective preprocessing for low-resource languages
- Evaluation using standard ML metrics
- Deployment using Gradio and Hugging Face Spaces
git https://github.com/batoolarifa/urdu-ai-sentiment-system.gitpip install -r requirements.txt
streamlit run app.pySyeda Arifa Batool
SE @ Karachi University | AI/ML Engineer | Applying technology to create real-world value 📈
- LinkedIn: Syeda Arifa Batool
- Kaggle: Syeda Arifa Batool
- Email: thearifabatool@gmail.com
⭐ If you find this project useful, feel free to star the repository!


