anpmts's picture
Upload sentiment classifier model
c27cd1b verified
---
language: multilingual
license: apache-2.0
tags:
- sentiment-analysis
- text-classification
- xlm-roberta
- dual-head
---
# Sentiment Classifier
## Model Description
This is a dual-head sentiment classifier built on top of XLM-RoBERTa. The model performs two tasks simultaneously:
1. **Sentiment Classification:** Predicts sentiment labels (positive, neutral, negative)
2. **Sentiment Score Regression:** Predicts a continuous sentiment score in the range [0, 1]
The model uses a weighted loss function combining cross-entropy (70%) for classification and MSE (30%) for regression,
allowing it to capture both discrete sentiment categories and fine-grained sentiment intensity.
## Model Architecture
- **Base Model:** xlm-roberta-base
- **Task:** text-classification
- **Number of Labels:** 3
- **Labels:** negative, neutral, positive
## Training Configuration
- **Epochs:** 10
- **Batch Size:** 128
- **Learning Rate:** 2e-05
- **Warmup Ratio:** 0.1
- **Weight Decay:** 0.01
- **Max Seq Length:** 256
- **Mixed Precision:** FP16=False, BF16=True
## Performance Metrics
- **Loss:** 0.6947
- **Accuracy:** 0.4901
- **Precision:** 0.2402
- **Recall:** 0.4901
- **F1:** 0.3224
- **F1 Macro:** 0.3289
- **F1 Negative:** 0.0000
- **Precision Negative:** 0.0000
- **Recall Negative:** 0.0000
- **Support Negative:** 900
- **F1 Neutral:** 0.6578
- **Precision Neutral:** 0.4901
- **Recall Neutral:** 1.0000
- **Support Neutral:** 865
- **Runtime:** 0.7012
- **Samples Per Second:** 2517.1350
- **Steps Per Second:** 9.9830
## Model Outputs
The model returns two outputs:
- **Logits:** Classification logits for sentiment labels [batch_size, 3]
- **Score Predictions:** Continuous sentiment scores [batch_size]
Both outputs are computed from the same shared representation (CLS token) of the input text.
## Intended Use
This model is intended for sentiment analysis tasks on multilingual text, particularly in scenarios where both
categorical sentiment (positive/neutral/negative) and sentiment intensity are important.
**Typical use cases:**
- Product review analysis
- Social media sentiment monitoring
- Customer feedback classification
## Usage
```python
from transformers import AutoTokenizer
from src.models.sentiment_classifier import SentimentClassifier
# Load model and tokenizer
model = SentimentClassifier.from_pretrained("YOUR_USERNAME/sentiment-classifier")
tokenizer = AutoTokenizer.from_pretrained("xlm-roberta-base")
# Prepare input
text = "Your input text here"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
# Make prediction
outputs = model(**inputs)
predictions = outputs["logits"].argmax(dim=-1)
```
## Citation
If you use this model, please cite:
```bibtex
@misc{sentiment_classifier,
title={Sentiment Classifier},
author={{Your Name}},
year={2025},
publisher={Hugging Face},
howpublished={{\url{{https://huggingface.co/YOUR_USERNAME/{model_name.lower().replace(' ', '-')}}}}}
}
```
---
*This model card was automatically generated with [Claude Code](https://claude.com/claude-code)*