LLaMA-3.2-3B Fine-tuned for Multilingual Emotion Classification (English + Spanish)
This model is a fine-tuned version of meta-llama/Llama-3.2-3B for emotion classification on mixed English and Spanish text. It has been trained on a balanced dataset combining English and Spanish text examples from the SemEval 2025 emotion dataset, and it detects the presence of five key emotions in text: anger, fear, joy, sadness, and surprise.
Model Details
Model Description
This model classifies emotions in English and Spanish text. It outputs the probability of five emotions (anger, fear, joy, sadness, surprise) for each input sentence.
- Model type: Transformer-based (LLaMA architecture)
- Language(s): English, Spanish
- Finetuned from model:
meta-llama/Llama-3.2-3B - Finetuning method: LoRA via PEFT
Model Sources
Uses
Direct Use
This model can be used to classify the emotions in English or Spanish text. The model outputs probabilities for five emotions, with higher values indicating stronger predictions.
Out-of-Scope Use
This model is not suitable for non-English/Spanish text or highly specific emotion subcategories beyond the five target labels.
Bias, Risks, and Limitations
This model may misclassify emotions in texts with sarcasm, irony, or cultural nuances not well represented in the training data. The model also has limitations when applied to texts outside of the SemEval dataset's domain or with very different language styles (e.g., formal vs. informal).
How to Get Started with the Model
You can load the model using the PEFT and transformers libraries:
from transformers import AutoTokenizer, AutoModelForSequenceClassification
from peft import PeftModel
import torch
# Paths / model name on Hugging Face
model_id = "gsi-upm/llama-3b-emotion-classifier-eng-esp"
base_model_name = "meta-llama/Llama-3.2-3B"
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_id)
tokenizer.padding_side = "left"
tokenizer.pad_token = tokenizer.pad_token or tokenizer.eos_token
# Load base model
base_model = AutoModelForSequenceClassification.from_pretrained(
base_model_name,
num_labels=5,
problem_type="multi_label_classification",
)
# Load LoRA adapter
model = PeftModel.from_pretrained(base_model, model_id)
model.config.problem_type = "multi_label_classification"
model.config.use_cache = False
device = "cuda" if torch.cuda.is_available() else "cpu"
model.to(device)
model.eval()
# Input text (English or Spanish)
text = "I am thrilled about the results, but also a bit nervous."
# Tokenize the input
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
inputs = {k: v.to(device) for k, v in inputs.items()}
# Predict emotions
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.sigmoid(logits)
# Display results
labels = ['anger', 'fear', 'joy', 'sadness', 'surprise']
results = {label: float(prob) for label, prob in zip(labels, probs[0])}
print(results)
You can also convert probabilities into binary labels using a threshold (e.g., 0.5):
predictions = (probs > 0.5).int()
print(predictions)
Output Format
The model outputs a dictionary of emotion probabilities:
{
'anger': 0.02,
'fear': 0.10,
'joy': 0.91,
'sadness': 0.05,
'surprise': 0.23
}
Training Details
Training Data
The model was trained on a balanced dataset based on the SemEval 2025 dataset (English and Spanish text with labeled emotions).
The training data was mixed at 50% English and 50% Spanish examples.
- Labels: anger, fear, joy, sadness, surprise
Evaluation
The model was evaluated on held-out test sets for both English and Spanish using accuracy, precision, recall, and F1-score. Results may vary depending on the specific bias/alpha configuration used during training.
English Results
- Eval loss: 0.4556
- Micro F1-score: 0.7564
- Macro F1-score: 0.7163
- Weighted F1-score: 0.7540
- Precision: 0.7627
- Recall: 0.6785
- Exact match ratio: 0.4585
- Alpha: 0.5
Spanish Results
- Eval loss: 0.2789
- Micro F1-score: 0.8186
- Macro F1-score: 0.8223
- Weighted F1-score: 0.8172
- Precision: 0.8586
- Recall: 0.7940
- Exact match ratio: 0.7000
- Alpha: 0.5
Citation
If you use this model, please cite the following:
BibTeX:
@misc{llama-multilingual-emotion-classifier,
author = {Adrián Maldonado Robles},
title = {LLaMA-3.2-3B Fine-tuned for Multilingual Emotion Classification},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/gsi-upm/llama-3b-emotion-classifier-eng-esp}
}
Model Card Contact
For questions or inquiries, please contact [adrian.maldonado@alumnos.upm.es].
Framework versions
- PEFT: 0.14.0
Model tree for gsi-upm/llama-3b-emotion-classifier-eng-esp
Base model
meta-llama/Llama-3.2-3B