Your new experience awaits. Try the new design now and help us make it even better

ORIGINAL RESEARCH article

Front. Artif. Intell.

Sec. Natural Language Processing

Volume 8 - 2025 | doi: 10.3389/frai.2025.1627078

Explainable AI for Mental Health: Detecting Mental Illness from Social Media Using NLP and Machine Learning

Provisionally accepted
Sidra  HameedSidra Hameed1Muhammad  NaumanMuhammad Nauman1Nadeem  AkhtarNadeem Akhtar2Muhammad  A B FayyazMuhammad A B Fayyaz3*Raheel  NawazRaheel Nawaz4
  • 1Islamia University, Bahawalpur, Pakistan
  • 2University of Punjab, Lahore, Pakistan
  • 3Manchester Metropolitan University, Manchester, United Kingdom
  • 4staffordshire Universityu, Stoke-on-Trent, United Kingdom

The final, formatted version of the article will be published soon.

Mental disorders are prevalent in modern society, causing significant personal and societal suffering due to various socioeconomic, clinical, and individual risk factors. Increasingly, users express their thoughts and emotions on social media platforms, which presents new opportunities to leverage user-generated content for addressing critical societal challenges, such as the early detection of mental disorders. This work specifically focuses on the early detection of depression, one of the most common mental disorders, using black box machine learning (ML) models, including Support Vector Machines (SVM), Random Forests (RF), Extreme Gradient Boosting (XGB), and Artificial Neural Networks (ANN). These models are combined with advanced Natural Language Processing (NLP) techniques such as TF-IDF, Latent Dirichlet Allocation (LDA), N-grams, Bag of Words (BoW), and GloVe embeddings to effectively capture linguistic and semantic features for depression detection. While these black box models achieve high accuracy, their lack of interpretability undermines trust and applicability in sensitive healthcare contexts. To mitigate this issue, we incorporate Explainable AI (XAI) methodologies, specifically LIME (Local Interpretable Model-agnostic Explanations), to enhance transparency and facilitate understanding of model predictions. The experimental results indicate that SVM outperformed RF, demonstrating a higher accuracy in detecting depression from the social media data. In contrast to the majority of prior depression detection studies that primarily optimise for classification accuracy, the present work accords equal importance to model interpretability. We systematically applied the Local Interpretable Model-Agnostic Explanations (LIME) technique, enabling a granular examination of the decision-making processes. This approach facilitated the identification of linguistic markers associated with depressive symptomatology that exhibit strong concordance with established findings in psychological research, thereby enhancing the transparency, interpretability, and potential clinical trustworthiness of the proposed models.

Keywords: Mental Illness Detection, Natural Language Processing, machine learning, Explainable artificial intelligence, Local Interpretable Model-Agnostic Explanations (LIME)

Received: 14 May 2025; Accepted: 18 Aug 2025.

Copyright: © 2025 Hameed, Nauman, Akhtar, Fayyaz and Nawaz. This is an open-access article distributed under the terms of the Creative Commons Attribution License (CC BY). The use, distribution or reproduction in other forums is permitted, provided the original author(s) or licensor are credited and that the original publication in this journal is cited, in accordance with accepted academic practice. No use, distribution or reproduction is permitted which does not comply with these terms.

* Correspondence: Muhammad A B Fayyaz, Manchester Metropolitan University, Manchester, United Kingdom

Disclaimer: All claims expressed in this article are solely those of the authors and do not necessarily represent those of their affiliated organizations, or those of the publisher, the editors and the reviewers. Any product that may be evaluated in this article or claim that may be made by its manufacturer is not guaranteed or endorsed by the publisher.