CoolFace
Modelpublic

FarazAbdulMuqtader/roman-urdu-sentiment-xlmr

sourceHugging Facemitupdated 15d agoView on Hugging Face
1likes41downloads
Model Card

Roman Urdu Sentiment Analysis (XLM-RoBERTa)

Fine-tuned XLM-RoBERTa model for sentiment analysis on Roman Urdu (Urdu written in Latin script) โ€” the informal script most commonly used across Pakistani social media, messaging, and reviews.

๐Ÿš€ [Try the live demo](https://huggingface.co/spaces/FarazAbdulMuqtader/roman-urdu-sentiment-demo)

๐Ÿ“ฆ [GitHub repo](https://github.com/FarazAbdulMuqtader/Roman-Urdu-Sentiment-Analysis) (full pipeline: preprocessing, training, evaluation scripts)

Model description

This model classifies Roman Urdu text into one of three sentiment classes: Positive, Negative, or Neutral. It's built on xlm-roberta-base, fine-tuned on a large Roman Urdu sentiment corpus to handle the inconsistent spelling and English code-mixing typical of informal Roman Urdu text.

How to use

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_id = "FarazAbdulMuqtader/roman-urdu-sentiment-xlmr"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

label_names = ["Positive", "Negative", "Neutral"]

def predict_sentiment(text):
    encoding = tokenizer(text, padding="max_length", truncation=True, max_length=128, return_tensors="pt")
    with torch.no_grad():
        logits = model(**encoding).logits
    probs = torch.softmax(logits, dim=1).squeeze()
    predicted_id = torch.argmax(probs).item()
    return label_names[predicted_id], probs[predicted_id].item()

label, confidence = predict_sentiment("wah kya baat hai zabardast")
print(f"{label} ({confidence*100:.1f}%)")

Training data

  • โ€”Source: `Khubaib01/RomanUrdu-NLP-Sentiment-Corpus`
  • โ€”~134K raw samples, cleaned down to ~129,377 rows after preprocessing (deduplication, length filtering, normalization)
  • โ€”Split: 103,501 train / 25,876 held-out test (stratified 80/20)

Training procedure

  • โ€”Base model: xlm-roberta-base
  • โ€”3 epochs, batch size 16, learning rate 2e-5, AdamW optimizer
  • โ€”Trained on a Kaggle T4 GPU
  • โ€”Max sequence length: 128 tokens

Evaluation results

Evaluated on the 25,876-row held-out test set.

Overall accuracy: 81%

LabelPrecisionRecallF1-scoreSupport
Positive0.810.820.827,252
Negative0.840.850.8510,504
Neutral0.780.760.778,120
Accuracy0.8125,876
Macro avg0.810.810.8125,876
Weighted avg0.810.810.8125,876

Confusion matrix (rows = actual, columns = predicted):

PositiveNegativeNeutral
Positive5,977508767
Negative5888,920996
Neutral8021,1776,141

Limitations

  • โ€”Neutral is the weakest class (78% precision, 76% recall) โ€” most confusion happens between Neutral and the other two classes, which is expected since neutral sentiment in short, code-mixed social text is inherently ambiguous (sarcasm, mild opinions, and rhetorical statements often blur the line).
  • โ€”Negative is the most reliably distinguished class (84% precision, 85% recall).
  • โ€”The model was trained and evaluated specifically on Roman Urdu. Since it's built on multilingual XLM-RoBERTa, it also handles plain English and code-mixed text reasonably, but accuracy on those inputs hasn't been formally evaluated.
  • โ€”Performance on heavily sarcastic, ironic, or highly context-dependent text may be lower than the aggregate numbers suggest, as these are known hard cases for sentiment classifiers in general.
  • โ€”The training corpus reflects informal Pakistani social media text; performance may differ on more formal Roman Urdu writing (e.g. news, official communication).

Intended use

Built to address a low-resource, code-mixed language largely underserved by mainstream NLP tooling. Suitable for sentiment tagging of Roman Urdu social media posts, reviews, and messages. Not intended for high-stakes decision-making without human review.