stanfordnlp/imdb
Viewer • Updated • 100k • 271k • 380
How to use nkadoor/sentiment-classifier-roberta with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="nkadoor/sentiment-classifier-roberta") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("nkadoor/sentiment-classifier-roberta")
model = AutoModelForSequenceClassification.from_pretrained("nkadoor/sentiment-classifier-roberta")This model is a fine-tuned version of roberta-base for sentiment analysis on movie reviews.
| Metric | Value |
|---|---|
| Test Accuracy | 0.9590 |
| Test F1 Score | 0.9791 |
| Test Precision | 1.0000 |
| Test Recall | 0.9590 |
| Parameter | Value |
|---|---|
| Training epochs | 3 |
| Batch size | 16 |
| Learning rate | 5e-05 |
| Warmup steps | 500 |
| Weight decay | 0.01 |
| Max sequence length | 512 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
# Using pipeline (recommended for quick inference)
classifier = pipeline("sentiment-analysis",
model="nkadoor/sentiment-classifier-roberta",
tokenizer="nkadoor/sentiment-classifier-roberta")
result = classifier("This movie was amazing!")
print(result) # [{'label': 'POSITIVE', 'score': 0.99}]
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
tokenizer = AutoTokenizer.from_pretrained("nkadoor/sentiment-classifier-roberta")
model = AutoModelForSequenceClassification.from_pretrained("nkadoor/sentiment-classifier-roberta")
def predict_sentiment(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
sentiment = "positive" if predicted_class == 1 else "negative"
return sentiment, confidence
# Example usage
text = "This movie was absolutely fantastic!"
sentiment, confidence = predict_sentiment(text)
print(f"Sentiment: {sentiment} (Confidence: {confidence:.4f})")
The model was trained on the IMDB Movie Reviews Dataset, which contains movie reviews labeled as positive or negative sentiment. The dataset consists of:
This model is intended for sentiment analysis of English movie reviews or similar text. It can be used to:
If you use this model, please cite:
@misc{sentiment-classifier-roberta,
title={Fine-tuned RoBERTa for Sentiment Analysis},
author={Narayana Kadoor},
year={2025},
url={https://huggingface.co/nkadoor/sentiment-classifier-roberta}
}
Final training metrics:
Model trained using Transformers library by Hugging Face