Downloads · 30 days
7
11% of all-time downloads
Strawberry0604/xlm-roberta-tourism-sentiment
xlm-roberta-tourism-sentiment is a text classification model from Strawberry0604. Use it when you need a label for a piece of text. The card lists the license as mit.
Fine-tuned XLM-RoBERTa model for multilingual tourism comment sentiment analysis.
Downloads · 30 days
7
11% of all-time downloads
All-time downloads
66
Public
Repo size
3.3 GB
Likes
0
Public
Click a slice to open those files.
.pt3.3 GB · 100%
From the Hugging Face model README
Fine-tuned XLM-RoBERTa model for multilingual tourism comment sentiment analysis.
This model classifies tourism comments in 39 languages into 3 sentiment categories:
| Language | Count | Percentage |
|---|---|---|
| English (en) | 1,088 | 51.3% |
| Korean (ko) | 306 | 14.4% |
| Russian (ru) | 156 | 7.3% |
| German (de) | 98 | 4.6% |
| French (fr) | 59 | 2.8% |
| Italian (it) | 50 | 2.4% |
| Spanish (es) | 46 | 2.2% |
| Filipino (tl) | 32 | 1.5% |
| Indonesian (id) | 23 | 1.1% |
| Polish (pl) | 22 | 1.0% |
| Sentiment | Count | Percentage |
|---|---|---|
| Positive | 1,325 | 62.4% |
| Negative | 547 | 25.8% |
| Neutral | 251 | 11.8% |
| Metric | Score |
|---|---|
| Accuracy | 80.71% |
| F1 Macro | 66.00% |
| F1 Weighted | 79.48% |
| Sentiment | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| Positive | 89.67% | 91.70% | 90.67% | 265 |
| Neutral | 50.00% | 26.00% | 34.21% | 50 |
| Negative | 67.97% | 79.09% | 73.11% | 110 |
Predicted
pos neu neg
Actual pos 243 8 14
neu 10 13 27
neg 18 5 87
import torch
import torch.nn as nn
from transformers import AutoTokenizer, AutoModel
# Define model architecture
class XLMRobertaSentimentClassifier(nn.Module):
def __init__(self, n_classes=3, dropout=0.3):
super(XLMRobertaSentimentClassifier, self).__init__()
self.xlm_roberta = AutoModel.from_pretrained('xlm-roberta-base')
self.dropout = nn.Dropout(dropout)
self.classifier = nn.Linear(self.xlm_roberta.config.hidden_size, n_classes)
def forward(self, input_ids, attention_mask):
outputs = self.xlm_roberta(input_ids=input_ids, attention_mask=attention_mask)
pooled_output = outputs[0][:, 0, :]
pooled_output = self.dropout(pooled_output)
logits = self.classifier(pooled_output)
return logits
# Load model
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
tokenizer = AutoTokenizer.from_pretrained('xlm-roberta-base')
model = XLMRobertaSentimentClassifier(n_classes=3)
checkpoint = torch.load('xlm_sentiment_best_model.pt', map_location=device)
model.load_state_dict(checkpoint['model_state_dict'])
model = model.to(device)
model.eval()
# Predict (works with any language!)
text = "Beautiful beach, loved it!" # English
# text = "아름다운 해변이에요!" # Korean
# text = "Sehr schöner Strand!" # German
encoding = tokenizer(
text,
add_special_tokens=True,
max_length=256,
padding='max_length',
truncation=True,
return_attention_mask=True,
return_tensors='pt'
)
input_ids = encoding['input_ids'].to(device)
attention_mask = encoding['attention_mask'].to(device)
with torch.no_grad():
outputs = model(input_ids=input_ids, attention_mask=attention_mask)
probs = torch.softmax(outputs, dim=1)
confidence, predicted = torch.max(probs, dim=1)
sentiments = ['positive', 'neutral', 'negative']
print(f"Sentiment: {sentiments[predicted.item()]} ({confidence.item():.4f})")
# Output: Sentiment: positive (0.9981)
| Epoch | Train Loss | Train Acc | Val Loss | Val Acc | F1 Macro |
|---|---|---|---|---|---|
| 1 | 0.9240 | 59.25% | 0.6880 | 62.35% | 25.60% |
| 2 | 0.6837 | 73.14% | 0.5516 | 79.06% | 53.71% |
| 3 | 0.5876 | 77.68% | 0.5722 | 77.41% | 52.72% |
| 4 | 0.4880 | 81.33% | 0.5112 | 80.94% | 60.46% |
| 5 | 0.4056 | 83.80% | 0.5240 | 80.71% | 66.00% ⭐ |
🌍 39 Languages: English, Korean, Russian, German, French, Italian, Spanish, Filipino, Indonesian, Polish, Portuguese, Chinese, Dutch, Afrikaans, Thai, Arabic, Romanian, Czech, Japanese, Catalan, Danish, Somali, Hebrew, Finnish, Welsh, Ukrainian, Turkish, Slovak, Swedish, Croatian, Norwegian, Hungarian, Estonian, Albanian, Bulgarian, Swahili, Greek, Macedonian, and more!
✅ Truly Multilingual: Works with 39+ languages out of the box ✅ High Accuracy: 80.71% overall accuracy across all languages ✅ Zero-Shot Capability: Can handle new languages not in training set ✅ Production Ready: Used in real-world tourism monitoring system ✅ Fast Inference: ~80ms per comment on GPU
| Model | Languages | F1 Macro | Accuracy | Domain |
|---|---|---|---|---|
| XLM-RoBERTa Tourism | 39 | 66.00% | 80.71% | Tourism |
| mBERT Sentiment | 104 | 62.10% | 78.50% | General |
| XLM-R Base | 100 | 58.30% | 75.20% | General |
@misc{xlm-roberta-tourism-sentiment,
author = {Strawberry0604},
title = {XLM-RoBERTa Tourism Sentiment Classifier},
year = {2025},
publisher = {HuggingFace},
howpublished = {\url{https://huggingface.co/Strawberry0604/xlm-roberta-tourism-sentiment}}
}
Strawberry0604
For questions and feedback, please open an issue in the GitHub repository.