File size: 5,845 Bytes
978a384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13fec06
 
 
 
 
 
 
 
978a384
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
---
language: ["en"]
license: mit
tags:
  - mental-health
  - bert
  - text-classification
  - nlp
  - transformers
  - explainable-ai
  - shap
datasets:
  - kaggle-sentiment-analysis-mental-health
metrics:
  - accuracy
  - f1
---

 # 🧠 MindSense-BERT β€” AI-Powered Mental Health Detection
![Python](https://img.shields.io/badge/Python-3.10-blue?style=flat-square&logo=python)
![BERT](https://img.shields.io/badge/Model-BERT-orange?style=flat-square)
![Accuracy](https://img.shields.io/badge/Accuracy-89%25-green?style=flat-square)
![Streamlit](https://img.shields.io/badge/UI-Streamlit-red?style=flat-square&logo=streamlit)
![HuggingFace](https://img.shields.io/badge/HuggingFace-Model-yellow?style=flat-square)
![License](https://img.shields.io/badge/License-MIT-lightgrey?style=flat-square)
---
MindSense-BERT is a fine-tuned BERT-based model designed to **classify text into 7 mental health categories** using real-world Reddit data.
It combines **state-of-the-art NLP, class imbalance handling, and explainable AI (SHAP)** to create a transparent and practical mental health analysis system.

---

## πŸ“Œ Model Overview

* **Model Type:** Transformer (BERT)

* **Base Model:** `bert-base-uncased`

* **Task:** Multi-class Text Classification

* **Classes (7):**

  * Normal
  * Depression
  * Anxiety
  * Bipolar
  * PTSD
  * Stress
  * Personality Disorder

* **Framework:** PyTorch + Hugging Face Transformers

* **Deployment:** Streamlit + Hugging Face Hub

---

## 🎯 Problem Statement

Mental health conditions affect **1 in 4 people globally**, but early detection is difficult due to stigma and lack of awareness.

This model aims to:

* Analyze user-written text
* Detect potential mental health conditions
* Enable early awareness and intervention

---

## πŸ“Š Dataset

* **Source:** Kaggle β€” *Sentiment Analysis for Mental Health*
* **Size:** 53,000+ Reddit posts
* **Input:** `statement` (text)
* **Label:** `status` (mental health category)

### Categories:

* Normal
* Depression
* Anxiety
* Bipolar
* PTSD
* Stress
* Personality Disorder

---

## βš™οΈ Preprocessing

* Removed URLs, special characters, duplicates
* Handled missing values
* Tokenized using BERT tokenizer
* Lowercasing (uncased model)
* Padding & truncation applied

---

## πŸ”¬ Training Methodology

### Phase 1 β€” Baseline Models

* TF-IDF (10k features, uni + bi-grams)
* Logistic Regression, Random Forest, SVM

### Phase 2 β€” BERT Fine-tuning

* Pretrained `bert-base-uncased`
* 3 epochs
* Learning rate: `1e-5`
* Batch size: `16`
* Trained on Google Colab T4 GPU

---

### Phase 3 β€” Class Imbalance Handling

* Weak classes identified: Stress, Personality Disorder
* Techniques used:

  * Word swap
  * Random deletion
  * Key phrase duplication
* Applied custom class weights

---

## πŸ“ˆ Model Performance

### Accuracy Comparison

| Model               | Accuracy    |
| ------------------- | ----------- |
| Logistic Regression | ~78%        |
| Random Forest       | ~74%        |
| SVM                 | ~82%        |
| BERT (initial)      | ~83%        |
| **BERT (final)**    | **~87–89%** |

---

### Per-Class F1 Score

| Category             | F1 Score |
| -------------------- | -------- |
| Normal               | 0.91     |
| Depression           | 0.89     |
| Anxiety              | 0.86     |
| Bipolar              | 0.84     |
| PTSD                 | 0.87     |
| Stress               | 0.82     |
| Personality Disorder | 0.80     |

---

## πŸ” Explainability (SHAP)

This model integrates **SHAP (SHapley Additive Explanations)** for transparency:

* πŸ”΄ Red words β†’ push prediction toward a class
* πŸ”΅ Blue words β†’ push prediction away

This improves trust and interpretability β€” critical in healthcare AI.

---

## πŸš€ Usage

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_name = "maitry30/mindsense-bert"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

text = "I feel completely hopeless and empty."

inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)

prediction = torch.argmax(outputs.logits, dim=1).item()
print(prediction)
```

---

## πŸ§ͺ Example Predictions

| Input Text                  | Predicted Class |
| --------------------------- | --------------- |
| "I feel hopeless and empty" | Depression      |
| "I keep having nightmares"  | PTSD            |
| "My mood swings a lot"      | Bipolar         |
| "I feel fine today"         | Normal          |

---

## πŸ›  Tech Stack

* Python 3.10
* PyTorch
* Hugging Face Transformers
* Scikit-learn
* SHAP
* Pandas, NumPy
* Matplotlib, Seaborn
* Streamlit (UI)
* Hugging Face Hub (model hosting)

---

## ⚠️ Limitations

* Limited to English text
* May struggle with sarcasm or slang
* Depends on dataset quality
* Not suitable for real clinical diagnosis

---

## βš–οΈ Ethical Considerations

* This model is for **educational purposes only**
* Not a replacement for mental health professionals
* Should not be used for medical decisions
* Predictions require human interpretation

---

## πŸ” Safety Notice

* ❌ Not a diagnostic tool
* ❌ Not for emergency use
* βœ… Can assist awareness and research

---

## πŸš€ Future Work

* Multilingual support (Hindi + regional languages)
* Voice-based mental health detection
* Multi-modal AI (text + physiological signals)
* Explainable AI improvements
* Production deployment (AWS/Azure)

---

## πŸ‘€ Author

**Maitry**

* GitHub: https://github.com/Maitry09/mindsense-mental-health
* Hugging Face: https://huggingface.co/maitry30
* Live App: https://mindsense.streamlit.app

---

## πŸ“„ License

MIT License

---

> ⭐ If you found this model useful, consider giving the project a star!