stanfordnlp/imdb
Viewer • Updated • 100k • 178k • 370
How to use Hums003/distilbert-imdb-sentiment with Transformers:
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("Hums003/distilbert-imdb-sentiment", dtype="auto")This model is a fine-tuned version of distilbert-base-uncased for binary sentiment classification on the IMDB movie reviews dataset.
distilbert-base-uncasedfrom transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
# Load model and tokenizer
model_name = "Hums003/distilbert-imdb-sentiment"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
# Prepare text
text = "This movie was absolutely fantastic! I loved every minute of it."
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
# Get predictions
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
# Interpret results
sentiment = "positive" if predictions[0][1] > 0.5 else "negative"
confidence = predictions[0][1].item() if predictions[0][1] > 0.5 else predictions[0][0].item()
print(f"Sentiment: {sentiment} (confidence: {confidence:.2%})")