nBERT: Harnessing NLP for Emotion Recognition in Psychotherapy to Transform Mental Health Care
Abstract
:1. Introduction
- We develop a fine-tuned nBERT model with domain-specific adjustments for psychotherapy transcripts, which significantly enhances the accuracy and precision of emotion recognition in text-based analysis for mental health research.
- We present the integration of the NRC Emotion Lexicon with an advanced AI model, which allows for the accurate identification and in-depth analysis of a wide range of emotional expressions during psychotherapy sessions.
- We offer empirical evidence proving that our method outperforms existing models. Our findings show significant improvements in emotion recognition accuracy, indicating an important advancement forward in the creation of more effective therapeutic approaches.
2. Literature Review
2.1. Text-Based Emotion Analysis
2.2. BERT in Mental Health
3. Proposed Methodology
- Data Construction: This phase involves transforming raw psychotherapy transcripts into a structured format suitable for computational analysis, ensuring data integrity and readiness for AI-based models.
- Emotion Recognition: Utilizes the NRC Lexicon to systematically categorize and quantify emotional expressions within the processed texts, setting the goal for in-depth emotional analysis.
- Model Configuration: Focuses on optimizing BERT through domain-specific adaptation and fine-tuning techniques, aligning the model with the intricacies of psychotherapeutic language to elevate its predictive accuracy and analytical depth.
3.1. Data Construction
- Dialogue Character Identification: Using regular expressions via Python’s ‘re’ module; this step identifies 31 unique dialogue characters, such as THERAPIST, PATIENT, DR, and NR. This method enhances character-based analysis and filters dialogue participants, offering deeper insights into client emotions and dialogue dynamics.
- Filtering Relevant Files: This step copies files containing specific target characters (e.g., PATIENT, COUNSELOR, THERAPIST) to narrow down the dataset for essential interactions, improving efficiency and reducing processing time, thus optimizing the research workflow.
- Content Preprocessing and Tokenization: It cleans text by removing noise, tokenizing words with NLTK’s ‘word_tokenize’, removing stopwords, and applying lemmatization with the ‘WordNetLemmatizer’. This process reduces text complexity and noise, significantly improving NLP models’ training efficiency, particularly for models like BERT.
- Tag Standardization: Regex pattern matching ensures uniformity in dialogue tags (e.g., converting ‘PATIENT’, ‘PT’ to ‘CLIENT’, and ‘COUNSELOR’, ‘THERAPIST’ to ‘COUNSELOR’), making analysis and categorization consistent and accurate.
- Metadata-Driven Insights: This approach leverages metadata to structure and analyze psychotherapeutic dialogues across five dimensions:
- Gender Analysis: Groups files based on client’s gender, enabling gender-specific dialogue pattern analysis using the ‘pandas’ library.
- Marital Status: Categorizes files by marital status (e.g., single, married, divorced) to study its impact on therapy discussions and outcomes.
- Sexual Orientation: Segregates files by sexual orientation (e.g., heterosexual, bisexual, gay), enhancing inclusivity in therapeutic analysis.
- Psychological Subjects: Organizes files based on psychological themes (e.g., depression, stress) for focused analysis.
- Symptoms Categorization: Groups files by symptoms (e.g., anxiety, anger) to recognize patterns and guide targeted therapeutic interventions.
- Syntactic Parsing: Utilizing spaCy, this method analyzes sentence structures to reveal relationships between subjects, verbs, and objects. It helps identify linguistic patterns in psychotherapeutic transcripts, aiding in the recognition of emotions and enhancing the understanding of mental health dynamics.
3.2. Emotion Recognition
3.3. nBERT Model Configuration
3.4. Input Representation
3.5. Transformer Architecture and Contextualization
3.6. Domain-Specific Adaptations
Algorithm 1 Emotion recognition via a fine-tuned nBERT with domain-specific adaptations |
Require: Psychotherapy Transcripts Dataframe D, Pretrained BERT Model Directory , NRC Emotion Lexicon L, Tokenizer Directory for WordPiece Tokenizer, Training , Validation , and Test data splits, Learning Parameters P including Batch Size, Learning Rate, and Epochs. |
Ensure: Fine-tuned nBERT model , Performance Metrics: Precision (P), Recall (R), F1-Score, and Accuracy (Acc.). |
|
4. Results
4.1. Experiment Process and Setup
4.2. Emotions and Sentiment Frequencies
4.3. Client’s NRC-Based Emotion Analysis
4.4. nBERT Prediction Performance
4.5. Comparison with Baseline Models
5. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Kim, S.; Cha, J.; Kim, D.; Park, E. Understanding mental health issues in different subdomains of social networking services: Computational analysis of text-based Reddit posts. J. Med. Internet Res. 2023, 25, e49074. [Google Scholar] [CrossRef] [PubMed]
- Hutto, C.; Gilbert, E. Vader: A parsimonious rule-based model for sentiment analysis of social media text. In Proceedings of the International AAAI Conference on Web and Social Media, Ann Arbor, MI, USA, 1–4 June 2014; Volume 8, pp. 216–225. [Google Scholar]
- Monferrer, M.; García, A.S.; Ricarte, J.J.; Montes, M.J.; Fernández-Caballero, A.; Fernández-Sotos, P. Facial emotion recognition in patients with depression compared to healthy controls when using human avatars. Sci. Rep. 2023, 13, 6007. [Google Scholar] [CrossRef] [PubMed]
- Rasool, A.; Shahzad, M.I.; Aslam, H.; Chan, V. Emotion-Aware Response Generation Using Affect-Enriched Embeddings with LLMs. arXiv 2024, arXiv:2410.01306. [Google Scholar]
- Senn, S.; Tlachac, M.; Flores, R.; Rundensteiner, E. Ensembles of bert for depression classification. In Proceedings of the 2022 44th Annual International Conference of the IEEE Engineering in Medicine & Biology Society (EMBC), Glasgow, UK, 11–15 July 2022; IEEE: Piscataway, NJ, USA, 2022; pp. 4691–4694. [Google Scholar]
- Simcock, G.; McLoughlin, L.T.; De Regt, T.; Broadhouse, K.M.; Beaudequin, D.; Lagopoulos, J.; Hermens, D.F. Associations between facial emotion recognition and mental health in early adolescence. Int. J. Environ. Res. Public Health 2020, 17, 330. [Google Scholar] [CrossRef]
- Mukhiya, S.K.; Ahmed, U.; Rabbi, F.; Pun, K.I.; Lamo, Y. Adaptation of IDPT system based on patient-authored text data using NLP. In Proceedings of the 2020 IEEE 33rd International Symposium on Computer-Based Medical Systems (CBMS), Rochester, MN, USA, 28–30 July 2020; IEEE: Piscataway, NJ, USA, 2020; pp. 226–232. [Google Scholar]
- Zad, S.; Jimenez, J.; Finlayson, M. Hell hath no fury? correcting bias in the nrc emotion lexicon. In Proceedings of the 5th Workshop on Online Abuse and Harms (WOAH 2021), Bangkok, Thailand, 6 August 2021; pp. 102–113. [Google Scholar]
- Yimu, X. Ethnic minorities’ mentality and homosexuality psychology in literature: A text emotion analysis with NRC lexicon. Appl. Comput. Eng. 2023, 13, 240–250. [Google Scholar] [CrossRef]
- Mohammad, S.M.; Turney, P.D. Crowdsourcing a word–emotion association lexicon. Comput. Intell. 2013, 29, 436–465. [Google Scholar] [CrossRef]
- Mohammad, S.M.; Turney, P.D. NRC Emotion Lexicon; National Research Council: Ottawa, ON, Canada, 2013; Volume 2, p. 234. [Google Scholar]
- Boyd, R.L.; Ashokkumar, A.; Seraj, S.; Pennebaker, J.W. The Development and Psychometric Properties of LIWC-22; The University of Texas at Austin: Austin, TX, USA, 2022; Volume 10. [Google Scholar]
- Han, P.; Chen, H.; Jiang, Q.; Yang, M. MFB: A Generalized Multimodal Fusion Approach for Bitcoin Price Prediction Using Time-Lagged Sentiment and Indicator Features. Expert Syst. Appl. 2025, 261, 125515. [Google Scholar] [CrossRef]
- Barik, K.; Misra, S.; Ray, A.K.; Bokolo, A. LSTM-DGWO-Based Sentiment Analysis Framework for Analyzing Online Customer Reviews. Comput. Intell. Neurosci. 2023, 2023, 6348831. [Google Scholar] [CrossRef]
- Velu, S.R.; Ravi, V.; Tabianan, K. Multi-lexicon classification and valence-based sentiment analysis as features for deep neural stock price prediction. Sci 2023, 5, 8. [Google Scholar] [CrossRef]
- Samir, H.A.; Abd-Elmegid, L.; Marie, M. Sentiment analysis model for Airline customers’ feedback using deep learning techniques. Int. J. Eng. Bus. Manag. 2023, 15, 18479790231206019. [Google Scholar] [CrossRef]
- Sung, Y.W.; Park, D.S.; Kim, C.G. A Study of BERT-Based Classification Performance of Text-Based Health Counseling Data. CMES-Comput. Model. Eng. Sci. 2023, 135, 795–808. [Google Scholar]
- Benítez-Andrades, J.A.; Alija-Pérez, J.M.; Vidal, M.E.; Pastor-Vargas, R.; García-Ordás, M.T. Traditional machine learning models and bidirectional encoder representations from transformer (BERT)–based automatic classification of tweets about eating disorders: Algorithm development and validation study. JMIR Med. Inform. 2022, 10, e34492. [Google Scholar] [CrossRef]
- Hudon, A.; Beaudoin, M.; Phraxayavong, K.; Dellazizzo, L.; Potvin, S.; Dumais, A. Use of automated thematic annotations for small data sets in a psychotherapeutic context: Systematic review of machine learning algorithms. JMIR Ment. Health 2021, 8, e22651. [Google Scholar] [CrossRef] [PubMed]
- Malgaroli, M.; Hull, T.D.; Zech, J.M.; Althoff, T. Natural language processing for mental health interventions: A systematic review and research framework. Transl. Psychiatry 2023, 13, 309. [Google Scholar] [CrossRef] [PubMed]
- Bharti, S.K.; Varadhaganapathy, S.; Gupta, R.K.; Shukla, P.K.; Bouye, M.; Hingaa, S.K.; Mahmoud, A. Text-Based Emotion Recognition Using Deep Learning Approach. Comput. Intell. Neurosci. 2022, 2022, 2645381. [Google Scholar] [CrossRef]
- Gatto, A.J.; Elliott, T.J.; Briganti, J.S.; Stamper, M.J.; Porter, N.D.; Brown, A.M.; Harden, S.M.; Cooper, L.D.; Dunsmore, J.C. Development and feasibility of an online brief emotion regulation training (BERT) program for emerging adults. Front. Public Health 2022, 10, 858370. [Google Scholar] [CrossRef] [PubMed]
- Zhang, T.; Schoene, A.M.; Ji, S.; Ananiadou, S. Natural language processing applied to mental illness detection: A narrative review. NPJ Digit. Med. 2022, 5, 46. [Google Scholar] [CrossRef]
- Alrasheedy, M.N.; Muniyandi, R.C.; Fauzi, F. Text-Based Emotion Detection and Applications: A Literature Review. In Proceedings of the 2022 International Conference on Cyber Resilience (ICCR), Dubai, United Arab Emirates, 6–7 October 2022; IEEE: Piscataway, NJ, USA, 2022; pp. 1–9. [Google Scholar]
- Han, P.; Hong, J.; Chen, H.; Pan, Y.; Jiang, Q. A Hybrid Recommendation Model for Social Network Services Using Twitter Data. In Web Services—ICWS 2022; Zhang, Y., Zhang, L.J., Eds.; Springer: Cham, Switzerland, 2022; pp. 122–129. [Google Scholar]
- Kour, H.; Gupta, M.K. AI assisted attention mechanism for hybrid neural model to assess online attitudes about COVID-19. Neural Process. Lett. 2023, 55, 2265–2304. [Google Scholar] [CrossRef]
- Krommyda, M.; Rigos, A.; Bouklas, K.; Amditis, A. An experimental analysis of data annotation methodologies for emotion detection in short text posted on social media. Informatics 2021, 8, 19. [Google Scholar] [CrossRef]
- Rasool, A.; Jiang, Q.; Qu, Q.; Kamyab, M.; Huang, M. HSMC: Hybrid Sentiment Method for Correlation to Analyze COVID-19 Tweets. In Advances in Natural Computation, Fuzzy Systems and Knowledge Discovery; Springer International Publishing: Cham, Switzerland, 2022; pp. 991–999. [Google Scholar]
- Alturayeif, N.; Luqman, H. Fine-grained sentiment analysis of arabic covid-19 tweets using bert-based transformers and dynamically weighted loss function. Appl. Sci. 2021, 11, 10694. [Google Scholar] [CrossRef]
- Antoniou, M.; Estival, D.; Lam-Cassettari, C.; Li, W.; Dwyer, A.; de Almeida Neto, A. Predicting mental health status in remote and rural farming communities: Computational analysis of text-based counseling. JMIR Form. Res. 2022, 6, e33036. [Google Scholar] [CrossRef]
- Liu, J.; Wang, H. Analysis of educational mental health and emotion based on deep learning and computational intelligence optimization. Front. Psychol. 2022, 13, 898609. [Google Scholar] [CrossRef]
- Liu, X.; Zhou, J.; Lu, R. Research on Text Emotion Analysis Based on LSTM. In Proceedings of the 2023 International Conference on Computer, Vision and Intelligent Technology, Chenzhou, China, 25–28 August 2023; pp. 1–6. [Google Scholar]
- Tang, J.; Su, Q.; Niu, L.; Huang, J.; Su, B.; Lin, S. Emotion analysis of Chinese reviews based on fusion of multi-layer CNN and LSTM. In Proceedings of the 2022 5th International Conference on Image and Graphics Processing, Beijing, China, 7–9 January 2022; pp. 351–356. [Google Scholar]
- Lu, Z. Analysis model of college students’ mental health based on online community topic mining and emotion analysis in novel coronavirus epidemic situation. Front. Public Health 2022, 10, 1000313. [Google Scholar] [CrossRef] [PubMed]
- Chriqui, A.; Yahav, I. HeBERT and HebEMO: A Hebrew BERT model and a tool for polarity analysis and emotion recognition. INFORMS J. Data Sci. 2022, 1, 81–95. [Google Scholar] [CrossRef]
- Makhmudov, F.; Kultimuratov, A.; Cho, Y.I. Enhancing Multimodal Emotion Recognition through Attention Mechanisms in BERT and CNN Architectures. Appl. Sci. 2024, 14, 4199. [Google Scholar] [CrossRef]
- Hou, Z.; Du, Y.; Li, Q.; Li, X.; Chen, X.; Gao, H. A false emotion opinion target extraction model with two stage BERT and background information fusion. Expert Syst. Appl. 2024, 250, 123735. [Google Scholar] [CrossRef]
- Sharma, A.; Miner, A.S.; Atkins, D.C.; Althoff, T. A computational approach to understanding empathy expressed in text-based mental health support. arXiv 2020, arXiv:2009.08441. [Google Scholar]
- Althoff, T.; Clark, K.; Leskovec, J. Large-scale analysis of counseling conversations: An application of natural language processing to mental health. Trans. Assoc. Comput. Linguist. 2016, 4, 463–476. [Google Scholar] [CrossRef]
- Rietberg, M.T.; Nguyen, V.B.; Geerdink, J.; Vijlbrief, O.; Seifert, C. Accurate and reliable classification of unstructured reports on their diagnostic goal using bert models. Diagnostics 2023, 13, 1251. [Google Scholar] [CrossRef]
- Lalk, C.; Steinbrenner, T.; Kania, W.; Popko, A.; Wester, R.; Schaffrath, J.; Eberhardt, S.; Schwartz, B.; Lutz, W.; Rubel, J. Measuring Alliance and Symptom Severity in psychotherapy transcripts using Bert Topic modeling. Adm. Policy Ment. Health Ment. Health Serv. Res. 2024, 51, 509–524. [Google Scholar] [CrossRef]
- Si, S.; Wang, R.; Wosik, J.; Zhang, H.; Dov, D.; Wang, G.; Carin, L. Students need more attention: Bert-based attention model for small data with application to automatic patient message triage. In Proceedings of the Machine Learning for Healthcare Conference, PMLR, Virtual, 7–8 August 2020; pp. 436–456. [Google Scholar]
- Usuga-Cadavid, J.P.; Lamouri, S.; Grabot, B.; Fortin, A. Using deep learning to value free-form text data for predictive maintenance. Int. J. Prod. Res. 2022, 60, 4548–4575. [Google Scholar] [CrossRef]
- Villatoro-Tello, E.; Parida, S.; Kumar, S.; Motlicek, P. Applying attention-based models for detecting cognitive processes and mental health conditions. Cogn. Comput. 2021, 13, 1154–1171. [Google Scholar] [CrossRef] [PubMed]
- Kabir, M.; Ahmed, T.; Hasan, M.B.; Laskar, M.T.R.; Joarder, T.K.; Mahmud, H.; Hasan, K. DEPTWEET: A typology for social media texts to detect depression severities. Comput. Hum. Behav. 2023, 139, 107503. [Google Scholar] [CrossRef]
- Danner, M.; Hadzic, B.; Gerhardt, S.; Ludwig, S.; Uslu, I.; Shao, P.; Weber, T.; Shiban, Y.; Ratsch, M. Advancing mental health diagnostics: GPT-based method for depression detection. In Proceedings of the 2023 62nd Annual Conference of the Society of Instrument and Control Engineers (SICE), Tsu, Japan, 6–9 September 2023; IEEE: Piscataway, NJ, USA, 2023; pp. 1290–1296. [Google Scholar]
- Khan, M.A.; Huang, Y.; Feng, J.; Prasad, B.K.; Ali, Z.; Ullah, I.; Kefalas, P. A multi-attention approach using BERT and stacked bidirectional LSTM for improved dialogue state tracking. Appl. Sci. 2023, 13, 1775. [Google Scholar] [CrossRef]
- Rasool, A. Advancing the Intersection of AI and Bioinformatics. J. Artif. Intell. Bioinform. 2024, 1, 1–2. [Google Scholar] [CrossRef]
- Aslam, S. CEL: A Continual Learning Model for Disease Outbreak Prediction by Leveraging Domain Adaptation via Elastic Weight Consolidation. Interdiscip. Sci. Comput. Life Sci. 2025. [Google Scholar] [CrossRef]
Parameters | Values |
---|---|
Environment | 12-layer, 768-hidden, 12-heads |
Parameters | 110 M |
Batch size | 16 |
Length embedding | 27 |
Epochs | 20 |
Optimizer | AdamW |
Learning rate | |
Dropout hidden | 0.3 |
Dropout attention | 0.5 |
Weight-decay |
No. | Client Emotional Statements | NRC Emotion |
---|---|---|
1 | That it is really just about getting up and doing your work and loving each other and finding purpose in everyday. | Joy |
2 | I talked to my mom and she said are you upset? And I said well I’m upset because I’ve been trying to get this answer for a couple weeks and he doesn’t tell me, and then he’s upset that it’s not the way he wants. | Anger |
3 | It wasn’t too bad. But I was glad I just didn’t have to worry like about getting here. So… | Anticipation |
4 | But I didn’t really… like I had done a dumb thing, but that I hadn’t… I hadn’t in a sense put a burden on him that he couldn’t take for once. | Negative |
5 | And she’s been sick for a while…when I walked into her apartment and her whole apartment smelled like gas. | Disgust |
6 | What was I afraid of? I guess just sex, I don’t know, but… | Fear |
7 | Yeah. It’s like all of a sudden it occurs to me that you know, perhaps just one part of it is that it’s like a real test of our love. | Positive |
8 | And that’s, I think, right these days that this jealousy and I’m sure it’s a fantasy. This is what makes me feel terribly neurotic. | Sadness |
9 | Yeah. I think so. Maybe I, well I don’t even remember even thinking that he was going to break up with this girl, you know. | Surprise |
10 | Because I’m convinced that it’s the best thing for me to do as well as the best thing for us to do as a couple and I know it will have positive results, no matter what. | Trust |
Epoch | BERT [37] | Proposed nBERT | |||||||
---|---|---|---|---|---|---|---|---|---|
P | R | F1 | Acc. | P | R | F1 | Acc. | Val. Acc. | |
2 | 0.848 | 0.844 | 0.8432 | 0.844 | 0.91 | 0.93 | 0.92 | 0.8308 | 0.9387 |
4 | 0.8979 | 0.8974 | 0.8959 | 0.8974 | 0.94 | 0.96 | 0.95 | 0.9242 | 0.9536 |
6 | 0.9203 | 0.9198 | 0.9196 | 0.9198 | 0.96 | 0.97 | 0.96 | 0.9441 | 0.9641 |
8 | 0.927 | 0.9265 | 0.9266 | 0.9265 | 0.97 | 0.97 | 0.97 | 0.9534 | 0.9657 |
10 | 0.9271 | 0.9254 | 0.9259 | 0.9254 | 0.97 | 0.97 | 0.97 | 0.9579 | 0.9662 |
12 | 0.9279 | 0.9278 | 0.9274 | 0.9278 | 0.97 | 0.96 | 0.96 | 0.9611 | 0.9638 |
14 | 0.93 | 0.9287 | 0.929 | 0.9287 | 0.97 | 0.97 | 0.97 | 0.9624 | 0.9662 |
16 | 0.931 | 0.9292 | 0.9305 | 0.9292 | 0.97 | 0.97 | 0.97 | 0.963 | 0.9665 |
18 | 0.932 | 0.9297 | 0.9319 | 0.9297 | 0.98 | 0.97 | 0.97 | 0.9635 | 0.9667 |
20 | 0.933 | 0.9301 | 0.9332 | 0.9301 | 0.98 | 0.97 | 0.97 | 0.9638 | 0.967 |
Ref.—Year | Dataset | Method | Model | Acc. (%) |
---|---|---|---|---|
[44]—2021 | Question-answer text | Fully connected network (FC) | BERT (fine-tuned) | 69 |
[5]—2022 | 12 Thematic Datasets | Base model with LSTM, self-attention (BLA) | Ensemble 3 | 62 |
[45]—2023 | DEPTWEET | Apply different algorithms | BERT | 82 |
[46]—2023 | DAIC-WOZ and Extended-DAIC | Multimodal approach | BERT | 82 |
[47]—2023 | WoZ-2.0 | BLA with Joint Goal | BERT-BiLSTM | 93 |
[26]—2023 | COVIDSenti-B | Hybrid Residual Encoder with BERT | RETN | 91 |
[36]—2024 | CMU-MOSEI | Attention-based fusion | BERT + CNN | 88.4 |
[37]—2024 | Weibo23 | Two-stage BERT fusion | BERT + CRF | 88.34 |
Our work—2025 | Counseling & Psychotherapy Transcripts, Volume II | Fine-tuned BERT adaptation with NRC lexicon | Domain-specific nBERT | 96 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Rasool, A.; Aslam, S.; Hussain, N.; Imtiaz, S.; Riaz, W. nBERT: Harnessing NLP for Emotion Recognition in Psychotherapy to Transform Mental Health Care. Information 2025, 16, 301. https://doi.org/10.3390/info16040301
Rasool A, Aslam S, Hussain N, Imtiaz S, Riaz W. nBERT: Harnessing NLP for Emotion Recognition in Psychotherapy to Transform Mental Health Care. Information. 2025; 16(4):301. https://doi.org/10.3390/info16040301
Chicago/Turabian StyleRasool, Abdur, Saba Aslam, Naeem Hussain, Sharjeel Imtiaz, and Waqar Riaz. 2025. "nBERT: Harnessing NLP for Emotion Recognition in Psychotherapy to Transform Mental Health Care" Information 16, no. 4: 301. https://doi.org/10.3390/info16040301
APA StyleRasool, A., Aslam, S., Hussain, N., Imtiaz, S., & Riaz, W. (2025). nBERT: Harnessing NLP for Emotion Recognition in Psychotherapy to Transform Mental Health Care. Information, 16(4), 301. https://doi.org/10.3390/info16040301