Downloads · 30 days
0
makbar023/roman-sentiment-model
roman-sentiment-model is a text classification model from makbar023. Use it when you need a label for a piece of text. The card lists the license as apache-2.0.
This model performs sentiment analysis on Roman Urdu (Romanized Urdu) text, classifying input into three categories: Negative, Neutral, and Positive. It can analyze both single sentences and batch process multiple sen…
Downloads · 30 days
0
Access
Public
Updated Feb 3, 2026
Repo size
670 MB
Likes
0
Public
Click a slice to open those files.
.pth670 MB · 100%
From the Hugging Face model README
This model performs sentiment analysis on Roman Urdu (Romanized Urdu) text, classifying input into three categories: Negative, Neutral, and Positive. It can analyze both single sentences and batch process multiple sentences from files.
This model is designed for:
nlptown/bert-base-multilingual-uncased-sentimentThe model was trained on a combined dataset of Roman Urdu reviews from three sources:
This diverse combination of datasets enables the model to generalize across different product categories and review types commonly found in Pakistani consumer feedback.
Note: The model is particularly well-suited for analyzing product reviews, customer feedback, and brand sentiment in the Pakistani market context.
The model achieves 87%+ accuracy on sentiment classification tasks for Roman Urdu text.
Note: Detailed performance metrics including precision, recall, and F1-scores for individual classes will be added in future updates.
The model was evaluated on a held-out test set from the combined dataset of Daraz reviews, Pakistan car reviews, and brand reviews.
pip install transformers torch huggingface_hub
import torch
import torch.nn as nn
from transformers import BertModel, BertTokenizer, BertConfig
from huggingface_hub import hf_hub_download
# Define the model class
class ModifiedBertForSentiment(nn.Module):
def __init__(self, config, n_classes):
super(ModifiedBertForSentiment, self).__init__()
self.bert = BertModel(config)
self.drop = nn.Dropout(p=0.3)
self.out = nn.Linear(config.hidden_size, n_classes)
def forward(self, input_ids, attention_mask):
outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)
pooled_output = outputs.last_hidden_state.mean(dim=1)
output = self.drop(pooled_output)
return self.out(output)
# Load model and tokenizer
class_names = ['Negative', 'Neutral', 'Positive']
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = BertTokenizer.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')
config = BertConfig.from_pretrained('nlptown/bert-base-multilingual-uncased-sentiment')
model = ModifiedBertForSentiment(config, len(class_names))
# Download and load weights
model_file = hf_hub_download(
repo_id="makbar023/roman-sentiment-model",
filename="roman_Sentiment.pth"
)
model.load_state_dict(torch.load(model_file, map_location=device))
model.to(device)
model.eval()
# Predict sentiment
def predict_sentiment(text):
inputs = tokenizer(text, padding=True, truncation=True,
return_tensors='pt', max_length=512)
input_ids = inputs['input_ids'].to(device)
attention_mask = inputs['attention_mask'].to(device)
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
_, preds = torch.max(outputs, dim=1)
probs = torch.nn.functional.softmax(outputs, dim=1)
sentiment = class_names[preds.item()]
confidence = {class_names[i]: float(probs[0][i]) for i in range(len(class_names))}
return sentiment, confidence
# Example
text = "yeh product bohat acha hai"
sentiment, probabilities = predict_sentiment(text)
print(f"Sentiment: {sentiment}")
print(f"Probabilities: {probabilities}")
If you use this model in your research or applications, please cite:
@misc{roman-urdu-sentiment,
author = {Muhammad Akbar},
title = {Roman Urdu Sentiment Analysis Model},
year = {2024},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/makbar023/roman-sentiment-model}}
}
For questions or feedback, please open an issue on the model repository or contact [email protected].