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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 |
+
|
| 58 |
+
## β
Evaluation
|
| 59 |
+
|
| 60 |
+
- **Metrics:** Accuracy, F1-score (micro, macro), confusion matrix
|
| 61 |
+
- **Evaluation Script:** `training/evaluate_model.py`
|
| 62 |
+
- **Performance:**
|
| 63 |
+
- Accuracy: ~87%
|
| 64 |
+
- Macro F1: ~85%
|
| 65 |
+
- Robust across common emotional states like `sad`, `happy`, `angry`
|
| 66 |
+
- **Visualization:** See `lstm_accuracy_bert.png` for comparisons
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
## π¦ Files
|
| 71 |
+
|
| 72 |
+
The model directory includes:
|
| 73 |
+
|
| 74 |
+
| File | Purpose |
|
| 75 |
+
|------|---------|
|
| 76 |
+
| `config.json` | Model architecture configuration |
|
| 77 |
+
| `model.safetensors` | Trained model weights |
|
| 78 |
+
| `tokenizer.json`, `vocab.txt` | Tokenizer config |
|
| 79 |
+
| `merges.txt` (if BPE-based) | Byte-pair encoding rules |
|
| 80 |
+
| `checkpoint-*/` (optional) | Intermediate training checkpoints |
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
## π Example Usage
|
| 85 |
+
|
| 86 |
+
```python
|
| 87 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 88 |
+
import torch
|
| 89 |
+
|
| 90 |
+
model_name = "mindpadi/emotion_model"
|
| 91 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 92 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 93 |
+
|
| 94 |
+
text = "I feel so overwhelmed and tired."
|
| 95 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 96 |
+
outputs = model(**inputs)
|
| 97 |
+
predicted_class = torch.argmax(outputs.logits, dim=1).item()
|
| 98 |
+
|
| 99 |
+
print("Predicted emotion class:", predicted_class)
|
| 100 |
+
````
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
## π‘ Integration
|
| 105 |
+
|
| 106 |
+
Integrated in:
|
| 107 |
+
|
| 108 |
+
* `app/chatbot/emotion.py`: Emotion detection during each chat turn.
|
| 109 |
+
* `app/utils/analytics.py`: Aggregates emotions for weekly mood charts.
|
| 110 |
+
* `LangGraph`: Used in flow state personalization nodes.
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
## β οΈ Limitations
|
| 115 |
+
|
| 116 |
+
* **Bias:** May inherit cultural or gender biases from training data.
|
| 117 |
+
* **Language:** English only.
|
| 118 |
+
* **False Positives:** Sarcasm or ambiguous text may confuse predictions.
|
| 119 |
+
* **Not Clinical:** Should not be relied upon for medical-level emotional assessments.
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
## π§ββοΈ Ethical Considerations
|
| 124 |
+
|
| 125 |
+
* MindPadi informs users that they are interacting with AI.
|
| 126 |
+
* Emotion analysis is used only to guide and personalize chatbot responses.
|
| 127 |
+
* All usage must respect user privacy (see `app/tools/encryption.py` for encryption methods).
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
## π§© License
|
| 132 |
+
|
| 133 |
+
MIT License. You are free to use, modify, and distribute the model with attribution.
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
## π¬ Contact
|
| 138 |
+
|
| 139 |
+
* **Project:** [MindPadi Mental Health Chatbot](https://huggingface.co/mindpadi)
|
| 140 |
+
* **Author:** MindPadi Team
|
| 141 |
+
* **Email:** \[[[email protected]](mailto:[email protected])]
|
| 142 |
+
* **GitHub:** \[github.com/your-org/mindpadi]
|
| 143 |
+
|
| 144 |
+
*Last updated: May 2025*
|