Downloads · 30 days
18
3% of all-time downloads
tahamueed23/fine_tuned_cardiffnlp_urdu_and_roman-urdu
fine_tuned_cardiffnlp_urdu_and_roman-urdu is a machine learning model from tahamueed23. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This repository contains a custom fine-tuned version of cardiffnlp/twitter-xlm-roberta-base-sentiment, optimized for Urdu and Roman-Urdu sentiment classification. The model is trained for 3-way sentiment analysis:
Downloads · 30 days
18
3% of all-time downloads
All-time downloads
670
Public
Parameters
278M
4.4 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors1.1 GB · 98%
From the Hugging Face model README
This repository contains a custom fine-tuned version of cardiffnlp/twitter-xlm-roberta-base-sentiment, optimized for Urdu and Roman-Urdu sentiment classification.
The model is trained for 3-way sentiment analysis:
This model is ideal for analyzing user feedback, social media comments, product reviews, educational surveys, and general-purpose Urdu/Roman-Urdu sentiment tasks.
A mixed dataset of Urdu and Roman-Urdu 26k sentences was used, representing:
Dataset was designed to test multilingual robustness and low-resource language performance.
Baseline fine-tuning of CardiffNLP Twitter-XLM-RoBERTa on an Urdu & Roman Urdu student feedback sentiment analysis dataset.
| Epoch | Training Loss | Validation Loss | Accuracy | F1 |
|---|---|---|---|---|
| 1 | 0.466900 | 0.344824 | 0.903001 | 0.897680 |
| 2 | 0.309900 | 0.336189 | 0.916920 | 0.913238 |
| 3 | 0.234500 | 0.367444 | 0.917355 | 0.915728 |
| 4 | 0.172900 | 0.398893 | 0.923880 | 0.921845 |
| 5 | 0.122500 | 0.438851 | 0.923880 | 0.922915 |
The final model is selected from Epoch 2, based on the minimum validation loss, to ensure better generalization on unseen Urdu and Roman Urdu student feedback.
This model performs well for real-world Urdu/Roman-Urdu texts with mixed grammar, slang, emojis, and conversational tone.
You can use this model directly with the Hugging Face transformers library for inference.
Ensure you have the necessary libraries installed:
pip install transformers torch
The following Python code snippet demonstrates how to load the model and tokenizer and perform sentiment classification on a sample text.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
# Define the model name
model_name = "tahamueed23/fine_tuned_cardiffnlp_urdu_and_roman-urdu"
# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Example text in Roman Urdu
text = "Bohat acha kam kia hai! Maza agaya." # (Translation: You did a very good job! It was fun.)
# Tokenize the input text
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
# Perform inference
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Get the predicted class and score
# Note: The label mapping (e.g., 0, 1, 2) depends on the dataset used for fine-tuning.
# Common mappings are: 0=Negative, 1=Neutral, 2=Positive.
predicted_class_id = predictions.argmax().item()
score = predictions[0][predicted_class_id].item()
print(f"Input Text: {text}")
print(f"Predicted Class ID: {predicted_class_id}")
print(f"Confidence Score: {score:.4f}")
# You may need to define the label mapping based on your training data
# Example:
# labels = ["Negative", "Neutral", "Positive"]
# print(f"Predicted Sentiment: {labels[predicted_class_id]}")
If you use this model in your research or project, please consider citing the original work by CardiffNLP and the XLM-RoBERTa paper.
@article{barbieri2020tweeteval,
title={TweetEval: Unified Benchmark and Comparative Evaluation for Tweet Classification},
author={Barbieri, Francesco and Camacho-Collados, Jose and Espinosa-Anke, Luis and Neves, Leonardo},
journal={arXiv preprint arXiv:2010.12421},
year={2020}
}
@article{conneau2019unsupervised,
title={Unsupervised Cross-lingual Representation Learning at Scale},
author={Conneau, Alexis and Khandelwal, Urvashi and Goyal, Naman and Goyal, Vitaly and Gu, Jingfei and Popat, Luke and Ko, Damian and Zettlemoyer, Luke},
journal={arXiv preprint arXiv:1911.02116},
year={2019}
}
For questions or feedback regarding this fine-tuned model, please contact the model owner: [email protected].