stanfordnlp/imdb
Viewer • Updated • 100k • 189k • 698
How to use cannizaroo/imdb-bert-sentiment with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="cannizaroo/imdb-bert-sentiment") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("cannizaroo/imdb-bert-sentiment")
model = AutoModelForSequenceClassification.from_pretrained("cannizaroo/imdb-bert-sentiment", device_map="auto")A fine-tuned BERT-base-uncased model for binary sentiment classification of IMDb movie reviews.
The model was fine-tuned using PyTorch and the Hugging Face Transformers Trainer API.
bert-base-uncasedBertForSequenceClassification| ID | Label |
|---|---|
| 0 | negative |
| 1 | positive |
0 → negative
1 → positive
This model can be used directly for binary sentiment classification of English movie reviews (or similar review-style text):
negative — negative sentimentpositive — positive sentimentfrom transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
model_id = "cannizaroo/imdb-bert-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
model.eval()
text = "This movie was absolutely fantastic. I loved every minute."
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
with torch.no_grad():
outputs = model(**inputs)
predicted_id = outputs.logits.argmax(dim=-1).item()
print(model.config.id2label[predicted_id]) # "positive" or "negative"
Using the pipeline API:
from transformers import pipeline
classifier = pipeline("text-classification", model="cannizaroo/imdb-bert-sentiment")
classifier("This movie was absolutely fantastic. I loved every minute.")
# [{'label': 'positive', 'score': ...}]
IMDb Movie Reviews (imdb):
0 → Negative, 1 → Positiveinput_ids + attention_mask), with padding and truncationFine-tuned with:
TrainerLearning Rate: 2e-5
Batch Size: 16
Epochs: 2
Weight Decay: 0.01
Maximum Sequence Length: 512
Evaluated on the final held-out IMDb test set:
Model: BERT-base-uncased + Fine-tuning
Accuracy: 93.21%
Precision: 95.53%
Recall: 90.66%
F1 Score: 93.03%
Predicted
Negative Positive
Actual Negative 11970 530
Actual Positive 1167 11333
Metrics computed with Hugging Face Evaluate and scikit-learn.
bert-base-uncased pretraining corpus.If you use this model, please cite the base model and dataset:
@article{devlin2018bert,
title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
journal={arXiv preprint arXiv:1810.04805},
year={2018}
}
@inproceedings{maas2011learning,
title={Learning Word Vectors for Sentiment Analysis},
author={Maas, Andrew L. and Daly, Raymond E. and Pham, Peter T. and Huang, Dan and Ng, Andrew Y. and Potts, Christopher},
booktitle={Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics},
year={2011}
}