Views
No views yet
| Metric | Value |
|---|---|
| Accuracy | 86.50% |
| F1 Score | 0.8672 |
| Precision | 84.21% |
| Recall | 89.47% |
1from transformers import pipeline
2
3# Load the model
4sentiment = pipeline("sentiment-analysis", model="shane-reaume/imdb-sentiment-analysis-v2")
5
6# Analyze text
7result = sentiment("I really enjoyed this movie!")
8print(result) # [{'label': 'POSITIVE', 'score': 0.9998}]
9
10# Batch processing
11texts = [
12 "This movie was absolutely amazing, I loved every minute of it!",
13 "The acting was terrible and the plot made no sense at all."
14]
15results = sentiment(texts)
16for i, (text, result) in enumerate(zip(texts, results)):
17 print(f"Text: {{text}}")
18 print(f"Sentiment: {{result['label']}}, Score: {{result['score']:.4f}}")1from transformers import AutoModelForSequenceClassification, AutoTokenizer
2import torch
3
4# Load model and tokenizer
5model_name = "shane-reaume/imdb-sentiment-analysis-v2"
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8
9# Prepare text
10text = "I really enjoyed this movie!"
11inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
12
13# Get prediction
14with torch.no_grad():
15 outputs = model(**inputs)
16
17# Process outputs
18probabilities = torch.nn.functional.softmax(outputs.logits, dim=-1)
19prediction = torch.argmax(probabilities, dim=-1).item()
20confidence = probabilities[0][prediction].item()
21
22# Map prediction to label (0: negative, 1: positive)
23sentiment_label = "POSITIVE" if prediction == 1 else "NEGATIVE"
24print(f"Sentiment: {{sentiment_label}}, Confidence: {{confidence:.4f}}")@misc{sentiment-analysis-model,
author = {Your Name},
title = {Sentiment Analysis Model based on DistilBERT},
year = {2023},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/shane-reaume/imdb-sentiment-analysis-v2}}
}