Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: text-classification
|
| 5 |
+
tags:
|
| 6 |
+
- bert
|
| 7 |
+
- emotion-classification
|
| 8 |
+
- multi-label
|
| 9 |
+
- goemotions
|
| 10 |
+
- contrastive-learning
|
| 11 |
+
- tri-tower
|
| 12 |
+
license: apache-2.0
|
| 13 |
+
datasets:
|
| 14 |
+
- go_emotions
|
| 15 |
+
model-index:
|
| 16 |
+
- name: fine_tuned_bert_emotions_large
|
| 17 |
+
results:
|
| 18 |
+
- task:
|
| 19 |
+
name: Multi-label Emotion Classification
|
| 20 |
+
type: text-classification
|
| 21 |
+
dataset:
|
| 22 |
+
name: GoEmotions
|
| 23 |
+
type: go_emotions
|
| 24 |
+
split: test
|
| 25 |
+
metrics:
|
| 26 |
+
- name: F1 (micro)
|
| 27 |
+
type: f1
|
| 28 |
+
value: 0.53
|
| 29 |
+
- name: F1 (macro)
|
| 30 |
+
type: f1
|
| 31 |
+
value: 0.41
|
| 32 |
+
- name: Accuracy
|
| 33 |
+
type: accuracy
|
| 34 |
+
value: 0.38
|
| 35 |
+
base_model:
|
| 36 |
+
- google-bert/bert-large-uncased
|
| 37 |
+
---
|
| 38 |
+
|
| 39 |
+
# fine_tuned_bert_emotions_large
|
| 40 |
+
|
| 41 |
+
## Model summary
|
| 42 |
+
- Base: `bert-large-uncased`
|
| 43 |
+
- Task: multi-label emotion classification (GoEmotions-level emotions)
|
| 44 |
+
- Fine-tuning: tri-tower setup with contrastive context/label alignment
|
| 45 |
+
- Max length: 256
|
| 46 |
+
- Labels: same 28 GoEmotions emotions (excluding `example_very_unclear`)
|
| 47 |
+
|
| 48 |
+
## Intended use
|
| 49 |
+
- Classify short texts (social posts, chats) with multiple emotions.
|
| 50 |
+
- Not for medical/mental-health diagnosis; avoid high-stakes use without human review.
|
| 51 |
+
|
| 52 |
+
## Training data
|
| 53 |
+
- GoEmotions dataset
|
| 54 |
+
- Preprocessing: standard HF tokenizer, lowercased, truncation at 256 tokens.
|
| 55 |
+
|
| 56 |
+
## Training procedure
|
| 57 |
+
- Optimizer: AdamW, LR 5e-5 (context head 2e-5), cosine scheduler, warmup 10%.
|
| 58 |
+
- Batch size: 8 (eval 32), epochs: 40 (early stop on val_f1_micro).
|
| 59 |
+
- Losses: BCE-with-logits for context, InfoNCE contrastive temperature 0.07, context loss weight 1.0.
|
| 60 |
+
- Regularization: dropout 0.1–0.2 (head), label smoothing 0.05.
|
| 61 |
+
- Hardware: NVIDIA GPU (NVIDIA GeForce RTX 5090 (sm_120)).
|
| 62 |
+
|
| 63 |
+
## Evaluation
|
| 64 |
+
Replace with your best numbers:
|
| 65 |
+
- Test F1 (micro): 0.53
|
| 66 |
+
- Test F1 (macro): 0.41
|
| 67 |
+
- Precision (micro): 0.47
|
| 68 |
+
- Accuracy: 0.38
|
| 69 |
+
- Thresholding: per-label tuned on validation split.
|
| 70 |
+
|
| 71 |
+
## How to use
|
| 72 |
+
```python
|
| 73 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 74 |
+
import torch
|
| 75 |
+
|
| 76 |
+
model_name = "your-hf-username/fine_tuned_bert_emotions_large"
|
| 77 |
+
tok = AutoTokenizer.from_pretrained(model_name)
|
| 78 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 79 |
+
|
| 80 |
+
text = "I’m excited but a bit nervous about tomorrow!"
|
| 81 |
+
enc = tok(text, return_tensors="pt", truncation=True, padding=True)
|
| 82 |
+
with torch.no_grad():
|
| 83 |
+
logits = model(**enc).logits
|
| 84 |
+
probs = torch.sigmoid(logits)[0]
|
| 85 |
+
label_map = model.config.id2label
|
| 86 |
+
preds = [(label_map[i], probs[i].item()) for i in range(len(probs))]
|
| 87 |
+
print(sorted(preds, key=lambda x: x[1], reverse=True)[:5])
|