stanfordnlp/imdb
Viewer β’ Updated β’ 100k β’ 175k β’ 472
This model is a fine-tuned version of distilbert-base-uncased for 2-class sentiment analysis (Positive, Negative) on movie reviews.
from transformers import pipeline
# Load the model
classifier = pipeline("sentiment-analysis",
model="your-username/sentiment-analysis-distilbert")
# Single prediction
result = classifier("This movie is fantastic!")
print(result)
# Output: [{'label': 'POSITIVE', 'score': 0.9987}]
# Batch prediction
texts = [
"Amazing cinematography and great acting!",
"Boring and predictable storyline.",
"It was an okay 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})")
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model_name = "your-username/sentiment-analysis-distilbert"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Prepare input
text = "This movie exceeded my expectations!"
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
# Get prediction
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Get predicted class
predicted_class = torch.argmax(predictions, dim=-1).item()
confidence = predictions[0][predicted_class].item()
labels = ["NEGATIVE", POSITIVE"]
print(f"Sentiment: {labels[predicted_class]} (Confidence: {confidence:.3f})")
distilbert-base-uncased| Metric | Score |
|---|---|
| Training Accuracy | ~95% |
| Validation Accuracy | ~93% |
| Training Loss | 0.12 |
| Validation Loss | 0.18 |
DistilBERT Base
βββ Transformer Layers: 6
βββ Hidden Size: 768
βββ Attention Heads: 12
βββ Intermediate Size: 3072
βββ Classification Head: Linear(768 β 3)
{
'label': 'POSITIVE', # One of: NEGATIVE, POSITIVE
'score': 0.9987 # Confidence score (0-1)
}
If you use this model in your research or applications, please cite:
@misc{sentiment-analysis-distilbert,
title={Fine-tuned DistilBERT for Sentiment Analysis},
author={Your Name},
year={2024},
publisher={Hugging Face},
url={https://huggingface.co/your-username/sentiment-analysis-distilbert}
}
This model is released under the Apache 2.0 License. See the LICENSE file for details.
Issues and pull requests are welcome! Please feel free to:
This model was created as part of a sentiment analysis fine-tuning project using modern NLP techniques and best practices.
Base model
distilbert/distilbert-base-uncased