YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
language: en license: mit datasets: - imdb metrics: - accuracy base_model: distilbert-base-uncased tags: - sentiment-analysis - nlp - transformers - pytorch
DistilBERT IMDB Sentiment Classifier
Model Description
This model is a fine-tuned version of DistilBERT (distilbert-base-uncased) for binary sentiment classification on movie reviews. It predicts whether a given English text expresses positive or negative sentiment.
The model was trained on the IMDB Large Movie Review Dataset (25,000 training reviews) and achieves 90.92% accuracy on a held-out validation set.
This project was created as a learning exercise to understand:
- Fine-tuning transformer models with Hugging Face
transformers - Data preprocessing and tokenization
- Training with PyTorch on Google Colab (Tesla T4 GPU)
- Model deployment via Hugging Face Hub
Model Details
- Developed by: Muhammad Ali
- Model type: Transformer-based text classification
- Language(s): English
- License: MIT
- Fine-tuned from model:
distilbert-base-uncased - Repository: GitHub - imdb-sentiment-analyzer
- Live Demo: imdb-sentiment-demo
)
Intended Uses
Direct Use
You can use this model to classify the sentiment of any English text, especially movie reviews or short product reviews.
from transformers import pipeline
classifier = pipeline("sentiment-analysis", model="mohdali1/distilbert-imdb-sentiment")
result = classifier("This movie was absolutely fantastic!")
print(result) # [{'label': 'POSITIVE', 'score': 0.998...}]
Out-of-Scope Use
- The model was trained only on movie reviews. Performance on other domains (e.g., political text, medical notes) may be lower.
- It is not intended for detecting nuanced emotions (anger, joy, sadness) โ only positive/negative polarity.
- Very long texts (>512 tokens) will be truncated.
Bias, Risks, and Limitations
- Dataset bias: IMDB reviews are written by English-speaking users and may not represent global or non-English sentiment expressions.
- Simple labels: Reviews with mixed sentiment (e.g., "good acting but terrible plot") are forced into a single positive/negative class. The model may struggle with such ambiguity.
- No demographic balancing: The original dataset does not provide author demographics, so the model may reflect unseen biases.
Recommendations
Users should consider testing the model on their specific domain before production use. For critical applications, combine with human review or confidence thresholds.
How to Get Started
Using the pipeline (easiest)
from transformers import pipeline
sentiment_pipeline = pipeline("sentiment-analysis", model="mohdali1/distilbert-imdb-sentiment")
sentiment_pipeline("A gripping story with brilliant performances.")
Using the model & tokenizer directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_name = "mohdali1/distilbert-imdb-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
inputs = tokenizer("Waste of time, boring plot.", return_tensors="pt")
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=1)
print(probs) # tensor([[0.92, 0.08]]) -> negative with 92% confidence
Training Details
Training Data
- Dataset: IMDB Large Movie Review Dataset
- Training samples: 25,000 labeled reviews (12,500 positive, 12,500 negative)
- Preprocessing: Lowercased, tokenized with DistilBERT tokenizer, truncated/padded to 512 tokens.
Training Procedure
- Framework: PyTorch + Hugging Face Transformers
- Hardware: Google Colab (Tesla T4 GPU, 16GB VRAM)
- Batch size: 16
- Epochs: 1
- Optimizer: AdamW
- Learning rate: 2e-5
- Loss function: Cross-entropy
Training Time
Approximately 18 minutes for 1 epoch (1,250 training steps).
Evaluation
Validation Data
- Split: 20% of training data held out (5,000 reviews)
- Stratified: Same class distribution as full dataset
Metrics
- Accuracy: 90.92%
- Loss: 0.2543
Results
| Predicted Negative | Predicted Positive | |
|---|---|---|
| Actual Neg | ~2,280 | ~220 |
| Actual Pos | ~234 | ~2,266 |
The model is slightly better at detecting positive sentiment but balanced overall.
Environmental Impact
- Hardware: NVIDIA T4 GPU (Google Colab)
- Hours used: ~0.3 hours (18 minutes)
- Cloud Provider: Google Cloud Platform (through Colab)
- Carbon Emitted: ~0.02 kg COโ (estimated via ML Impact Calculator)
Acknowledgements
- Hugging Face for the
transformersanddatasetslibraries - Stanford AI Lab for the IMDB dataset
- Google Colab for free GPU access
Contact
- GitHub: mohdali-dev
- LinkedIn: Muhammad Ali
- Hugging Face: mohdali1
Model Card Contact
For questions or feedback, please open an issue on the GitHub repository or reach out via LinkedIn.
- Downloads last month
- 14