Skip to content

Deep learning models and fine-tuned transformers for detecting mental illness from user content on Reddit. 🧠

License

Notifications You must be signed in to change notification settings

GeorgiosIoannouCoder/mindscanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn GitHub

Analyzing Mental Health Posts on Social Media: A Deep Learning Approach to Reddit Post Classification


Logo

MINDSCANNER

This project aims to predict a user’s potential mental health condition based on the sentiment and linguistic cues found in Reddit posts. Social media platforms, particularly Reddit, are widely used for expressing emotions and seeking support, often anonymously. Users frequently share personal experiences that may indicate underlying mental health issues such as autism, anxiety, bipolar disorder, borderline personality disorder, dpression, schizophrenia.

To address this, we developed and evaluated deep learning models, including both models built from scratch and fine-tuned transformer-based models. These models were trained on labeled data from dedicated mental health subreddits and optimized for classifying the specific condition associated with each post. We trained and evaluated our models and fine-tuned transformer-based models on two versions of the original data. The first version where we did the cleaning which can found by running the code here and and second version where we apply the transformation on the clean version of the data which can be found by running the code here.

Our work contributes to the field of public mental health by leveraging user-generated content to identify potential mental health conditions. Beyond academic value, this project has real-world implications for improving online mental health support. By accurately classifying Reddit posts according to specific mental health conditions, our models can help guide users toward the most appropriate subreddit communities, where they are more likely to receive relevant support, shared experiences, and information. This can enhance early detection, reduce miscommunication, and improve users’ chances of accessing the right resources or treatment pathways within these online communities.

In total, four models from scratch were developed and two transformer models were fine-tuned and compared to identify the most effective architecture for detecting a user’s potential mental health condition based on the sentiment and linguistic cues found in Reddit posts. Our best-performing model, a BERT fine-tuned model, achieved an accuracy of 87.3% on the test set, demonstrating that fine-tuned models can perform better than models build from scratch with minimal code.
Explore the docs »

Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started With Georgios Ioannou Code
  3. Getting Started With Zechen Yang Code
  4. Usage
  5. Code With Plotly Graphs
  6. Paper
  7. Contributing
  8. License
  9. Contact

About The Project

Logo

Tasks

Tasks
Create Github Repository
Brainstorm Project
Find Dataset
EDA
Data Preprocessing and Cleaning
Data Modeling: BiLSTM, CNN+BiLSTM, CNN, BiGRU
Fine-Tune: BERT, MISTRAL-7B
Model Evaluation
Write Paper

Back to top

Dataset

Subreddits Dataset For NLP

  • 3 Columns:
    • Title
    • Text
    • Subreddit
  • 488,472 rows
  • 7 Classes:
    • depression: 58496
    • anxiety: 86243
    • bipolar: 41493
    • mentalhealth: 39373
    • bpd: 38216
    • schizophrenia: 17506
    • autism: 7142
  • 2 Versions of Data:
    • Version 1: Clean
    • Version 2: Clean + Transform

Back to top

Cleaning

Please note that in our pre-processing we excluded the class "mentalhealth" as it is a more generic class and our models performed better without it.

Moreover, we combine the title and text to form our X and use bureddit as our y.

Data Cleaning Diagram

Back to top

Transformation

Please note that in our pre-processing we excluded the class "mentalhealth" as it is a more generic class and our models performed better without it.

Moreover, we combine the title and text to form our X and use bureddit as our y.

Transformation Steps:

  • Synonym Replacement
  • For words longer than 3 characters, there's a 10% chance they'll be replaced with synonyms
  • Random Typos
  • For words longer than 3 characters, there's a 10% chance of introducing a typing error

Back to top

Models Built With Version 1 of The Original Data

  1. Bidirectional Long Short-Term Memory (BiLSTM)
  2. Convolutional Neural Network (CNN)
  3. CNN + BiLSTM
  4. Bidirectional Gated Recurrent Unit (BiGRU)

Back to top

Models Built With Version 2 of The Original Data

  1. Bidirectional Long Short-Term Memory (BiLSTM)
  2. Convolutional Neural Network (CNN)
  3. CNN + BiLSTM
  4. Bidirectional Gated Recurrent Unit (BiGRU)

Back to top

Models Performance

Performance Metrics on Version 1 of Data

Model Accuracy (%) Precision (%) Recall (%) F1 (%)
BiLSTM 85.3 85.3 85.3 85.3
CNN + BiLSTM 84.7 84.7 84.7 84.7
CNN 84.1 84.1 84.1 84.1
BiGRU 85.2 85.2 85.2 85.2
BERT 86.4 86.4 86.4 86.1

Performance Metrics on Version 2 of Data

Model Accuracy (%) Precision (%) Recall (%) F1 (%)
BiLSTM 84.5 84.5 84.5 84.5
CNN + BiLSTM 83.8 83.8 83.8 83.8
CNN 83.3 83.3 83.3 83.3
BiGRU 84.6 84.6 84.6 84.6
BERT 83 81 79 80

Performance Metrics on Version 2 of Data With Balanced Classes

Model Accuracy (%) Precision (%) Recall (%) F1 (%)
BERT 87.3 87.5 87.1 87.3
Mistral7b 69.9 76.6 69.5 70.8

Back to top

Evaluation Metrics Used

  1. Classification Report
    • Precision
    • Recall
    • F1-score
    • Accuracy
    • Macro average
    • Weighted average
  2. Confusion Matrix
  3. ROC Curve
  4. Precision-Recall Curve

Back to top

Models Weights

Please contact me at [email protected] to get the models weights as they were too large to be uploaded in this GitHub repository.

Back to top

Inference Example

Inference Example

Back to top

Built With

Python Pandas Numpy scikitlearn Nltk Pytorch Tensorflow Matplotlib Seaborn Plotly Tensordock

Back to top

Getting Started With Georgios Ioannou Code

NOTE: This code was run on a cloud GPU server from Tensordock with these specifications:

  • 1x h100-sxm5-80gb
  • 20x vCPUs
  • 64GB RAM
  • 300GB NVME STORAGE

To get a local copy of MINDSCANNER Georgios Ioannou code up and running locally follow these simple example steps:

Prerequisites

NOTE: How to check if Python is installed and what is its version

  python --version

NOTE: How to check if Git is installed and what is its version

  git -v
  1. Please make sure you have pyenv installed and use Python3 version 3.12.7:

  2. Please make sure you have git installed

  3. Please make sure you have Anaconda installed

Setup

  1. Navigate to the directory where you want to clone/run/save the application:

    cd your_selected_directory
  2. Clone this repository:

    git clone https://github.com/GeorgiosIoannouCoder/mindscanner.git
  3. Navigate to the mindscanner git repository:

    cd mindscanner
  4. Create a new conda environment in the cloned repository folder:

    conda env create -f environment.yml
  5. Activate the conda environment:

    conda activate mindscanner-venv
  6. To Run The Jupyter Notebook and Code Files on GPU (2 Main Options):

    1. Use Kaggle - Free
    2. Rent a cloud GPU server like Tensordock and SSH to Jupyter Notebook Extension for VS Code - NOT Free
  7. The Jupyter Notebook here can be run step by step as it include the entire code for the follwoing models: BiLSTM, CNN + BiLSTM, CNN, and BiGRU.

  8. In case you just want to clean the data use the code here and in case you aslo want to transform it, then use the code here. Please note that you first have to clean adn then transform as the transformation hasppens on the cleaned data.

Back to top

Getting Started With Zechen Yang Code

  • To get a local copy of MINDSCANNER Zechen Yang BERT code up and running locally follow these simple example steps here.

  • To get a local copy of MINDSCANNER Zechen Yang MISTRAL-7B code up and running locally follow these simple example steps here.

Back to top

Code With Plotly Graphs

The full code for BiLSTM, CNN + BiLSTM, CNN, and BiGRU with all the Plotly interactive graphs can be found here. In case you have issues opening it is due to the fact that there is a lot of output making the .ipynb file size large. That is why it was uploaded with git lfs. The solution is to download the .ipynb here and open it locally.

Back to top

Paper

Project Final Paper is located here.

Back to top

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Back to top

License

Distributed under the MIT License. See LICENSE for more information.

MIT License

Copyright (c) 2025 Georgios Ioannou

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Back to top

Contact

Georgios Ioannou - @LinkedIn

Project Link: https://github.com/GeorgiosIoannouCoder/mindscanner

Back to top