How to Fine-Tune an SLM for Emotion Recognition

· Source: Towards Data Science · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Data Science & Analytics, Natural Language Processing · Depth: Intermediate, medium

Summary

A new fine-tuned small language model, MistralSmall-3.1.GoEmotions, has been released on Hugging Face under the Apache 2.0 license, designed for detailed emotion recognition. This model extends traditional sentiment analysis by assigning probabilities across 27 distinct emotion categories, such as "anger" and "disappointment", from text. Developed to address the significant class imbalance in the 58k-entry GoEmotions dataset, particularly the prevalence of "neutral" labels, the fine-tuning process employed a three-pronged strategy. This involved undersampling majority classes, synthetically expanding minority emotion categories using the 2025 ISMOTE algorithm, and implementing a weighted focal loss function. The fine-tuning of Mistral Small-3.1-24B-Instruct-2503, utilizing the Unsloth framework and LoRA, took 9 hours and 30 minutes on an NVIDIA RTX 6000 GPU. The resulting model achieved F1 scores exceeding 0.7 for most target emotions.

Key takeaway

For AI Engineers developing fine-grained emotion recognition models, you must prioritize robust data preprocessing to counter class imbalance. Implement a strategy combining undersampling, synthetic data generation like ISMOTE, and weighted focal loss during fine-tuning. This method, proven with Mistral Small, improves performance on minority emotion categories. It enables more accurate analysis for customer support or brand monitoring.

Key insights

Fine-tuning SLMs for fine-grained emotion recognition on imbalanced datasets requires a multi-technique approach to data balancing and loss weighting.

Principles

Method

Address class imbalance by undersampling majority classes, synthetically expanding minority classes with ISMOTE, and applying a weighted focal loss function during LoRA fine-tuning with Unsloth.

In practice

Topics

Code references

Best for: Machine Learning Engineer, NLP Engineer, AI Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by Towards Data Science.