Views
No views yet
transformers library:1from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
2import torch
3
4# Load the model and tokenizer
5model_name = "Ashaduzzaman/imdb-distilbert-funetuned",
6tokenizer = DistilBertTokenizer.from_pretrained(model_name)
7model = DistilBertForSequenceClassification.from_pretrained(model_name)
8
9# Example text
10text = "The movie was absolutely fantastic! The acting was superb and the story was gripping."
11
12# Tokenize and predict
13inputs = tokenizer(text, return_tensors="pt")
14outputs = model(**inputs)
15logits = outputs.logits
16predictions = torch.softmax(logits, dim=1)
17
18# Get the predicted label
19predicted_label = torch.argmax(predictions).item()
20labels = ["Negative", "Positive"]
21print(f"Predicted sentiment: {labels[predicted_label]}")| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|---|---|---|---|---|
| 0.2239 | 1.0 | 1563 | 0.2026 | 0.9227 |
| 0.1468 | 2.0 | 3126 | 0.2319 | 0.9320 |