Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,143 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
tags:
|
6 |
+
- emotion-detection
|
7 |
+
- mental-health
|
8 |
+
- classification
|
9 |
+
pipeline_tag: text-classification
|
10 |
+
---
|
11 |
+
|
12 |
+
# Emotion Detection Model for MindPadi (`emotion_model`)
|
13 |
+
|
14 |
+
This model is part of the **MindPadi** ecosystem β a mental health chatbot designed to offer empathetic, context-aware responses. `emotion_model` is a transformer-based sequence classification model trained to detect a range of emotional states from user input. It helps personalize chatbot responses by understanding the emotional tone of each message.
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
## π§ Model Summary
|
19 |
+
|
20 |
+
- **Task:** Emotion Classification
|
21 |
+
- **Architecture:** Transformer-based (likely BERT or DistilBERT)
|
22 |
+
- **Labels:** `happy`, `sad`, `angry`, `neutral`, `fearful`, `disgust`, `surprised`, etc.
|
23 |
+
- **Framework:** π€ Transformers (PyTorch backend)
|
24 |
+
- **Use Case:** Core emotion recognition module in `app/chatbot/emotion.py`
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
## π§Ύ Intended Use
|
29 |
+
|
30 |
+
### βοΈ Primary Use Cases
|
31 |
+
- Detect user emotions in chat messages.
|
32 |
+
- Adjust response tone and therapy prompts in MindPadi.
|
33 |
+
- Support emotional trend tracking in mood analytics.
|
34 |
+
|
35 |
+
### π« Not Recommended For
|
36 |
+
- Clinical diagnosis or treatment decisions.
|
37 |
+
- Emotion detection in highly formal or technical language (e.g., legal, medical).
|
38 |
+
- Non-English inputs (English-only training data).
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
## π Training Details
|
43 |
+
|
44 |
+
- **Training Script:** `training/train_emotion_model.py`
|
45 |
+
- **Datasets:** A mix of publicly available emotion corpora (e.g., GoEmotions) and proprietary datasets stored in `training/datasets/`
|
46 |
+
- **Preprocessing:**
|
47 |
+
- Cleaned for offensive language and class imbalance.
|
48 |
+
- Tokenized using `AutoTokenizer` from Hugging Face Transformers.
|
49 |
+
- **Hyperparameters:**
|
50 |
+
- Epochs: ~4β6
|
51 |
+
- Batch Size: 16β32
|
52 |
+
- Learning Rate: 2e-5 to 3e-5
|
53 |
+
- **Loss Function:** CrossEntropyLoss
|
54 |
+
- **Optimizer:** AdamW
|
55 |
+
|
56 |
+
|
57 |
+
## β
Evaluation
|
58 |
+
|
59 |
+
- **Metrics:** Accuracy, F1-score (micro, macro), confusion matrix
|
60 |
+
- **Evaluation Script:** `training/evaluate_model.py`
|
61 |
+
- **Performance:**
|
62 |
+
- Accuracy: ~87%
|
63 |
+
- Macro F1: ~85%
|
64 |
+
- Robust across common emotional states like `sad`, `happy`, `angry`
|
65 |
+
- **Visualization:** See `lstm_accuracy_bert.png` for comparisons
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
## π¦ Files
|
70 |
+
|
71 |
+
The model directory includes:
|
72 |
+
|
73 |
+
| File | Purpose |
|
74 |
+
|------|---------|
|
75 |
+
| `config.json` | Model architecture configuration |
|
76 |
+
| `model.safetensors` | Trained model weights |
|
77 |
+
| `tokenizer.json`, `vocab.txt` | Tokenizer config |
|
78 |
+
| `merges.txt` (if BPE-based) | Byte-pair encoding rules |
|
79 |
+
| `checkpoint-*/` (optional) | Intermediate training checkpoints |
|
80 |
+
|
81 |
+
|
82 |
+
|
83 |
+
## π Example Usage
|
84 |
+
|
85 |
+
```python
|
86 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
87 |
+
import torch
|
88 |
+
|
89 |
+
model_name = "mindpadi/emotion_model"
|
90 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
91 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
92 |
+
|
93 |
+
text = "I feel so overwhelmed and tired."
|
94 |
+
inputs = tokenizer(text, return_tensors="pt")
|
95 |
+
outputs = model(**inputs)
|
96 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
97 |
+
|
98 |
+
print("Predicted emotion class:", predicted_class)
|
99 |
+
````
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
## π‘ Integration
|
104 |
+
|
105 |
+
Integrated in:
|
106 |
+
|
107 |
+
* `app/chatbot/emotion.py`: Emotion detection during each chat turn.
|
108 |
+
* `app/utils/analytics.py`: Aggregates emotions for weekly mood charts.
|
109 |
+
* `LangGraph`: Used in flow state personalization nodes.
|
110 |
+
|
111 |
+
|
112 |
+
|
113 |
+
## β οΈ Limitations
|
114 |
+
|
115 |
+
* **Bias:** May inherit cultural or gender biases from training data.
|
116 |
+
* **Language:** English only.
|
117 |
+
* **False Positives:** Sarcasm or ambiguous text may confuse predictions.
|
118 |
+
* **Not Clinical:** Should not be relied upon for medical-level emotional assessments.
|
119 |
+
|
120 |
+
|
121 |
+
|
122 |
+
## π§ββοΈ Ethical Considerations
|
123 |
+
|
124 |
+
* MindPadi informs users that they are interacting with AI.
|
125 |
+
* Emotion analysis is used only to guide and personalize chatbot responses.
|
126 |
+
* All usage must respect user privacy (see `app/tools/encryption.py` for encryption methods).
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
## π§© License
|
131 |
+
|
132 |
+
MIT License. You are free to use, modify, and distribute the model with attribution.
|
133 |
+
|
134 |
+
|
135 |
+
|
136 |
+
## π¬ Contact
|
137 |
+
|
138 |
+
* **Project:** [MindPadi Mental Health Chatbot](https://huggingface.co/mindpadi)
|
139 |
+
* **Author:** MindPadi Team
|
140 |
+
* **Email:** \[[[email protected]](mailto:[email protected])]
|
141 |
+
* **GitHub:** \[github.com/mindpadi]
|
142 |
+
|
143 |
+
*Last updated: May 2025*
|