--- 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:** \[[cloud@mindpadi.com](mailto:cloud@mindpadi.com)] * **GitHub:** \[github.com/mindpadi] *Last updated: May 2025*