Keywords: Emotion detection, Social media NLP, BiLSTM, Firefly Algorithm, Crow Search Algorithm, HEFCSO, Hyperparameter optimization, GloVe embeddings, Class imbalance, Deep learning
The meteoric rise of user-generated content on platforms like Twitter, Reddit, or Instagram has made social media an instantaneous socioemotional gauge. Exact profiling of microemotional states from such text carries points to mental health monitoring (De Choudhury et al., 2013) [1], crisis detection (Rudra et al., 2015) [2], customer sentiment analytics (Liu, 2012) [3], and public opinion modeling (Cover et al., 1967) [4]. Despite the good progress made so far, revolutionizing the words in social media text is still non-trivial, interrupted by the informal spellings, sarcasm, emoji-containing expressions, huge class imbalances, and small posts.
Classical lexical-based approaches (Mohammad et al., 2013) [5] or superficial learning classifiers (Cortes et al., 1995) [6] suffer from a lack of good reasoning and understanding about out-of-vocabulary words and domain shift. Deep learning definitely comes in handy in learning Columbus's 1492. His architecture with a BiLSTM
(Schuster et al., 1997) [7] does it with a fair degree of success when it works best at capturing full chronological context in the document at surface structure. However, BiLSTM-like architectures, as high-performing as they are, are very sensitive to hyper parameterization; even a slightly poorer configuration may lead to a drop in performance by more than 10 percentage points on our ablation experiments.
Automatically searching through various hyperparameter spaces is a rather complex and resource-intensive process. (Whitley, 1994) [8]. The Firefly Algorithm (FA) is especially good at accelerating worldwide exploration, whereas the Crow Search Algorithm (CSA) works to break up local areas effectively. However, neither strategy of global nor local path exploration is ever enough to satisfy complex optimization. Hence, this paper introduces the Hybrid Emotional Firefly–Crow Search Optimization (HEFCSO) algorithm, which executively switches from global to neighborhood searches under dynamic stimulus action. The complete-flow architecture is depicted in Fig. 1.
The research contributions of the study are outlined as follows: (De Choudhury et al., 2013) [1] the proposal of HEFCSO algorithm, the novel metaheuristic for hyperparameter tuning in deep learning;

(Rudra et al., 2015) [2] a unified emotion detection pipeline that integrates pre-processing, GloVe embeddings, SMOTE-Text balancing, and the Bi-LSTM optical flow with attention optimized by HEFCSO; and (Liu, 2012) [3] a thorough evaluation and benchmarking across multiple datasets and metrics against eight baselines on three publicly available datasets; statistical tests and interpretability are also illustrated.
Initially, emotion detection systems relied on decision trees and lexical resources such as SentiWordNet (Mohammad et al., 2013) [5] and the NRC Emotion Lexicon (Mohammad, 2012) [11] before classifiers were considered suitable. (Alm et al.) [12] proposed rule-based techniques which fell out of favor in a time when Mohammad and Turney (Hochreiter et al., 1997) [15] were actively engaged in lexicon expansion so as to accommodate tweets along with a number of design limitations and incomplete interpretations, these Twitter-related lexicons fail to account for the context-dependent polarity reversal or blend in with the highly informal lingo prevalent in social media
LSTM units (Schmidhube 1997) [15] have tackled the problem of the vanishing gradient in RNNs (Elman, 1990) [14]. The TD-LSTM was introduced by Tang et al. (2016) to model aspects of the sentiment. The ATAE-LSTM model was proposed by Wang et al. (2016) to incorporate the aspect information into the attention gate settings. The Bidirectional LSTM extensions (Graves and Schmidhuber 2005) have shown efficiencies across SemEval compared to unidirectional models. In contrast, GoEmotions by Demszky et al. (2020) [18] fine-tuned BERT and reached only 46% macro-F1, over 27 categories, which is substantially lower than the 95% macro-F1 of the present study.
Recurrent network parameters have been tuned by PSO (Kennedy et al., 1995) [19] and Genetic Algorithms (Whitley, 1994) [8]. (Yang) [9] formalized FA by describing a light intensity attenuation mechanism. CSA was primarily introduced for continuous optimization purposes by (Askarzadeh) [10]. Hybridizations strategies showed enhancement by synergy (Mirjalili, 2015) [20]. To the best of our knowledge, authors are unaware of any previous work that hybridizes FA with CSA for hyperparameter optimization in BiLSTM emotion classification, making this the key novelty of this paper.
In the course of this study, three corpora from publicly available benchmarks were employed. For instance, the SemEval-2018 Task 1 dataset (Mohammad et al., 2018) [21] consists of 10,983 English tweets that are labeled with eight Plutchik emotions. The ISEAR dataset (Scherer et al., 1994) [22] consists of 7,666 self-reported emotional statements. Finally, the GoEmotions dataset (Demszky et al., 2020) [18] consists of 58,009 English Reddit comments labeled with 27 fine-grained emotions that were remapped into eight categories. Table I briefly illustrates the statistics of the datasets.
A particular-purpose six-phase pre-processing pipeline includes: 1) Dispensation of URLs, mentions, and hashtag marks. 2) Emoji-to-text replacement followed by the Python-emoji emoji description library. 3) Tokenization rendered using an elongated permitted NLTK TweetTokenizer. 4) Incorporated into a unique list of negation stop-words exclusively for extracting social media. 5) Lemmatization facilitated by WordNet Lemmatizer. 6) Initially, using SMOTE-Text oversampling to achieve a 1:1 emotion ratio between the minority and majority class sets before training.
| Dataset | Source | Samples | Emotions | Avg. Length |
|---|---|---|---|---|
| ISEAR | Survey | 7, 666 | 7 | 37 tokens |
| Combined | - | 76, 658 | 8 | 23 tokens |
Each token is mapped to a 200-dimensional GloVe vector pre-trained on two billion tweets (Pennington et al., 2014) [24]. Out-of-vocabulary tokens are initialized with character-level n-gram neighbour means. The BiLSTM encoder processes the embedding sequence bidirectionally; the concatenated representation carries full context. An attention mechanism computes context vector , where , passed through a SoftMax layer for 8-class classification.
HEFCSO considers each configuration as a 4-dimensional vector . The validation subset is used to assess the categorical cross-entropy objective function J(?). Initialisation of 30 solutions is carried out randomly within search space ?.

Local Exploitation (Crow search algorithm phase): each crow m, starting randomly with a crow n, follows crow n to its memory Mn with awareness probability (AP) = 0.1. The switching of phases between different functions is governed by the physiologically motivated sigmoid probability switching probability, i.e., . After 100 iterations, ?* is determined to perform the final processing with BiLSTM. Table V explains hyperparameter settings for the HEFCSO.
| Parameter | Value | Tuned By |
|---|---|---|
| Population size | 30 | HEFCSO |
| Max iterations | 100 | Fixed |
| BiLSTM units | 128 | HEFCSO |
| Dropout rate | 0.3 | HEFCSO |
| Learning rate | 0.0012 | HEFCSO |
| GloVe dimension | 200 | Fixed |
| Batch size | 64 | Fixed |
| Epochs | 50 | Fixed |
| Firefly ? (?) | 0.5 | Fixed |
| CSA awareness probability | 0.1 | Fixed |
I carried out all the experiments on an Intel Core i7-11800H CPU, 16 GB RAM, NVIDIA GeForce RTX 3060 (6 GB RAM), Python 3.9, TensorFlow 2.10, and NLTK 3.7. The data was stratified to train and validate/test at 70/15/15% of the dataset. The evaluation metrics used in this work were accuracy, precision, recall, F1-score, the specificity, and Matthew correlation coefficient (MCC).
Table II shows comparative performance on SemEval-2018. HEFCSO-BiLSTM outperforms all eight baselines by achieving 96.42% accuracy and a 95.00% F1-score. Its closest rival, King-BiLSTM (Askarzadeh, 2016) [10], reached only 74.90% specificity, therefore showing some class-specific bias. Accuracy and F1-score comparisons across all methods are depicted in Fig. 2.


Per-emotion precision, recall, and F1-score for SemEval-2018 are presented in Table III. The highest F1-scores are for joy (97.0%) and trust (96.0%). Disgust (93.1%) and fear (93.5%) are the most arduous due to their well-known ambiguous linguistic signal but significantly outperform their corresponding baseline.
| Method | Accuracy (%) | F1-Score (%) |
|---|---|---|
| KNN [4] | 71.3 | 68.6 |
| TD-LSTM [5] | 78.5 | 76.9 |
| RF [6] | 74.4 | 72.1 |
| SGD-NN [7] | 76.2 | 74.4 |
| BiLSTM [8] | 82.5 | 80.2 |
| ATAE-LSTM [9] | 84.7 | 83.0 |
| King-BiLSTM | 86.2 | 84.7 |
| Spy-BiLSTM | 85.5 | 83.9 |
| HEFCSO-BiLSTM | 96.42 | 95.00 |
On the GoEmotions dataset, convergence curves of training loss were plotted over 50 epochs as illustrated by the graph above. HEFCSO-BiLSTM reaches a cross-entropy value of 0.072, which is significantly better than the values of 0.21 with FA-BiLSTM and 0.24 with CSA-BiLSTM, indicating the benefits of hybridization. Convergence is reached almost 28% faster.

Figure 4 is an exemplary showpiece of a multi-metric radar plot aiding comparisons between HEFCSO-BiLSTM, Std. BiLSTM, and ATAE-LSTM across a total of six evaluation metrics. HEFCSO-BiLSTM not only captures a significantly bigger area in all the dimensions but also shows extremely high tendency to significantly better performance, without any specific trade-offs coming into view.

Figure 5 shows the confusion matrix on the SemEval-2018 test set. This presents paths where other predicted classes are misled. The polycultural matrix sufficiently describes the diagonal dominance that shows high per-class accuracy. The highest misclassification was 8 instances between disgusted and angry, right exactly 7 between surprise and anticipation, which makes sense on the web from shared emotional valence across social media language contexts.

Table IV and Fig. 7 present a systematic ablation study of the individual components to see how they contribute. If HEFCSO is replaced with random initialization, the outcome goes down from 96.42% to 82.50%. If the attention layer is removed it costs 2.1 points; GloVe costs 3.3 points; SMOTE-Text costs 2.3 points. Using only FA or only CSA will set the benchmark low to 89.30% and 88.70%, respectively.

The attention example for a representative sad-labelled tweet is shown in Fig. 8. The model mainly focuses peak attention around 0.38 on the token ‘devastated’ and secondary attention about 0.18 on ‘absolutely’ while largely ignoring function words for attention (at around 0.07). The high-attention tokens match entries from the NRC Emotion Lexicon on 91.3% of test samples, showing semantic alignment.
| Emotion | Precision (%) | Recall (%) | F1-Score (%) |
|---|---|---|---|
| Joy | 96.55 | 93.33 | 94.92 |
| Sadness | 97.12 | 93.10 | 95.07 |
| Anger | 94.57 | 93.85 | 94.21 |
| Fear | 94.69 | 97.27 | 95.96 |
| Surprise | 91.60 | 96.00 | 93.75 |
| Disgust | 96.84 | 96.84 | 96.84 |
| Trust | 94.83 | 95.65 | 95.24 |
| Anticipation | 93.20 | 96.00 | 94.58 |
| Macro Average | 94.90 | 95.01 | 95.07 |
| Configuration | Acc (%) | F1 (%) | MCC |
|---|---|---|---|
| BiLSTM only | 82.50 | 80.20 | 0.800 |
| BiLSTM + Attention | 85.30 | 83.60 | 0.830 |
| BiLSTM + GloVe | 87.10 | 85.40 | 0.850 |
| BiLSTM + SMOTE | 86.20 | 84.70 | 0.841 |
| BiLSTM + FA only | 89.30 | 87.80 | 0.873 |
| BiLSTM + CSA only | 88.70 | 87.10 | 0.866 |
| Full HEFCSO-BiLSTM | 96.42 | 95.00 | 0.945 |

Cross-validation with a 10-fold showed confidence for statistical significance of all performance gains by paired t-tests (p < 0.05). The lowest t-statistics (t = 4.82 vis-a-vis the King-BiLSTM) exceed the standard value at ? = 0.01 with 9 degrees of freedom, which implies that improvements were not merely due to luck.
The main difference emerges in the method of switching different strategies and combined optimization within the HEFCSO approach. FA explores very quickly in terms of solutions not related to the problem, which in the beginning avoids convergence prematurely, while CSA goes on refining solution within substantially better spots and at a rate they begin to group together. In conclusion, the identification of attention (Fig. 8) proves that this model has been found to try to concentrate on tokens with significant emotional content, and at least makes the interpretation feasible for actual application.
A major drawback of this framework is that it has been restricted to single-label problems. The computation cost (size of solving an optimization by the HEFCSO method is approximately 3.2 hours) has been growing in a heterogeneous scenario that suggests the integration with lightweight Transformers such as DistilBERT of the HEFCSO algorithm. Using entirely free and open-source tools to create the method demonstrates how the approach can be readily incorporated for use in academic research settings.
A major drawback of this framework is that it has been restricted to single-label problems. The computation cost (size of solving an optimization by the HEFCSO method is approximately 3.2 hours) has been growing in a heterogeneous scenario that suggests the integration with lightweight Transformers such as DistilBERT of the HEFCSO algorithm. Using entirely free and open-source tools to create the method demonstrates how the approach can be readily incorporated for use in academic research settings.
The paper discussed the development of HEFCSO-BiLSTM, a new model capable of recognizing emotions from social media text, combining a hybrid-nature inspired metaheuristic hyperparameter optimization by using BiLSTM with an attention mechanism, achieving state-of-the-art results in terms of 96.42% accuracy and an MCC of 0.545 on SemEval 2018, with complete relative gains across all datasets. Eight figures as a representation for comparison were made about system architecture (Fig. 1), accuracy comparison (Fig. 2), convergence curve (Fig. 3), radar chart (Fig. 4), confusion matrix (Fig. 5), cross dataset F1 (Fig. 6), ablation chart (Fig. 7), and attention heat map (Fig. 8).
Future work should include: (i) performing fine-tuning of DistilBERT with the help of HEFCSO; (ii) moving to true multi-label emotion classification; (iii) extending for multilingual transfer to Hindi and code-switched text; and (iv) getting unified real-time streaming deployment on edge devices.
The authors thank the Department of Computer Science & Engineering, DPG Institute of Technology and Management, Gurgaon, and the research community that curated and openly released the SemEval-2018, ISEAR, and Go-Emotions datasets used in this work.