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:
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2from peft import PeftModel
3import torch
4
5# Paths / model name on Hugging Face
6model_id = "gsi-upm/llama-3b-emotion-classifier-eng-esp"
7base_model_name = "meta-llama/Llama-3.2-3B"
8
9# Load tokenizer
10tokenizer = AutoTokenizer.from_pretrained(model_id)
11tokenizer.padding_side = "left"
12tokenizer.pad_token = tokenizer.pad_token or tokenizer.eos_token
13
14# Load base model
15base_model = AutoModelForSequenceClassification.from_pretrained(
16 base_model_name,
17 num_labels=5,
18 problem_type="multi_label_classification",
19)
20
21# Load LoRA adapter
22model = PeftModel.from_pretrained(base_model, model_id)
23model.config.problem_type = "multi_label_classification"
24model.config.use_cache = False
25
26device = "cuda" if torch.cuda.is_available() else "cpu"
27model.to(device)
28model.eval()
29
30# Input text (English or Spanish)
31text = "I am thrilled about the results, but also a bit nervous."
32
33# Tokenize the input
34inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
35inputs = {k: v.to(device) for k, v in inputs.items()}
36
37# Predict emotions
38with torch.no_grad():
39 logits = model(**inputs).logits
40 probs = torch.sigmoid(logits)
41
42# Display results
43labels = ['anger', 'fear', 'joy', 'sadness', 'surprise']
44results = {label: float(prob) for label, prob in zip(labels, probs[0])}
45print(results)
You can also convert probabilities into binary labels using a threshold (e.g., 0.5):
1predictions = (probs > 0.5).int()
2print(predictions)
Output Format
The model outputs a dictionary of emotion probabilities:
1{
2 'anger': 0.02,
3 'fear': 0.10,
4 'joy': 0.91,
5 'sadness': 0.05,
6 'surprise': 0.23
7}
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:
1@misc{llama-multilingual-emotion-classifier,
2 author = {Adrián Maldonado Robles},
3 title = {LLaMA-3.2-3B Fine-tuned for Multilingual Emotion Classification},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/gsi-upm/llama-3b-emotion-classifier-eng-esp}
7}
Model Card Contact
For questions or inquiries, please contact [
adrian.maldonado@alumnos.upm.es].
Framework versions