Upload 7 files
Browse files- README.md +155 -0
- config.json +79 -0
- pytorch_model.bin +3 -0
- requirements.txt +3 -0
- special_tokens_map.json +7 -0
- tokenizer_config.json +58 -0
- vocab.txt +0 -0
README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
| 1 |
---
|
| 2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- emotion-classification
|
| 5 |
+
- mental-health
|
| 6 |
+
- multi-label
|
| 7 |
+
- transformers
|
| 8 |
+
- distilbert
|
| 9 |
+
- goemotions
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
metrics:
|
| 13 |
+
- f1
|
| 14 |
+
- precision
|
| 15 |
+
- recall
|
| 16 |
+
pipeline_tag: text-classification
|
| 17 |
+
base_model: distilbert-base-uncased
|
| 18 |
---
|
| 19 |
+
|
| 20 |
+
# Mental Health Emotion Detection - Enhanced DistilBERT
|
| 21 |
+
|
| 22 |
+
This model is a fine-tuned DistilBERT for multi-label emotion classification in mental health applications, detecting 28 different emotions from text input with enhanced architecture and advanced training techniques.
|
| 23 |
+
|
| 24 |
+
## Model Description
|
| 25 |
+
|
| 26 |
+
- **Model Type:** Enhanced DistilBERT (Fine-tuned)
|
| 27 |
+
- **Base Model:** distilbert-base-uncased
|
| 28 |
+
- **Task:** Multi-label emotion classification
|
| 29 |
+
- **Dataset:** GoEmotions (balanced and enhanced)
|
| 30 |
+
- **Languages:** English
|
| 31 |
+
- **Architecture:** Enhanced with additional layers, focal loss, and class balancing
|
| 32 |
+
|
| 33 |
+
## Performance
|
| 34 |
+
|
| 35 |
+
| Metric | Score |
|
| 36 |
+
|--------|-------|
|
| 37 |
+
| F1-Score | 0.298 |
|
| 38 |
+
| Precision | 0.459 |
|
| 39 |
+
| Recall | 0.260 |
|
| 40 |
+
| Accuracy | 89.5% |
|
| 41 |
+
| Improvement | 7.6x over baseline |
|
| 42 |
+
|
| 43 |
+
## Emotions Detected
|
| 44 |
+
|
| 45 |
+
The model can detect 28 emotions: admiration, amusement, anger, annoyance, approval, caring, confusion, curiosity, desire, disappointment, disapproval, disgust, embarrassment, excitement, fear, gratitude, grief, joy, love, nervousness, optimism, pride, realization, relief, remorse, sadness, surprise, neutral.
|
| 46 |
+
|
| 47 |
+
## Usage
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 51 |
+
import torch
|
| 52 |
+
|
| 53 |
+
# Load model and tokenizer
|
| 54 |
+
tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/mental-health-enhanced-distilbert")
|
| 55 |
+
model = AutoModelForSequenceClassification.from_pretrained("YOUR_USERNAME/mental-health-enhanced-distilbert")
|
| 56 |
+
|
| 57 |
+
# Example usage
|
| 58 |
+
text = "I'm feeling really anxious about tomorrow"
|
| 59 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
|
| 60 |
+
|
| 61 |
+
with torch.no_grad():
|
| 62 |
+
outputs = model(**inputs)
|
| 63 |
+
predictions = torch.sigmoid(outputs.logits)
|
| 64 |
+
|
| 65 |
+
# Get emotion labels
|
| 66 |
+
emotions = []
|
| 67 |
+
for i, score in enumerate(predictions[0]):
|
| 68 |
+
if score > 0.4: # Threshold
|
| 69 |
+
emotion = model.config.id2label[i]
|
| 70 |
+
emotions.append((emotion, score.item()))
|
| 71 |
+
|
| 72 |
+
print(emotions)
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Training Details
|
| 76 |
+
|
| 77 |
+
### Enhanced Architecture
|
| 78 |
+
- **Base:** DistilBERT with additional hidden layers
|
| 79 |
+
- **Enhancements:**
|
| 80 |
+
- Layer normalization
|
| 81 |
+
- Dropout regularization
|
| 82 |
+
- Enhanced forward pass with ReLU activations
|
| 83 |
+
- Multi-layer classification head (768 → 512 → 256 → 128 → 28)
|
| 84 |
+
|
| 85 |
+
### Advanced Training Techniques
|
| 86 |
+
- **Loss Function:** Focal Loss for class imbalance handling
|
| 87 |
+
- **Class Weighting:** Advanced weighting for rare emotions
|
| 88 |
+
- **Data Balancing:** Oversampling rare emotions, undersampling common ones
|
| 89 |
+
- **Optimization:** AdamW with cosine scheduling
|
| 90 |
+
- **Early Stopping:** Patience-based with best model saving
|
| 91 |
+
|
| 92 |
+
### Training Data
|
| 93 |
+
- **Dataset:** GoEmotions (balanced subset)
|
| 94 |
+
- **Training Samples:** ~12,750
|
| 95 |
+
- **Validation Samples:** ~2,250
|
| 96 |
+
- **Preprocessing:** Contraction expansion, lowercase normalization
|
| 97 |
+
- **Balancing:** Advanced sampling for 28 emotion categories
|
| 98 |
+
|
| 99 |
+
## Model Architecture
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
Input Text → DistilBERT Encoder → Enhanced Classification Head
|
| 103 |
+
↓
|
| 104 |
+
Hidden Layer 1 (768→512)
|
| 105 |
+
↓
|
| 106 |
+
Hidden Layer 2 (512→256)
|
| 107 |
+
↓
|
| 108 |
+
Hidden Layer 3 (256→128)
|
| 109 |
+
↓
|
| 110 |
+
Output Layer (128→28)
|
| 111 |
+
```
|
| 112 |
+
|
| 113 |
+
## Intended Use
|
| 114 |
+
|
| 115 |
+
This model is designed for:
|
| 116 |
+
- Mental health chatbots and companions
|
| 117 |
+
- Emotion-aware dialogue systems
|
| 118 |
+
- Mental health screening tools
|
| 119 |
+
- Research in computational psychology
|
| 120 |
+
- Empathetic AI applications
|
| 121 |
+
|
| 122 |
+
## Limitations
|
| 123 |
+
|
| 124 |
+
- Trained primarily on English text
|
| 125 |
+
- Performance may vary with very informal language
|
| 126 |
+
- Should not be used as sole diagnostic tool for mental health
|
| 127 |
+
- Requires context for optimal performance
|
| 128 |
+
|
| 129 |
+
## Training Metrics by Epoch
|
| 130 |
+
|
| 131 |
+
| Epoch | F1-Score | Precision | Recall |
|
| 132 |
+
|-------|----------|-----------|--------|
|
| 133 |
+
| 1 | 0.0145 | 0.0419 | 0.0089 |
|
| 134 |
+
| 2 | 0.1430 | 0.2797 | 0.1211 |
|
| 135 |
+
| 3 | 0.2141 | 0.4751 | 0.1804 |
|
| 136 |
+
| 4 | 0.2749 | 0.4317 | 0.2340 |
|
| 137 |
+
| 5 | 0.2897 | 0.4524 | 0.2533 |
|
| 138 |
+
| 6 | 0.2981 | 0.4592 | 0.2597 |
|
| 139 |
+
|
| 140 |
+
## Citation
|
| 141 |
+
|
| 142 |
+
If you use this model, please cite:
|
| 143 |
+
|
| 144 |
+
```
|
| 145 |
+
@misc{mental-health-emotion-distilbert,
|
| 146 |
+
title={Mental Health Emotion Detection - Enhanced DistilBERT},
|
| 147 |
+
author={Your Name},
|
| 148 |
+
year={2024},
|
| 149 |
+
publisher={Hugging Face},
|
| 150 |
+
url={https://huggingface.co/YOUR_USERNAME/mental-health-enhanced-distilbert}
|
| 151 |
+
}
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
## Acknowledgments
|
| 155 |
+
|
| 156 |
+
- Built on DistilBERT by Hugging Face
|
| 157 |
+
- Trained on GoEmotions dataset
|
| 158 |
+
- Enhanced with advanced ML techniques for mental health applications
|
config.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"activation": "gelu",
|
| 3 |
+
"attention_dropout": 0.1,
|
| 4 |
+
"dim": 768,
|
| 5 |
+
"dropout": 0.1,
|
| 6 |
+
"hidden_dim": 3072,
|
| 7 |
+
"id2label": {
|
| 8 |
+
"0": "admiration",
|
| 9 |
+
"1": "amusement",
|
| 10 |
+
"2": "anger",
|
| 11 |
+
"3": "annoyance",
|
| 12 |
+
"4": "approval",
|
| 13 |
+
"5": "caring",
|
| 14 |
+
"6": "confusion",
|
| 15 |
+
"7": "curiosity",
|
| 16 |
+
"8": "desire",
|
| 17 |
+
"9": "disappointment",
|
| 18 |
+
"10": "disapproval",
|
| 19 |
+
"11": "disgust",
|
| 20 |
+
"12": "embarrassment",
|
| 21 |
+
"13": "excitement",
|
| 22 |
+
"14": "fear",
|
| 23 |
+
"15": "gratitude",
|
| 24 |
+
"16": "grief",
|
| 25 |
+
"17": "joy",
|
| 26 |
+
"18": "love",
|
| 27 |
+
"19": "nervousness",
|
| 28 |
+
"20": "optimism",
|
| 29 |
+
"21": "pride",
|
| 30 |
+
"22": "realization",
|
| 31 |
+
"23": "relief",
|
| 32 |
+
"24": "remorse",
|
| 33 |
+
"25": "sadness",
|
| 34 |
+
"26": "surprise",
|
| 35 |
+
"27": "neutral"
|
| 36 |
+
},
|
| 37 |
+
"initializer_range": 0.02,
|
| 38 |
+
"label2id": {
|
| 39 |
+
"admiration": 0,
|
| 40 |
+
"amusement": 1,
|
| 41 |
+
"anger": 2,
|
| 42 |
+
"annoyance": 3,
|
| 43 |
+
"approval": 4,
|
| 44 |
+
"caring": 5,
|
| 45 |
+
"confusion": 6,
|
| 46 |
+
"curiosity": 7,
|
| 47 |
+
"desire": 8,
|
| 48 |
+
"disappointment": 9,
|
| 49 |
+
"disapproval": 10,
|
| 50 |
+
"disgust": 11,
|
| 51 |
+
"embarrassment": 12,
|
| 52 |
+
"excitement": 13,
|
| 53 |
+
"fear": 14,
|
| 54 |
+
"gratitude": 15,
|
| 55 |
+
"grief": 16,
|
| 56 |
+
"joy": 17,
|
| 57 |
+
"love": 18,
|
| 58 |
+
"nervousness": 19,
|
| 59 |
+
"neutral": 27,
|
| 60 |
+
"optimism": 20,
|
| 61 |
+
"pride": 21,
|
| 62 |
+
"realization": 22,
|
| 63 |
+
"relief": 23,
|
| 64 |
+
"remorse": 24,
|
| 65 |
+
"sadness": 25,
|
| 66 |
+
"surprise": 26
|
| 67 |
+
},
|
| 68 |
+
"max_position_embeddings": 512,
|
| 69 |
+
"model_type": "distilbert",
|
| 70 |
+
"n_heads": 12,
|
| 71 |
+
"n_layers": 6,
|
| 72 |
+
"pad_token_id": 0,
|
| 73 |
+
"problem_type": "multi_label_classification",
|
| 74 |
+
"qa_dropout": 0.1,
|
| 75 |
+
"seq_classif_dropout": 0.2,
|
| 76 |
+
"sinusoidal_pos_embds": false,
|
| 77 |
+
"transformers_version": "4.56.0",
|
| 78 |
+
"vocab_size": 30522
|
| 79 |
+
}
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b844b4253f4b7502efc99fa889584c27425d58bbfc82550d70f9259d60165c10
|
| 3 |
+
size 267749227
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
transformers>=4.21.0
|
| 2 |
+
torch>=1.12.0
|
| 3 |
+
numpy>=1.21.0
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"extra_special_tokens": {},
|
| 49 |
+
"mask_token": "[MASK]",
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "DistilBertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|