File size: 2,599 Bytes
393ffde | 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 | ---
license: mit
tags:
- pytorch
- text-classification
- emotion-detection
- mlp
- nlp
datasets:
- nelgiriyewithana/emotions
metrics:
- accuracy
- f1
---
# Emotions Classifier - Deep MLP
Model klasyfikacji emocji w tekście oparty na wielowarstwowym perceptronie (MLP) z regularyzacją.
## Model Details
- **Architektura:** Deep MLP (5 warstw ukrytych)
- **Input:** TF-IDF vectors (5000 features)
- **Output:** 6 klas emocji (sadness, joy, love, anger, fear, surprise)
- **Accuracy:** 88.69% na zbiorze testowym
- **Overfitting Gap:** 6.02%
### Architektura:
```
Input (5000)
→ Linear(1024) + BatchNorm + ReLU + Dropout(0.5)
→ Linear(512) + BatchNorm + ReLU + Dropout(0.4)
→ Linear(256) + BatchNorm + ReLU + Dropout(0.3)
→ Linear(128) + BatchNorm + ReLU + Dropout(0.2)
→ Linear(6)
```
### Techniki regularyzacji:
- **Progresywny Dropout:** 0.5 → 0.4 → 0.3 → 0.2
- **Batch Normalization** po każdej warstwie
- **L2 Regularization** (weight decay = 1e-4)
## Usage
```python
import torch
import pickle
from sklearn.feature_extraction.text import TfidfVectorizer
# Wczytaj model
model = DeepMLP()
model.load_state_dict(torch.load("model.pth", map_location="cpu"))
model.eval()
# Wczytaj vectorizer i emotion_map
with open("vectorizer.pkl", "rb") as f:
vectorizer = pickle.load(f)
with open("emotion_map.pkl", "rb") as f:
emotion_map = pickle.load(f)
# Klasyfikacja
text = "I am so happy today!"
X = vectorizer.transform([text]).toarray()
X_tensor = torch.FloatTensor(X)
with torch.no_grad():
outputs = model(X_tensor)
_, predicted = torch.max(outputs, 1)
emotion = emotion_map[predicted.item()]
print(f"Emotion: {emotion}")
```
## Training Details
- **Dataset:** Emotions Dataset (Kaggle) - 150,000 examples
- **Train/Val/Test split:** 70% / 15% / 15%
- **Optimizer:** Adam (lr=0.001, weight_decay=1e-4)
- **Batch size:** 256
- **Epochs:** 10
- **Loss function:** CrossEntropyLoss
## Performance
| Emotion | Precision | Recall | F1-Score |
|---------|-----------|--------|----------|
| sadness | 0.95 | 0.90 | 0.92 |
| joy | 0.89 | 0.93 | 0.91 |
| love | 0.81 | 0.73 | 0.77 |
| anger | 0.88 | 0.91 | 0.89 |
| fear | 0.83 | 0.86 | 0.84 |
| surprise | 0.72 | 0.77 | 0.74 |
| **Macro avg** | **0.85** | **0.85** | **0.85** |
## Citation
```bibtex
@misc{emotions-classifier-mlp,
author = {Hubert Brzozowski},
title = {Emotions Classifier - Deep MLP},
year = {2026},
publisher = {Hugging Face}
}
```
## License
MIT License
|