stanfordnlp/imdb
Viewer • Updated • 100k • 189k • 371
How to use harshaojha/bert-imdb-finetuned with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="harshaojha/bert-imdb-finetuned") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("harshaojha/bert-imdb-finetuned")
model = AutoModelForSequenceClassification.from_pretrained("harshaojha/bert-imdb-finetuned")A fine-tuned bert-base-uncased model that classifies English text as Positive or Negative sentiment. Trained on the IMDB movie reviews dataset.
🎛️ Live demo: huggingface.co/spaces/harshaojha/bert-imdb-demo
bert-base-uncased (110M parameters)0 = Negative, 1 = PositiveEducational / demonstration — learning how to fine-tune a transformer and wrap it in a web UI. Works well on movie-review-style text; less reliable on other domains.
A balanced subset of the IMDB reviews dataset:
| Hyperparameter | Value |
|---|---|
| Optimizer | AdamW |
| Learning rate | 2e-5 |
| Batch size (train / eval) | 16 / 32 |
| Epochs | 3 |
| Weight decay | 0.01 |
| Warmup ratio | 0.1 |
| Max sequence length | 256 |
| Best-checkpoint metric | accuracy |
| Hardware | NVIDIA T4 GPU (Google Colab) |
| Epoch | Validation Accuracy |
|---|---|
| 1 | 89.80% |
| 2 | 91.45% ← best |
| 3 | 91.10% |
from transformers import pipeline
clf = pipeline("text-classification", model="harshaojha/bert-imdb-finetuned")
ID2LABEL = {"LABEL_0": "Negative", "LABEL_1": "Positive"}
result = clf("An absolute masterpiece.")[0]
print(ID2LABEL[result["label"]], round(result["score"], 3))
# Positive 0.993
Or load the tokenizer and model directly:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("harshaojha/bert-imdb-finetuned")
model = AutoModelForSequenceClassification.from_pretrained("harshaojha/bert-imdb-finetuned")
inputs = tokenizer("Painfully boring.", return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)[0]
print({"Negative": probs[0].item(), "Positive": probs[1].item()})
bert-base-uncased model.Trained by @harshaojha as part of a learning project on transformer fine-tuning.
Base model
google-bert/bert-base-uncased