FINE-GRAINED EMOTION DETECTION USING NLP-BASED TRANSFORMER MODELS: A COMPARATIVE STUDY OF BERT AND ROBERTA FOR MULTI-CLASS TEXT CLASSIFICATION

Authors

  • Shujaat Ali Shariati MS Data Science (2025–2027), Department of Computer Science Bahauddin Zakariya University, Multan, Pakistan

Abstract

The ability to detect emotions from text is a key NLP task that is applicable to a wide range of fields, including mental health analytics, HCI, customer experience analytics, and social media intelligence. However, the task of fine-grained multi-class emotion classification, which involves 27 different emotion classes, is still an open and challenging research problem, whereas binary sentiment analysis has matured. We systematically compare BERT-base-uncased and RoBERTa-base on the GoEmotions dataset, consisting of 58,009 human-annotated Reddit comments from 28 emotion categories. We use three optimization techniques: (1) focal loss and inverse-frequency class weighting to cope with severe class imbalance; (2) per-class threshold tuning on the validation set to maximize macro-F1; and (3) cosine learning rate scheduling with warmup. We get a macro-F1 score of 0.5227 for our BERT model, which is better than the best BERT baseline reported in previous literature (0.49). RoBERTa achieves a macro-F1 of 0.5213 with a micro-F1 of 0.5909. These two models perform significantly better than the TF-IDF + Logistic Regression baseline (macro-F1 = 0.1967). We also show that per-class threshold optimization consistently improves BERT's and RoBERTa's performance by +0.0462 and +0.0293, respectively. Dominant emotions (e.g., gratitude, F1 = 0.91; amusement, F1 = 0.83) can be learned reliably in contrast to rare emotions (e.g., realization, F1 = 0.22; relief, F1 = 0.33). By identifying reproducible benchmarks and practical deployment guidance for fine-grained emotion classifications in resource-constrained environments, our results can inform future research and practical applications.Our results offer reproducible benchmarks and practical deployment guidance for fine-grained emotion classifications in resource-constrained environments, which can guide future research and practical applications.

Keywords: Emotion Detection, Natural Language Processing, BERT, RoBERTa, Multi-Class Text Classification, GoEmotions, Transformer Models, Focal Loss, Threshold Optimization, Transfer Learning

Downloads

Published

2026-05-29

How to Cite

Shujaat Ali Shariati. (2026). FINE-GRAINED EMOTION DETECTION USING NLP-BASED TRANSFORMER MODELS: A COMPARATIVE STUDY OF BERT AND ROBERTA FOR MULTI-CLASS TEXT CLASSIFICATION. Spectrum of Engineering Sciences, 4(5), 2923–2931. Retrieved from https://thesesjournal.com/index.php/1/article/view/3093