Skip to main content
MethodsX logoLink to MethodsX
. 2025 Dec 11;16:103756. doi: 10.1016/j.mex.2025.103756

AI-powered mental health application with data privacy preservation

Pooja Bagane a,, Anushree Dahiya a, Shardul Kacheria a, Ansh Sehgal a, Shrishti Bajpai a, Obsa Amenu Jebessa b
PMCID: PMC12775963  PMID: 41509187

Abstract

Anxiety disorders, emotional conditions, and stress are becoming an increasing tendency in modern society, which makes digital mental health technologies that provide support in these cases highly demanded. This paper focuses on proposing an AI-driven framework that combines Natural Language Processing (NLP) with privacy-protective systems to recognize emotions in the text of the user. The AES-256 encryption, Supabase authentication, and role-based access control are used to secure data security. It is presented as a multi-label problem of emotion classification, which is fine-tuned on the BERT-base-uncased and ModernBERT Large transformer. ModernBERT exhibited rapid convergence and enhanced situational sensitivity especially when it comes to sarcasm and mixed emotional states.

Key contributions include:

  • Planning an emotion feedback loop offering contextual response and customized mindfulness teaching.

  • Performing a Class imbalance analysis of emotions and trade-offs in precision and recall.

  • Illustrating privacy-first architecture that is able to integrate with digital-therapy and clinician assisted decision software.

Keywords: Mental health, Emotion detection, Natural language processing (NLP), BERT-base-uncased, ModernBERT large, GoEmotions dataset, Multi-label classification, Binary cross entropy (BCE) loss, Anonymous communication, Mindfulness exercises, Supabase, React, TailwindCSS, Secure data handling

Graphical abstract

Image, graphical abstract

Specifications table

Subject area Computer Science
More specific subject area Artificial Intelligence
Name of your method BERT-base-uncased, ModernBERT Large
Name and reference of original method None
Resource availability None

Background

Modern living, augmented digital dependency, and socialization have become significant sources of emotional discomfort and the emerging issues of psychological concern across the globe. Even with the increasing awareness, stigma towards professional assistance and privacy issues usually dishearten people to get treatment or share their feelings. This highlights the necessity of safe, anonymous online communities where people could receive mental -health care without loss of confidentiality.

The most critical aspect of it is Artificial Intelligence (AI), especially its Natural Language Processing (NLP) applications. NLP provides machines with the ability to recognize human emotion patterns. Transformer-based systems like BERT have been particularly beneficial to digital mental-health tasks, where the system needs to be aware of sub-communication like sarcasm, confusion, distress, etc., to respond appropriately. The privacy of users is ensured, unauthorised access is avoided, and the user trust is retained by AES-256 encryption and role-based authentication.

This paper designs a privacy-conscious emotion sensitive AI model that is trained on GoEmotions dataset of 58,000 posts on Reddit categorized in 27 fine-grained emotions. Subtle categories like embarrassment, grief, curiosity and sarcasm are contained in the dataset, which is suitable in real-life emotion detection. We test two models of transformers, namely BERT-base-uncased (medium-weight, efficient) and ModernBERT Large (deeper contextual knowledge), to compare their suitability to be used in the context of emotion detection, which may be applied in mental-health scenarios.

Even AI-based mental-care chatbots like Wysa [1] and Woebot [2] and Youper [3], though, are mostly based on rule-based or shallow NLP, which means that they are less successful at perceiving the presence of implicit emotional cues, or that they are not completely user-anonymous. The need to improve and improve accuracy of emotion-recognition and privacy is thus a step in a crucial direction in the development of digital well-being tools.

The solution proposed combines real time affect sensing, mindfulness coaching, journaling prompts, breathing exercise recommendations in the form of a privacy preserving architecture. It further develops AI of emotions sensitivity and ethical data processing. The best trade-off between the accuracy, speed, and ethical design of the BERT models is presented by our comparative analysis that shows the possibility to integrate into digital-therapy systems or clinician-guided decision-support systems.

Method details

The proposed system assesses the emotions that are extracted in informal written input by users to be used to evaluate mental health and provide early intervention support. Deep learning transformer models reach their objectives by receiving labeled emotion data training. The system includes safeguarding mechanisms which defend user privacy throughout each process. As shown in Fig. 1, our methodology consists of four main phases for the system development: Dataset Preparation, Preprocessing, Model Selection and Fine-tuning along with Evaluation.

Fig. 1.

Fig 1

Workflow of the proposed system — illustrates the sequential process of data preprocessing, model training, inference, and privacy modules ensuring AES-256 encryption and user anonymity at every stage.

Related tools and gaps

Different online platforms have now emerged to guide individuals in managing stress, emotional health, and anxiety levels with the aim of managing such aspects due to the growing awareness of mental health. The platforms make use of AI together with chatbots and therapeutic CBT protocols to provide support services for large groups of users. Existing solutions have various shortcomings when it comes to user-specific support, deep emotion understanding and secure handling of user data.

Table 1 highlights that while most existing applications employ AI for wellness, their privacy implementations vary widely. None combine deep NLP-based emotion detection with strict encryption and anonymity as proposed in this study.

Table 1.

International applications that can be used to enhance emotional and psychological well-being.

App Name Features Limitations Encryption / Privacy Support
Wysa [1] The application offers AI-driven CBT chatbot, mood tracking, self-care exercises, access to human therapists It provides restrictions that help with complicated cases, yet fails to function as a comprehensive therapy solution Yes (End-to-End Encryption)
Youper [3] The mental wellness application provides AI therapy with CBT, ACT, DBT, mood tracking, and mindfulness exercises as its main features. No integration of human therapists, not suitable in extreme cases Yes (HIPAA compliant)
Woebot [2] The application provides an AI chatbot for CBT, regular mood tracking, and providing with mental health education No human therapist option, lacks specialization Partial (SSL only)
Mindspa [4] Articles, mood tracking, therapy courses, sound therapy, and emergency AI chatbot support Rich in features, but the AI chatbot is reserved for emergency use only Unspecified
Earkick [5] It is a real-time mental health tracking tool that performs alongside AI assistance to support users who deal with anxiety and stress Doesn’t extend support to depression, stress, or trauma; no therapist involvement included Unspecified
Clare & Me [6] Users can access a WhatsApp AI chatbot for 24-hour communication, together with therapeutic strategies and sessions which provide similar mental health treatment Communication style becomes tiring in longer sessions Yes (End-to-End Encryption)

Although these platforms constitute innovative solutions, they usually do not provide real-time emotion analysis through NLP-based methods and individual crisis advice in the process of guaranteeing complete anonymity of expression of emotions. Users experience privacy risks because of NLP's limited capability to evaluate emotional context while performing emotional analysis. An enhanced intelligent mental health solution can be achieved by implementing advanced AI/NLP emotion analysis methods with customised mindfulness exercises that follow privacy-first specifications. Our solution, in contrast to existing platforms, ensures that communication is entirely anonymized, and offers real-time emotion analysis, which will solve the important gaps in privacy and personalization that exist in the current use of digital mental health solutions.

Artificial Intelligence (AI) applications have advanced rapidly in mental health due to their capacity to address stigma-related problems and improve care accessibility while creating individualized therapy methods. Studies have analyzed smart AI agents to determine their adaptability as clinical tools for depression care programs, anxiety disorders, and addiction treatment. Alanzi et al. [7] found that Generation Y and Generation Z users had positive reactions toward AI mental health chatbots, yet they expressed worry about both privacy and reliability. According to Khalid et al. [8], AI mental health tools need End-to-End Encryption (E2EE) and Multi-Factor Authentication (MFA), together with blockchain-based encryption, since standard methods are inadequate.

The research team composed of Djalo and Alonso (2022) [9] designed KAI as an AI-based chatbot that extends mental health therapy assistance via conversation while promoting emotional well-being and easing mental health professional work operations. The healthcare sector gains its advantages in two distinct manners showcased by these research studies that analyze security platforms and therapeutic services.

The study by Shoghli et al. [10] highlights that healthcare AI ethics encompass three domains: discrimination in data sources, patient authorization processes, and established technical standards of system management. The authors proposed adopting federated learning systems together with transparent AI models to address security risks.

Balcombe and De Leo [11] researched how deep learning could be applied to predictive analytics in substance abuse therapy among patients with complex psychiatric disorders, but their study revealed obstacles in creating personalized interventions and identified dependency issues regarding AI systems.​​ A customized AI assistant that relied on NLP combined with GNNs and reinforcement learning elements was described by Sharma et al. [12] but the paper also emphasized unsolved problems in personalized analytics.

Several studies point out multiple ethical issues that emerge from utilizing AI technology to support mental healthcare. The users' failure to recognize AI chatbots as unlicensed professionals creates ethical problems, requiring users to better understand the technology while developers must improve system transparency. Recent publications by Elsevier [13] revealed that XAI and federated learning are the tools needed to deal with hallucinations, explainability issues, and regulatory compliance.

Adiningrum et al. [14] researched character-based AI personas which assist in suicidal emergencies, yet pointed out that only qualified professionals can address these situations since AI is not a substitute for human intervention. The tools Woebot, Wysa and Replika function as psychological assistance platforms which remove obstacles for people in rural areas to reach mental health services because these platforms provide confidential support, according to Kettle and Lee [15].

KAI chatbot developed by González and Pérez [16] utilized text classification for CBT delivery, although they encountered obstacles while building both top-quality datasets and deep therapeutic relationships.​ AI mental health programs introduce large-scale methods which deliver fresh ways for emotional assistance. The present solutions fall short of delivering real-time customization features along with total encryption methods which permit users to convey themselves securely through unrestricted communication.

This project works to resolve the noted gaps by bringing together an AI platform which unites sentiment-aware NLP with mood tracking technology together with anonymous ranting capabilities that operate under end-to-end encryption methods.

The current AI mental health applications which are available for public use encounter multiple difficulties regarding their ability to conduct real-time emotional analysis coupled with personalized guidance and user encryption to establish full anonymity. The present user limitations prevent individuals from expressing their feelings securely and obtaining proper intervention strategies. The current platforms fall short of necessary ethical factors and therapeutic bonds along with reliability and so they cannot effectively help during crisis moments or emotional distress.

To address the existing gaps in technology, a secure, ethical, and privacy-preserving mental-health AI assistant will have to be developed. The proposed solution will involve sentiment-sensitive NLP and mood-tracking features plus anonymous ranting functionalities, which can be conducted on the basis of the end-to-end encryption.

Combining these elements, the system will not only solve the privacy and personalization issues but will also provide the basis of integrating into digital-therapy ecosystems and clinician-assisted decision-support systems, to improve the early emotional intervention in a scalable and safe way.

Data retrieval and preprocessing preparation

Google Research developed GoEmotions which contains 58,000 English Reddit comments labeled with 27 fine-grained emotions plus neutrality. The study focuses on five primary emotions relevant to mental health analysis: anger, surprise, sadness, joy and neutrality, because they are fundamental affective states that are of immediate interest to mental health analysis. This minimizes class imbalance in GoEmotions and makes the evaluation simpler as well, but it limits generalization to more nuanced or less frequent emotional states (e.g., grief, embarrassment).

Specific validation: A manually labelled subset of 200 Reddit samples using the GoEmotions labeling guidelines was obtained and sarcasm-specific validation was conducted to ensure the contextual detection ability of sarcasm with the ability to interpret indirect sentiment expression. Multi-label samples with the emotions not belonging to the five categories chosen were excluded to ensure the label purity and comparability of all data splits.

Re, NLTK, and HuggingFace tokenizers were used to implement preprocessing in Python. Any text was stripped (of special characters), turned to lower case, and tokenized with the BERT-base-uncased tokenizer (HuggingFace Transformers v4.34). After analysis, it was determined that a sequence length of 128 tokens was good and covered almost 90 percent of the comments made on Reddit with little truncation.

Stratified sampling was used to separate the dataset into training, validation, and test sets (80:10:10) so that the proportions of classes could be maintained. Reproducibility was ensured using a fixed random seed (42 to stratify and 1234 to initialize weights), meaning that the results can be reproduced by any of its runs. The strategy of truncation and padding to the maximum length were the longest-first and maximum sequence length implemented in TensorFlow tokenization.

Transformer models need attention mask and input IDs to each text sample. Label mappings were transformed into numeric class IDs which could be compatible with the TensorFlow datasets to optimally batch and evaluate them.

We used several open-source GoEmotions implementations, such as the PyTorch version by Monologg [17] and the HuggingFace pipeline by Minfenli [18] as the baselines to determine the validity of our preprocessing pipeline. Past studies (e.g., Song, 2024 [19]) have shown that the fine-tuned versions of BERT can detect subtle emotional expressions and our method is based on such studies.

All the preprocessing scripts, tokenizer configuration, and its environment configuration files can be accessed publicly in our GitHub repository (https://github.com/anushreedahiya/ModernBERT-Large-GoEmotions).

[20], making reproducibility and transparency wholly guaranteed.

Model architecture

Mental health-related conversation emotion recognition presents a complex challenge because it requires models to identify direct emotional indications and detect both subtle signals and hidden feelings and sarcastic statements as well as contextualized emotional nuances. We developed two transformer-based architectures for assessing their capability to detect emotions in mental health-related user inputs through fine-tuning using GoEmotions. This dataset originated from Reddit posts.

BERT-base-uncased model

The model uses BERT-base-uncased architecture as its foundation which stands as a well-known general-purpose language understanding system. This model contains 12 transformer layers and 110 million parameters which establishes it as a reference point for identifying emotional content.

  • Fine-Tuning Configuration:
    • Learning Rate: 1e-6
    • Batch Size: 32
    • Epochs: 50
    • Optimizer: AdamW
    • Loss Function: Binary Cross-Entropy (in case of the multi label classification)
    • Framework: TensorFlow
    • Emotion Subset Used: anger, surprise, sadness, joy, and neutral (out of 28 labels of original GoEmotions dataset). It is a strategic choice process that enhances targeting in mental health content as these choice emotions are recurrent.

BERT-base-uncased achieved good results with frequent expressions of joy and sadness yet showed challenges with advanced emotional signals including sarcasm combined with mixed feelings or disguise of negative emotion which frequently appear in mental health dialogues. BERT-base-uncased showed limited capacity to capture deeper emotional context, motivating the need for a richer model.

ModernBERT large model

ModernBERT Large was used as an alternative to BERT-base-uncased since it is a more advanced transformer model that is specifically trained on fine-grained emotion recognition. The model has improved the number of layers to 24 along with higher attention depth and better contextual output which makes it better at detecting subtle emotional cues.

  • Fine-Tuning Configuration:
    • Learning Rate: 2e-5
    • Batch Size: 16
    • Epochs: 3
    • Weight Decay: 0.01
    • Optimizer: AdamW
    • Measures of Evaluation: Accuracy, Precision, Recall and Weighted F1 Score. Training employed PyTorch Automatic Mixed Precision (fp16) to reduce GPU memory usage and accelerate convergence. Sigmoid outputs ≥ 0.5 on each label were considered positive; the threshold was selected for maximal F1 on the validation set.
    • Integration PyTorch with HuggingFace for Transformer.

ModernBERT Large achieved the best performance results because it successfully identified mixed or ambiguous emotional states among its test datasets. The attention mechanism of this model achieved successful identification of emotional contexts in sarcastic and empathetic and multi-emotional comments thereby validating its context detection potential.

This table consolidates the main hyperparameters used for training each model. Future work may explore further hyperparameter tuning and class-imbalance mitigation strategies such as weighted loss or focal loss.

Comparison of models

  • ModernBERT Large achieved superior performance than BERT-base-uncased across all target emotions but showed notable results in identifying anger together with surprise emotions found within user-generated content.

  • BERT-base-uncased was trained using early stopping that used 50 epochs, and ModernBERT Large only used 3 epochs because of computational constraints. Although ModernBERT Large had shorter training, it converged fast and further gains were not material after epoch 3. The difference does not favour one side of the comparison because both models were trained until their validation performance stopped improving.

  • ModernBERT Large learned more quickly because representation of the context were denser and initial weights more appropriate and needed only three epochs, as opposed to fifty by BERT-base-uncased. Preliminary experiments ensured that this difference did not bias the performance because both models were close to optimum results.

  • ModernBERT Large validation curves were monitored so as to achieve proper generalization with little overfitting. BERT-base-uncased was overfitting on shared emotions (e.g., joy), but ModernBERT Large was less affected by these differences in categories. Though the use of per-class measures and confusion matrices were not calculated in this study, they should be introduced into future research in order to better measure the underrepresented or difficult emotions.

  • ModernBERT Large was advantaged by the extensibility of HuggingFace and PyTorch, whereas BERT-base-uncased was trained in TensorFlow because it had a faster start-up time.

  • GoEmotions had class imbalance, with predominant emotions, such as joy and sadness, and this led to lower recall on less common emotions, which could be reduced using weighted loss or oversampling.

  • BERT-base-uncased is reproducible and was trained in TensorFlow through the Kaggle notebook of Enesztrk [21] and ModernBERT Large, which is written in PyTorch and uses the HuggingFace GoEmotions dataset [22]. Transparency of the preprocessing scripts, tokenization pipelines and hyperparameter (Table 2) settings are well documented.

Table 2.

Consolidated hyperparameters used for training BERT-base-uncased and ModernBERT Large models.

Model Learning Rate Batch Size Epochs Optimizer Loss Function Framework Other Notes
BERT-base-uncased 1e-6 32 50 AdamW Binary Cross-Entropy TensorFlow Subset of 5 emotions
ModernBERT Large 2e-5 16 3 AdamW Binary Cross-Entropy PyTorch/HuggingFace Weight decay 0.01, fp16

Modern transformer architecture approaches such as ModernBERT Large provide superior performance when used in emotional mental health detection tasks that require understanding of subtle contexts. The foundation of Model B for empathetic AI application development is preferred because of its capability to process mixed-emotion and sarcastic content.

Experimental setup

The experiment was performed on a high-perform workstation that had been equipped. Model implementation was done using Tensorflow and PyTorch with HuggingFace Transformers, and common Python packages were used to process and assess data. The specifications are given in detail in Table 3.

Table 3.

Hardware and software specifications for model training.

Component Specification/ Version
CPU Intel Core i7–12,700 K, 3.6 GHz (12 cores)
GPU NVIDIA RTX 3090, 24 GB VRAM
RAM 64 GB DDR4
Storage 2 TB NVMe SSD
Operating System Windows 11 Pro / Ubuntu 22.04 LTS
CUDA Version 12.1
Python Version 3.11
TensorFlow Version 2.13
PyTorch Version 2.1
HuggingFace Transformers 4.34
Other Libraries NumPy (1.26), Pandas (2.1), scikit-learn (1.3)

Reproducibility note: Due to the long runtime, the experiment can also be re-executed on mid-range GPUs (e.g., NVIDIA RTX 3060). This statement is based on theoretical estimation and framework compatibility, as lower-tier hardware testing was not empirically conducted.

Evaluation parameter

The efficiency of the model can be calculated using validation accuracy which are explained by Eqs. (1), (2), (3) and (4).

Accuracy=TP+TNTP+TN+FP+FN×100 (1)
Precision=TPTP+FP×100 (2)
Recall=TPTP+FN (3)
F1score=2×(Precision×Recall)(Precision+Recall) (4)

Where

TP = True Positive correctly predicted [23].

TN = True Negative correctly predicted [23].

FP = False Positive incorrectly predicted [23].

FN = False Negative incorrectly predicted [23].

Ethical and privacy considerations

Policy of data retention and anonymization: The system is adhering to privacy-by-design lifecycle. Input texts are inferred after processing them temporarily; there are no long-term user identifiers and raw messages. Session artifacts (encrypted to be useful during debugging or performance optimization) will be deleted within 24 h by default; exceptions of 7 days will only be used on high-risk escalation logs that human moderators will review.

The only outputs that are saved to be used in reporting research are aggregated, de-identified statistics (no text or metadata). Transport-layer encryption is based on HTTPS/TLS 1.3 together with rest-based AES-256 encryption. It has user-initiated deletion features to allow auditing and access control based on roles to maintain traceability and accountability.

  • Handling of neutral text or off-topic text: In cases where the user input does not fit in any of the trained categories of emotion, the model will pick the input as neutral/undefined, and offer a generic supportive response inviting the user to rephrase their feelings. There is no misclassification that is stored and logged.

  • Clinical danger and escalation reasoning: There is the risk of ethics of misclassification of negative emotional states (e.g., distress or suicidal ideation). The system also has a triage system in which high-risk content causes immediate flagging to an encrypted queue, which can only be accessed by validated mental-health professionals. Such flagged data are kept no longer than 7 days as encrypted data and then automatically cleansed. In a practical implementation, human-in-the-loop validation and partner agencies (e.g. helplines or clinicians) would be included in this process. Emotion detection is not diagnostic, only a support of automation.

  • Regulatory and ethical posture: The design is based on the principles of GDPR (data minimization, user consent and right to erasure) and adheres to the industry best practices in regards to the deployment of AI. The architecture also meets the most important regulatory requirements of health AI privacy, although there are no formal audits (e.g., GDPR/HIPAA certification) yet.

Method validation

The section illustrates the observations of model training to implement performance analysis that rides on a system improvement strategy. Model training process involves thorough testing such as the response of the model to validation exercises and the influence of various measures on the model performance. The analysis of model purposes identifies present strong elements along with expansion opportunities that improve the system's final generalization abilities. Validation data accuracy assessment occurs together with training phase results evaluation to show model performance.

This division includes the outcome derived after the analysis, and its discussions:

Data partitioning

The dataset was divided into training (80 percent), validation (10 percent), and testing (10 percent) in order to create a fair assessment system.

  • Training Set: 80 %

  • Validation Set: 10 %

  • Test Set: 10 %

Performance overview

Training accuracy

  • BERT-base-uncased demonstrates reliable performance, emotion identification through rapid training and economical resources usage.

  • This scaled version of ModernBERT is superior to its counterparts in the processing of emotions in the complex forms of language.

Model size and complexity

  • BERT-base-uncased: ∼110 M parameters. The technology is efficient but it has a limit in the number of parameters that it can capture to capture the broad emotional contexts.

  • ModernBERT Large: ∼340 M parameters. Achieves improved contextual representation through additional computation.

  • Although ModernBERT Large contains more parameters (∼340 M) than BERT-base-uncased (∼110 M), it is more prone to converge faster owing to compact pre-trained representations on context and deeper attention layers, which enable successful learning in less epochs (3 vs. 50). This demonstrates the advantage that the large transformers with pre-trained can give to the recognition of their fine-grained emotions using limited training cycles.

Handling sarcasm & nuances

The basic emotional states detection function of BERT-base-uncased works well although it fails to recognize ambiguous or sarcastic messages. The ModernBERT Large model shows a better capacity to detect more complex emotional clues that comprise sarcasm as well as multi-layered emotions and nuanced emotions.

Application suitability

  • BERT-base-uncased: It is fast and has a small deployment structure to that it can be implemented in mobile solutions, chatbots services or mood tracking systems.

  • ModernBERT Large: Provides the most benefit in complex mental health evaluation systems because of its strong capacity to comprehend emotionally sophisticated high-stakes applications.

System resource utilization

  • BERT-base-uncased:
    • Efficient on CPUs or modest GPUs.
    • Offers fast learning as well as prediction speeds.
    • Can be executed on its own and straight onto user devices.
  • ModernBERT Large:
    • Needs powerful GPUs, and huge memory storage, as well as longer periods of training.
    • It matches server-grade and cloud-based deployments which have sufficient resources to operate.

ModernBERT Large does not have any validation curves since the key point of this research was on deployable models including BERT-base-uncased. Because of the cost of training the larger model we only applied curve-based visualization to BERT-base-uncased.

However, Table 4 presents the summary of the comparative performance metrics and the trade-off between the accuracy and recall are observed in case of a class imbalance.

Table 4.

Performance comparison of BERT-base-uncased and ModernBERT Large models.

ModernBERT achieves higher overall accuracy but substantially lower recall and F1-score, indicating that it predicts majority emotion classes effectively while overlooking minority emotions due to dataset imbalance.

Model Accuracy Precision Recall F1 Score
BERT-base-uncased 89 % 88 % 86 % 85 %
ModernBERT Large 97 % 66.5 % 38.9 % 46.5 %

The apparent contradiction between ModernBERT’s high accuracy (97 %) and low recall (38.9 %) reflects the influence of class imbalance in GoEmotions. In this case, majority classes (neutral and anger) are dominated by accuracy, the model predicts most of the time thus inflating the overall score. Nonetheless, it does not identify less frequent emotions (e.g., joy, sadness, surprise) and, therefore, recalls poorly, with high F1. This behaviour indicating that the confidence distribution of the model is concentrated on dominant classes can be fixed in future research by means of reweighting, focal loss, or oversampling.

Although they do not report per-class precision / recall values and confusion matrices in this implementation, the imbalance of the classes is clearly shown in Fig. 2. The dataset is dominated by neutral and anger as compared to sadness, joy and surprise which are underrepresented. This discrepancy is the cause of systematic differences in performance: ModernBERT demonstrates high overall accuracy because it is highly predictive of majority classes, but has low recall rates on minority emotions. Therefore, frequent classes are easily identified but rare emotions are often overlooked. This skew may be overcome in future work by methods like class reweighting or augmentation of the data to improve recall on skewed categories.

Fig. 2.

Fig 2

Distribution of emotion labels in GoEmotions.

Class imbalance strongly favours “neutral” and “anger,” explaining low recall for minority emotions like “sadness,” “joy,” and “surprise.”

In the case of BERT-base, the training accuracy rises gradually with each epoch, and the accuracy peaks at 89 %. Nevertheless, the accuracy of validation is initially high (epoch = 6 8 and the like) and then decreases, which is a typical indicator of overfitting. It means that BERT-base will only memorize the training set, but not generalize, particularly in the minority emotion classes.

Loss on training reduces steadily, however, validation loss starts to increase after epoch 15, which supports the idea of overfitting in BERT-base. The model gives preference to majority classes, although regularization measures (dropout, early stopping) are used, the minority ones are not well represented.

In Fig. 3, Fig. 4, the trends of overfitting in BERT-base are observed as such BERT-base values begin to decrease in validation accuracy after epoch 6–8 and begin to increase in validation loss after epoch 15. In the case of ModernBERT, we were limited by resources to generate very long validation curves, but early experiments showed that validation did not change dramatically over the epochs, indicating that the validation performance improved less than in the case of BERT-base. BERT-base-uncased is more efficient to deploy and use in the general purpose. ModernBERT Large performs best in complex emotion recognition, in particular, sarcasm, though it needs a higher amount of resources and data balancing to achieve optimum recall.

Fig. 3.

Fig 3

Training vs. validation accuracy for BERT-base-uncased.

X-axis: epochs (0–50); Y-axis: accuracy ( %). The divergence after epoch 6 indicates overfitting, as validation accuracy peaks early and then declines.

Fig. 4.

Fig 4

Training vs. validation loss for BERT-base-uncased.

X-axis: epochs (0–50); Y-axis: loss value. The rise in validation loss after epoch 15 further confirms overfitting behaviour.

Result interpretation

  • Fig. 2 shows the high level of class imbalance in the GoEmotions data where neutral and anger are the most common, whereas sadness, joy, and surprise are underrepresented. This asymmetry directly affects model behaviour: BERT-base and ModernBERT are both highly accurate overall but have low recall on infrequent categories.

  • BERT-base-uncased has consistent performance with 86 to 92 precision, 86 to 89 recall, 89 accuracy and 85 to 90 F1-scores. Fig. 3, Fig. 4, however, show obvious indications of overfitting - training accuracy increases continuously whereas validation accuracy reaches a peak early and then decays. Equally, the loss on training also declines but validation loss increases, at epoch 15, which shows that there is little generalization when the conditions are unbalanced.

  • Ethical implications: The low recall of minority emotions in a mental-health support setting can imply that a system is unable to identify any subtle or uncommon emotional indicators of grief, confusion, and distress. This false negative may decrease trust of users or decrease response time. Thus, to be responsible in implementing it in mental-health settings, dataset balancing and adaptive thresholding is important to enhance recall.

  • The overall accuracy of ModernBERT Large is the highest (97 percent), whereas the recall is extremely low (38.9), and F1-score is quite low (46.5). This gives a high level of accuracy in large classes but low sensitivity to rare or less pronounced emotions which is the trade-off between the ability and the strength to imbalance. Since this release of ModernBERT Large is limited to computing a small number of metrics, it does not include fine-grained class-by-class statistics and intra-validation curves. However, even aggregate measures and Fig. 2 already demonstrate that the feelings of minorities are being under-measured systematically.

  • In order to have transparency, a place holder template of per-class metrics (Precision, Recall, F1-score and Support) is added in Table S1 in the Appendix. They will be filled and they can be released in the next update of the repository. The future versions will also have complete curves of epoch-wise validation of ModernBERT and other class-balancing approaches like weighted loss and oversampling.

Limitations

The GoEmotions dataset contains only comments in the English language on Reddit and, thus, might not capture cultural or language differences in expression of emotions. Moreover, the research concentrated on five main affective states (anger, surprise, sadness, joy, and neutral), making it easier to assess the research, but it restricts generalizations to the entire range of human affect. This limitation could be overcome by future research training on multilingual, diverse and domain-specific data to enhance the inclusiveness of different cultures.

The underrepresented emotions, sadness and surprise, are more difficult to recognize, as reflected in Fig. 2. The ethical implications of this diminished recall in the sensitive mental-health cases are possible when distress or crisis consequences are missed. This is why the existing system is to be regarded as a supportive measure instead of a diagnostic one that supplements but does not substitute professional mental-health care.

Future work

In the future, we would like to go beyond the GoEmotions data set to multilingual and culturally adaptive corpora that capture the expression of emotions of the world in a more thorough manner. We will also incorporate federated learning to improve privacy, measure the use of differential-privacy noise to provide an extra-data protection, and conduct field tests within clinical and community-setting to test feasibility.

Further research will focus on methods of data-balancing and enhanced regularization to enhance a better generalization of models to underrepresented emotions. Another line of investigation will connect this framework with digital-therapy and clinician-support systems, creating privacy-preserving pipelines for emotion-aware recommendations and decision assistance.

The future directions of the research will focus on the class-imbalance mitigation strategies, including focal loss, weighted sampling, or class-specific cost functions, to further enhance recall of minority emotions.

Ethics statements

The study used only publicly available anonymized samples of the GoEmotions dataset, comprising of Reddit messages without user identifiers, and does not exceed the limits of the terms of use of the latter platform. There were no experiments involving human beings or animals.

Possible threats are the inappropriate classification of the emotions of the users that would result in an unsuitable response. The system is created as an aid, rather than a replacement of therapy, to counter this, with the possibility of escalation of high-risk content (i.e., suicidal ideation) by redirecting users to professional help lines or clinicians.

Every communication is encrypted by HTTPS/TLS and AES-256, and all the processing is performed based on the principles of privacy-by-design mentioned above.

Related research article

None.

For a published article

None.

CRediT authorship contribution statement

Pooja Bagane: Investigation, Supervision, Writing – review & editing. Anushree Dahiya: Formal analysis, Conceptualization, Methodology, Visualization, Software, Validation, Writing – original draft. Shardul Kacheria: Conceptualization, Investigation, Supervision, Writing – review & editing. Ansh Sehgal: Formal analysis, Conceptualization, Methodology, Visualization, Software, Validation, Writing – original draft. Shrishti Bajpai: Formal analysis, Conceptualization, Methodology, Visualization, Software, Validation, Writing – original draft. Obsa Amenu Jebessa: Investigation, Supervision, Writing – review & editing.

Declaration of competing interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Acknowledgments

This research was not funded by any grant but we would like to express our gratitude to different research paper publishers and online websites for providing valuable information on the concept of GoEmotion dataset, machine learning, deep learning.

Footnotes

Supplementary material associated with this article can be found, in the online version, at doi:10.1016/j.mex.2025.103756.

Appendix. Supplementary materials

Supplementary material and/or additional information [OPTIONAL]

mmc1.docx (15.4KB, docx)

Data availability

Data will be made available on request.

References

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

Supplementary material and/or additional information [OPTIONAL]

mmc1.docx (15.4KB, docx)

Data Availability Statement

Data will be made available on request.


Articles from MethodsX are provided here courtesy of Elsevier

RESOURCES