File size: 4,212 Bytes
8d6c518
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
language:
- en
tags:
- emotion-detection
- mental-health
- classification
pipeline_tag: text-classification
---

# Emotion Detection Model for MindPadi (`emotion_model`)

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.



## 🧠 Model Summary

- **Task:** Emotion Classification
- **Architecture:** Transformer-based (likely BERT or DistilBERT)
- **Labels:** `happy`, `sad`, `angry`, `neutral`, `fearful`, `disgust`, `surprised`, etc.
- **Framework:** πŸ€— Transformers (PyTorch backend)
- **Use Case:** Core emotion recognition module in `app/chatbot/emotion.py`



## 🧾 Intended Use

### βœ”οΈ Primary Use Cases
- Detect user emotions in chat messages.
- Adjust response tone and therapy prompts in MindPadi.
- Support emotional trend tracking in mood analytics.

### 🚫 Not Recommended For
- Clinical diagnosis or treatment decisions.
- Emotion detection in highly formal or technical language (e.g., legal, medical).
- Non-English inputs (English-only training data).



## πŸ“š Training Details

- **Training Script:** `training/train_emotion_model.py`
- **Datasets:** A mix of publicly available emotion corpora (e.g., GoEmotions) and proprietary datasets stored in `training/datasets/`
- **Preprocessing:**
  - Cleaned for offensive language and class imbalance.
  - Tokenized using `AutoTokenizer` from Hugging Face Transformers.
- **Hyperparameters:**
  - Epochs: ~4–6
  - Batch Size: 16–32
  - Learning Rate: 2e-5 to 3e-5
- **Loss Function:** CrossEntropyLoss
- **Optimizer:** AdamW


## βœ… Evaluation

- **Metrics:** Accuracy, F1-score (micro, macro), confusion matrix
- **Evaluation Script:** `training/evaluate_model.py`
- **Performance:**
  - Accuracy: ~87%
  - Macro F1: ~85%
  - Robust across common emotional states like `sad`, `happy`, `angry`
- **Visualization:** See `lstm_accuracy_bert.png` for comparisons



## πŸ“¦ Files

The model directory includes:

| File | Purpose |
|------|---------|
| `config.json` | Model architecture configuration |
| `model.safetensors` | Trained model weights |
| `tokenizer.json`, `vocab.txt` | Tokenizer config |
| `merges.txt` (if BPE-based) | Byte-pair encoding rules |
| `checkpoint-*/` (optional) | Intermediate training checkpoints |



## πŸ” Example Usage

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

model_name = "mindpadi/emotion_model"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

text = "I feel so overwhelmed and tired."
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
predicted_class = torch.argmax(outputs.logits, dim=1).item()

print("Predicted emotion class:", predicted_class)
````



## πŸ’‘ Integration

Integrated in:

* `app/chatbot/emotion.py`: Emotion detection during each chat turn.
* `app/utils/analytics.py`: Aggregates emotions for weekly mood charts.
* `LangGraph`: Used in flow state personalization nodes.



## ⚠️ Limitations

* **Bias:** May inherit cultural or gender biases from training data.
* **Language:** English only.
* **False Positives:** Sarcasm or ambiguous text may confuse predictions.
* **Not Clinical:** Should not be relied upon for medical-level emotional assessments.



## πŸ§‘β€βš–οΈ Ethical Considerations

* MindPadi informs users that they are interacting with AI.
* Emotion analysis is used only to guide and personalize chatbot responses.
* All usage must respect user privacy (see `app/tools/encryption.py` for encryption methods).



## 🧩 License

MIT License. You are free to use, modify, and distribute the model with attribution.



## πŸ“¬ Contact

* **Project:** [MindPadi Mental Health Chatbot](https://huggingface.co/mindpadi)
* **Author:** MindPadi Team
* **Email:** \[[[email protected]](mailto:[email protected])]
* **GitHub:** \[github.com/mindpadi]

*Last updated: May 2025*