This is a fine-tuned RoBERTa model for Aspect-Based Sentiment Analysis (ABSA) on food delivery reviews, achieving 93.97% accuracy on the validation set. The model analyzes customer reviews across multiple specific aspects like food quality, delivery service, pricing, and more.
🎯 What is Aspect-Based Sentiment Analysis?
Unlike traditional sentiment analysis that gives one overall sentiment, ABSA identifies sentiment for specific aspects of a product or service. For example:
"The food was amazing but delivery took forever"
Food aspect: ✅ Positive
Delivery aspect: ❌ Negative
This granular analysis helps businesses identify exactly what customers love and what needs improvement.
🚀 Quick Start
Using the Model
python
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
34# Load model and tokenizer5model_name ="Anudeep-Narala/fabsa-roberta-sentiment"6tokenizer = AutoTokenizer.from_pretrained(model_name)7model = AutoModelForSequenceClassification.from_pretrained(model_name)89# Example: Analyze a review10review ="The food was delicious but the delivery was slow"11aspect ="delivery"# Can be: food, delivery, service, price, interface, overall1213# Format input14input_text =f"Review: {review} | Aspect: {aspect}"15inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=256)1617# Get prediction18with torch.no_grad():19 outputs = model(**inputs)20 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)21 predicted_class = torch.argmax(predictions, dim=-1).item()22 confidence = predictions[0][predicted_class].item()2324# Map prediction to sentiment25sentiment_map ={0:"negative",1:"neutral",2:"positive"}26print(f"Aspect: {aspect}")27print(f"Sentiment: {sentiment_map[predicted_class]}")28print(f"Confidence: {confidence:.2%}")
Batch Processing Multiple Aspects
python
1defanalyze_review(review_text, aspects=["food","delivery","service","price"]):2"""Analyze a review across multiple aspects"""3 results ={}45for aspect in aspects:6 input_text =f"Review: {review_text} | Aspect: {aspect}"7 inputs = tokenizer(input_text, return_tensors="pt", truncation=True, max_length=256)89with torch.no_grad():10 outputs = model(**inputs)11 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)12 predicted_class = torch.argmax(predictions, dim=-1).item()13 confidence = predictions[0][predicted_class].item()1415 sentiment_map ={0:"negative",1:"neutral",2:"positive"}16 results[aspect]={17"sentiment": sentiment_map[predicted_class],18"confidence": confidence
19}2021return results
2223# Example usage24review ="Great food and reasonable prices, but the app keeps crashing"25results = analyze_review(review)2627for aspect, result in results.items():28print(f"{aspect.capitalize()}: {result['sentiment']} (confidence: {result['confidence']:.2%})")
📈 Performance Metrics
Metric
Value
Validation Accuracy
93.97%
Training Loss
0.1611
Validation Loss
0.1749
Training Time
302.74 seconds
Training Examples
13,998
Validation Examples
1,858
🎯 Supported Aspects
The model is trained to analyze sentiment for these specific aspects: