Update README.md
Browse files
README.md
CHANGED
@@ -2,269 +2,128 @@
|
|
2 |
license: mit
|
3 |
language:
|
4 |
- en
|
5 |
-
base_model:
|
6 |
-
- openai-community/gpt2
|
7 |
-
- distilbert/distilgpt2
|
8 |
-
pipeline_tag: text-generation
|
9 |
tags:
|
10 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
# 🧠
|
14 |
|
15 |
-
This
|
16 |
|
17 |
|
18 |
-
##
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
-
|
23 |
-
-
|
24 |
-
-
|
25 |
-
|
26 |
-
-
|
27 |
-
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
|
31 |
-
##
|
32 |
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
- 🗣️ Text generation
|
36 |
-
- 🎭 Emotion detection
|
37 |
-
- 🎯 Intent classification
|
38 |
-
- 📊 Sentence embedding
|
39 |
|
40 |
-
Models are stored in the `models/` directory and published to the Hugging Face Hub for scalable inference.
|
41 |
|
|
|
42 |
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
- **Description**: Pre-trained DistilGPT-2 for text generation
|
48 |
-
- **Task**: Text Generation
|
49 |
-
- **Architecture**: 6-layer transformer (82M params)
|
50 |
-
- **Use Case**: Default conversational model
|
51 |
-
|
52 |
-
|
53 |
-
### 🔹 `fine_tuned_distilgpt2_lora`
|
54 |
-
|
55 |
-
- **Description**: DistilGPT-2 fine-tuned using LoRA for mental health contexts
|
56 |
-
- **Training Script**: `training/finetune_distilgpt2_lora.py`
|
57 |
-
- **Use Case**: Therapy-specific generation
|
58 |
-
|
59 |
-
|
60 |
-
### 🔹 `fine_tuned_gpt2`
|
61 |
-
|
62 |
-
- **Description**: GPT-2 fine-tuned for rich and context-aware dialogues
|
63 |
-
- **Architecture**: GPT-2 (124M params)
|
64 |
-
- **Training Script**: `training/finetune_gpt2_pipeline.py`
|
65 |
-
|
66 |
-
|
67 |
-
### 🔹 `merged_distilgpt2`
|
68 |
-
|
69 |
-
- **Description**: Optimized DistilGPT-2 with merged fine-tuned weights
|
70 |
-
- **Use Case**: Fallback generation model
|
71 |
-
|
72 |
-
|
73 |
-
### 🔹 `gpt2`
|
74 |
-
|
75 |
-
- **Description**: Raw GPT-2 as a baseline model
|
76 |
-
- **Source**: Hugging Face Transformers
|
77 |
-
|
78 |
-
|
79 |
-
### 🔹 `emotion_classifier`
|
80 |
-
|
81 |
-
- **Task**: Emotion Classification (e.g., joy, sadness, anger)
|
82 |
-
- **Training Script**: `training/train_emotion_model.py`
|
83 |
-
- **Use Case**: Used in `app/chatbot/emotion.py`
|
84 |
-
|
85 |
-
|
86 |
-
### 🔹 `emotion_model`
|
87 |
-
|
88 |
-
- **Description**: Variant or backup for emotion analysis
|
89 |
-
|
90 |
-
|
91 |
-
### 🔹 `intent_classifier`
|
92 |
-
|
93 |
-
- **Task**: User intent detection (e.g., schedule, vent, help)
|
94 |
-
- **Training Script**: `training/train_intent_classifier.py`
|
95 |
-
- **Use Case**: `app/chatbot/intent_classifier.py`
|
96 |
-
|
97 |
-
|
98 |
-
### 🔹 `intent_encoder`
|
99 |
-
|
100 |
-
- **Description**: Sentence-BERT used to embed user input
|
101 |
-
- **Use Case**: Vector search in `app/utils/embedding_search.py`
|
102 |
-
|
103 |
-
|
104 |
-
### 🔹 `intent_fallback`
|
105 |
-
|
106 |
-
- **Description**: Fallback model for intent classification errors
|
107 |
-
|
108 |
-
|
109 |
-
### 🔹 `sentence_transformer`
|
110 |
-
|
111 |
-
- **Architecture**: Sentence-BERT (e.g., all-MiniLM-L6-v2)
|
112 |
-
- **Use Case**: Text embedding for similarity queries
|
113 |
-
|
114 |
-
|
115 |
-
## 🎯 Intended Use
|
116 |
-
|
117 |
-
These models are intended for use in:
|
118 |
-
|
119 |
-
- Conversational therapy interfaces
|
120 |
-
- Mental health chatbots
|
121 |
-
- Emotion-aware agents
|
122 |
-
- Intent-based routing systems
|
123 |
-
|
124 |
-
### 👥 Primary Users:
|
125 |
-
|
126 |
-
- End-users of the MindPadi mental health app
|
127 |
-
- Developers integrating AI into mental health tools
|
128 |
-
|
129 |
-
### 🚫 Out-of-Scope:
|
130 |
-
|
131 |
-
- Medical diagnosis
|
132 |
-
- Legal/financial decision-making
|
133 |
-
- Non-mental health chatbots without validation
|
134 |
-
|
135 |
-
|
136 |
-
## 🛠 Training Details
|
137 |
-
|
138 |
-
### 🧾 Datasets
|
139 |
-
|
140 |
-
- Location: `training/datasets/`
|
141 |
-
- Intents: Stored in `data/processed_intents.json`
|
142 |
-
- Processing scripts: `process_conversation_data.py`, `convert_intents_format.py`
|
143 |
-
|
144 |
-
### 💻 Environment
|
145 |
-
|
146 |
-
- Hardware: NVIDIA GPUs (local/cloud)
|
147 |
-
- Pretrained models: from Hugging Face
|
148 |
-
- Fine-tuned models: custom scripts
|
149 |
-
|
150 |
-
### 🔧 Scripts Used
|
151 |
-
|
152 |
-
| Model | Script |
|
153 |
-
|-------|--------|
|
154 |
-
| LoRA GPT-2 | `training/finetune_distilgpt2_lora.py` |
|
155 |
-
| Fine-tuned GPT-2 | `training/finetune_gpt2_pipeline.py` |
|
156 |
-
| Emotion Classifier | `training/train_emotion_model.py` |
|
157 |
-
| Intent Classifier | `training/train_intent_classifier.py` |
|
158 |
-
|
159 |
-
|
160 |
-
## 📊 Evaluation
|
161 |
-
|
162 |
-
### ✅ Metrics
|
163 |
-
|
164 |
-
- **Text Gen**: Perplexity, BLEU
|
165 |
-
- **Classification**: Accuracy, F1-score
|
166 |
-
|
167 |
-
### 📈 Results
|
168 |
-
|
169 |
-
- Emotion classifier: High accuracy
|
170 |
-
- Fine-tuned GPT models: Better than baseline
|
171 |
-
- Evaluation logs: `logs/training.log`, TensorBoard
|
172 |
-
|
173 |
-
|
174 |
-
## ⚠ Limitations
|
175 |
-
|
176 |
-
- **Bias**: Possible due to training data
|
177 |
-
- **Generalization**: May fail on out-of-domain text
|
178 |
-
- **Language**: Only English supported
|
179 |
-
- **Inference Cost**: Large models require GPU memory
|
180 |
-
- **Safety**: Human monitoring is recommended
|
181 |
|
|
|
182 |
|
183 |
-
|
184 |
|
185 |
-
|
|
|
186 |
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
pip install transformers huggingface_hub requests
|
191 |
-
```
|
192 |
|
|
|
|
|
193 |
|
194 |
-
###
|
195 |
|
196 |
```python
|
197 |
-
from
|
198 |
-
|
199 |
-
model = AutoModelForCausalLM.from_pretrained("mindpadi/distilgpt2")
|
200 |
-
tokenizer = AutoTokenizer.from_pretrained("mindpadi/distilgpt2")
|
201 |
|
202 |
-
|
203 |
-
|
|
|
204 |
|
205 |
-
print(
|
206 |
```
|
207 |
|
208 |
|
209 |
-
### 😢 Example: Emotion Classification
|
210 |
|
211 |
-
|
212 |
-
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
213 |
|
214 |
-
|
215 |
-
|
|
|
|
|
|
|
216 |
|
217 |
-
|
218 |
-
outputs = model(**inputs)
|
219 |
|
220 |
-
|
221 |
-
|
222 |
|
223 |
|
224 |
-
### 🌐 Using Inference Endpoints
|
225 |
|
226 |
-
|
227 |
-
import requests
|
228 |
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
"Content-Type": "application/json"
|
233 |
-
}
|
234 |
-
payload = {"inputs": "What should I do when I'm anxious?"}
|
235 |
|
236 |
-
res = requests.post(url, json=payload, headers=headers)
|
237 |
-
print(res.json())
|
238 |
-
```
|
239 |
|
240 |
|
241 |
-
|
242 |
|
243 |
-
|
244 |
-
| ---------------------------------- | ------------------------------------- |
|
245 |
-
| `app/chatbot/core.py` | Text generation |
|
246 |
-
| `app/chatbot/emotion.py` | `emotion_classifier` |
|
247 |
-
| `app/chatbot/intent_classifier.py` | `intent_classifier`, `intent_encoder` |
|
248 |
-
| `app/utils/embedding_search.py` | `sentence_transformer` |
|
249 |
|
|
|
|
|
|
|
250 |
|
251 |
-
## 🧩 Ethical Considerations
|
252 |
|
253 |
-
* **Supportive, Not Diagnostic**: Not a replacement for therapy
|
254 |
-
* **Bias Risk**: Model outputs may contain implicit bias
|
255 |
-
* **Data Privacy**: User data must be anonymized
|
256 |
-
* **Transparency**: Clearly inform users they're chatting with AI
|
257 |
|
|
|
258 |
|
259 |
-
|
|
|
|
|
260 |
|
261 |
-
* 📧 Email: [admin@mindpad.com](admin@mindpad.com)
|
262 |
-
* 🔗 GitHub: [MindPadi](https://github.com/MindPadi)
|
263 |
-
* 🤗 Hugging Face: [https://huggingface.co/mindpadi](https://huggingface.co/mindpadi)
|
264 |
|
265 |
|
266 |
## 📄 License
|
267 |
|
268 |
-
|
269 |
-
|
270 |
-
*
|
|
|
2 |
license: mit
|
3 |
language:
|
4 |
- en
|
|
|
|
|
|
|
|
|
5 |
tags:
|
6 |
+
- intent-classification
|
7 |
+
- emotion-detection
|
8 |
+
- mental-health
|
9 |
+
- lstm
|
10 |
+
- sentence-transformers
|
11 |
+
- sklearn
|
12 |
+
pipeline_tag: text-classification
|
13 |
---
|
14 |
|
15 |
+
# 🧠 MindPadi: Hybrid Classifier Suite
|
16 |
|
17 |
+
This repository contains auxiliary models for intent and emotion classification used in the **MindPadi** mental health assistant. These models include rule-based, ML-based, and deep learning classifiers trained to detect emotional states, user intent, and conversational cues.
|
18 |
|
19 |
|
20 |
+
## 📦 Files
|
21 |
|
22 |
+
| File | Description |
|
23 |
+
|-------------------------------|----------------------------------------------------------|
|
24 |
+
| `intent_clf.joblib` | scikit-learn pipeline for intent classification (TF-IDF) |
|
25 |
+
| `intent_sentence_classifier.pkl` | Sentence-level intent classifier (pickle) |
|
26 |
+
| `lstm_tfidf.h5` | LSTM model trained on TF-IDF vectors |
|
27 |
+
| `lstm_bert.h5` | LSTM model trained on BERT embeddings |
|
28 |
+
| `tfidf_vectorizer.pkl` | TF-IDF vectorizer for preprocessing text |
|
29 |
+
| `tfidf_embeddings.pkl` | Cached TF-IDF embeddings for faster lookup |
|
30 |
+
| `bert_embeddings.npy` | Precomputed BERT embeddings used in training/testing |
|
31 |
+
| `lstm_accuracy_tfidf.png` | Evaluation plot (TF-IDF model) |
|
32 |
+
| `lstm_accuracy_bert.png` | Evaluation plot (BERT model) |
|
33 |
+
| `model_configs/` | JSON configs for training and architecture |
|
34 |
|
35 |
|
36 |
+
## 🎯 Tasks Supported
|
37 |
|
38 |
+
- **Intent Classification**: Understand what the user is trying to communicate.
|
39 |
+
- **Emotion Detection**: Identify the emotional tone (e.g., sad, angry).
|
40 |
+
- **Embedding Generation**: Support vector similarity or hybrid routing.
|
41 |
|
|
|
|
|
|
|
|
|
42 |
|
|
|
43 |
|
44 |
+
## 🔬 Model Overview
|
45 |
|
46 |
+
| Model Type | Framework | Notes |
|
47 |
+
|----------------|-------------|----------------------------------------|
|
48 |
+
| LSTM + TF-IDF | Keras | Traditional pipeline with good generalization |
|
49 |
+
| LSTM + BERT | Keras | Handles contextual sentence meanings |
|
50 |
+
| TF-IDF + SVM | scikit-learn | Lightweight and interpretable intent routing |
|
51 |
+
| Sentence Classifier | scikit-learn | Quick rule or decision-tree model for sentence-level labels |
|
52 |
|
53 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
55 |
+
## 🛠️ Usage Example
|
56 |
|
57 |
+
### Intent Prediction (Joblib)
|
58 |
|
59 |
+
```python
|
60 |
+
from joblib import load
|
61 |
|
62 |
+
clf = load("intent_clf.joblib")
|
63 |
+
text = ["I feel really anxious today"]
|
64 |
+
pred = clf.predict(text)
|
|
|
|
|
65 |
|
66 |
+
print("Intent:", pred[0])
|
67 |
+
````
|
68 |
|
69 |
+
### LSTM Emotion Prediction
|
70 |
|
71 |
```python
|
72 |
+
from tensorflow.keras.models import load_model
|
73 |
+
import numpy as np
|
|
|
|
|
74 |
|
75 |
+
model = load_model("lstm_bert.h5")
|
76 |
+
embeddings = np.load("bert_embeddings.npy") # assuming aligned with test set
|
77 |
+
output = model.predict(embeddings)
|
78 |
|
79 |
+
print("Predicted emotion class:", output.argmax(axis=1))
|
80 |
```
|
81 |
|
82 |
|
|
|
83 |
|
84 |
+
## 📊 Evaluation
|
|
|
85 |
|
86 |
+
| Model | Accuracy | Dataset Size | Notes |
|
87 |
+
| ------------------- | -------- | ------------ | -------------------------------- |
|
88 |
+
| `lstm_bert.h5` | \~88% | 10,000+ | Best for nuanced emotional input |
|
89 |
+
| `lstm_tfidf.h5` | \~83% | 10,000+ | Lighter, faster |
|
90 |
+
| `intent_clf.joblib` | \~90% | 8,000+ | Works well with short queries |
|
91 |
|
92 |
+
Evaluation visualizations:
|
|
|
93 |
|
94 |
+
* 
|
95 |
+
* 
|
96 |
|
97 |
|
|
|
98 |
|
99 |
+
## ⚠️ Limitations
|
|
|
100 |
|
101 |
+
* English only
|
102 |
+
* May misclassify ambiguous or sarcastic phrases
|
103 |
+
* LSTM models require matching vectorizer or embeddings
|
|
|
|
|
|
|
104 |
|
|
|
|
|
|
|
105 |
|
106 |
|
107 |
+
## 🧩 Integration
|
108 |
|
109 |
+
These models are invoked in:
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
+
* `app/chatbot/intent_classifier.py`
|
112 |
+
* `app/chatbot/emotion.py`
|
113 |
+
* `app/utils/embedding_search.py`
|
114 |
|
|
|
115 |
|
|
|
|
|
|
|
|
|
116 |
|
117 |
+
## 🧠 Intended Use
|
118 |
|
119 |
+
* Mental health journaling feedback
|
120 |
+
* Chatbot-based emotion understanding
|
121 |
+
* Offline fallback for heavy transformer models
|
122 |
|
|
|
|
|
|
|
123 |
|
124 |
|
125 |
## 📄 License
|
126 |
|
127 |
+
MIT License – free for commercial and research use.
|
128 |
+
|
129 |
+
*Last updated: May 6, 2025*
|