Views
No views yet
distilbert/distilbert-base-multilingual-cased specifically optimized for sentiment analysis of Italian-language Tripadvisor reviews. The model was trained on a dataset of 15,000 Italian Tripadvisor reviews to classify sentiment into positive, negative, or neutral categories.distilbert-base-multilingual-casedtransformers library:1from transformers import pipeline
2
3# Initialize sentiment analysis pipeline
4sentiment_analyzer = pipeline(
5 "text-classification",
6 model="misterkigore/distilbert-italian-tripadvisor-sentiment",
7 tokenizer="misterkilgore/distilbert-italian-tripadvisor-sentiment"
8)
9
10# Analyze a sample review
11review = "L'hotel aveva una vista magnifica ma il servizio era terribile."
12results = sentiment_analyzer(review)
13print(results)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "misterkilgore/distilbert-italian-tripadvisor-sentiment"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
9# Prepare input
10review = "Il ristorante offre una cucina eccellente con ingredienti di prima qualità."
11inputs = tokenizer(review, return_tensors="pt", truncation=True, padding=True)
12
13# Get predictions
14with torch.no_grad():
15 outputs = model(**inputs)
16 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
17
18# Interpret results
19labels = ["very negative", "negative", "neutral", "positive", "very positive"]
20scores = predictions[0].tolist()
21for label, score in zip(labels, scores):
22 print(f"{label}: {score:.4f}")| Metric | Score |
|---|---|
| Accuracy | 0.73 |
| F1 (macro) | 0.70 |
| Precision | 0.69 |
| Recall | 0.73 |