yezdata commited on
Commit
b5bf754
·
verified ·
1 Parent(s): 229e620

Delete README.md

Browse files
Files changed (1) hide show
  1. README.md +0 -218
README.md DELETED
@@ -1,218 +0,0 @@
1
- ---
2
- language:
3
- - en
4
- license: cc-by-nc-nd-4.0
5
- library_name: transformers
6
- pipeline_tag: text-classification
7
- tags:
8
- - emotion-recognition
9
- - bayesian-deep-learning
10
- - mc-dropout
11
- - uncertainty-quantification
12
- - multi-label-classification
13
- datasets:
14
- - Skylion007/openwebtext
15
- - google-research-datasets/go_emotions
16
- metrics:
17
- - precision
18
- - recall
19
- - f1
20
- model-index:
21
- - name: EmCoder
22
- results:
23
- - task:
24
- type: text-classification
25
- name: Multi-label Emotion Classification
26
- dataset:
27
- name: GoEmotions
28
- type: go_emotions
29
- split: test
30
- metrics:
31
- - name: Macro F1
32
- type: f1
33
- value: 0.463
34
- - name: Macro Precision
35
- type: precision
36
- value: 0.469
37
- - name: Macro Recall
38
- type: recall
39
- value: 0.486
40
- ---
41
-
42
- # EmCoder
43
- <blockquote>
44
- <b>Probabilistic Emotion Recognition & Uncertainty Quantification</b><br>
45
- <b>28 Emotion multi-label Transformer classifier</b>
46
- </blockquote>
47
-
48
-
49
- Unlike standard classifiers, EmCoder quantifies what it doesn't know using Monte Carlo Dropout, making it suitable for high-stakes AI pipelines.<br>
50
- EmCoder is optimized for **MC Dropout inference**.
51
-
52
-
53
-
54
- ## SOTA benchmark
55
- ### Evaluation on the GoEmotions test split (macro avg metrics)
56
- EmCoder achieves competitive F1-score with its compact size (~35% smaller than RoBERTa-base and ~45% smaller than ModernBERT), while providing per-class epistemic uncertainty quantification.
57
- | Model | Precision | Recall | F1-Score | Params |
58
- | :--- | :--- | :--- | :--- | :--- |
59
- | **EmCoder** | **0.469** | **0.486** | **0.463** | **82.1M** |
60
- | Google BERT (Original) | 0.400 | 0.630 | 0.460 | 110M |
61
- | RoBERTa-base | 0.575 | 0.396 | 0.450 | 125M |
62
- | ModernBERT-base | 0.583 | 0.535 | 0.550 | 149M |
63
-
64
-
65
- ## How to use
66
- ### 1. Setup & Tokenization
67
- EmCoder uses the `roberta-base` tokenizer for correct token-to-embedding mapping.
68
- Ensure you allow remote code execution since it's a custom architecture.
69
- ```python
70
- import torch
71
- from transformers import AutoModel, AutoTokenizer
72
-
73
- repo_id = "yezdata/EmCoder"
74
-
75
- # Load the same tokenizer used during training
76
- tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
77
-
78
- # Initialize with same config as training
79
- model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)
80
- ```
81
- ### 2. Bayesian inference
82
- To obtain probabilistic outputs and uncertainty metrics, use the `mc_forward` method:
83
- ```python
84
- # Perform 50 stochastic passes
85
- N_SAMPLES = 50
86
- MAX_BATCH_SIZE = 10 # optional sub-batching of N_SAMPLES
87
-
88
- inputs = tokenizer("I am so happy you are here!", return_tensors="pt")
89
-
90
- model.eval()
91
- with torch.no_grad():
92
- # Automatically keeps Dropout active, even when in model.eval
93
- mc_logits = model.mc_forward(
94
- **inputs,
95
- n_samples=N_SAMPLES,
96
- max_batch_size=MAX_BATCH_SIZE
97
- )
98
-
99
- # Bayesian Post-processing
100
- all_probs = torch.sigmoid(mc_logits) # (n_samples, B, 28)
101
-
102
- mean_probs = all_probs.mean(dim=0) # Mean Predicted Probability
103
- uncertainty = all_probs.std(dim=0) # Epistemic Uncertainty
104
-
105
-
106
- # Formatted Output
107
- m_probs = mean_probs.squeeze(0)
108
- u_vals = uncertainty.squeeze(0)
109
-
110
- print(f"{'Emotion':<15} | {'Prob':<10} | {'Uncertainty':<10}")
111
- print("-" * 40)
112
-
113
- sorted_indices = torch.argsort(m_probs, descending=True)
114
-
115
- for idx in sorted_indices:
116
- prob, unc = m_probs[idx].item(), u_vals[idx].item()
117
- label = model.config.id2label[idx.item()]
118
-
119
- if prob > 0.05: # Print only emotions with prob > 5%
120
- print(f"{label:<15} | {prob:>8.2%} | ±{unc:>8.4f}")
121
- ```
122
-
123
-
124
- ## Model Architecture
125
- ![EmCoder Architecture](outputs/architecture.png)
126
-
127
-
128
- ### Optimization
129
- The model is trained using a **Weighted Binary Cross Entropy loss**
130
- Where weights **w** are calculated using a logarithmic class-balancing scale to handle extreme label imbalance:
131
-
132
- $$
133
- w_{c} = \max\left( 0.1, \min\left( 20, 1 + \ln \left( \frac{N_{neg,c} + \epsilon}{N_{pos,c} + \epsilon} \right) \right) \right)
134
- $$
135
-
136
-
137
-
138
- ## Performance on test set
139
- **Using `thresholds.json` optimization of probabilty thresholds for binarizing predictions (from val set)**
140
- | | precision | recall | f1-score | support |
141
- |:---------------|------------:|---------:|-----------:|----------:|
142
- | micro avg | 0.482 | 0.627 | 0.545 | 6329 |
143
- | **macro avg** | **0.469** |**0.486** | **0.463** | 6329 |
144
- | weighted avg | 0.508 | 0.627 | 0.550 | 6329 |
145
- | samples avg | 0.532 | 0.651 | 0.560 | 6329 |
146
- |----------------|-------------|----------|------------|-----------|
147
- | admiration | 0.613 | 0.607 | 0.610 | 504 |
148
- | amusement | 0.724 | 0.886 | 0.797 | 264 |
149
- | anger | 0.384 | 0.535 | 0.447 | 198 |
150
- | annoyance | 0.230 | 0.431 | 0.300 | 320 |
151
- | approval | 0.229 | 0.436 | 0.300 | 351 |
152
- | caring | 0.262 | 0.281 | 0.271 | 135 |
153
- | confusion | 0.395 | 0.320 | 0.354 | 153 |
154
- | curiosity | 0.441 | 0.736 | 0.551 | 284 |
155
- | desire | 0.538 | 0.422 | 0.473 | 83 |
156
- | disappointment | 0.221 | 0.152 | 0.180 | 151 |
157
- | disapproval | 0.242 | 0.536 | 0.333 | 267 |
158
- | disgust | 0.595 | 0.407 | 0.483 | 123 |
159
- | embarrassment | 0.556 | 0.405 | 0.469 | 37 |
160
- | excitement | 0.375 | 0.379 | 0.377 | 103 |
161
- | fear | 0.575 | 0.538 | 0.556 | 78 |
162
- | gratitude | 0.948 | 0.886 | 0.916 | 352 |
163
- | grief | 0.200 | 0.167 | 0.182 | 6 |
164
- | joy | 0.566 | 0.559 | 0.562 | 161 |
165
- | love | 0.762 | 0.861 | 0.809 | 238 |
166
- | nervousness | 0.333 | 0.174 | 0.229 | 23 |
167
- | optimism | 0.632 | 0.516 | 0.568 | 186 |
168
- | pride | 0.750 | 0.375 | 0.500 | 16 |
169
- | realization | 0.250 | 0.159 | 0.194 | 145 |
170
- | relief | 0.286 | 0.182 | 0.222 | 11 |
171
- | remorse | 0.547 | 0.839 | 0.662 | 56 |
172
- | sadness | 0.432 | 0.513 | 0.469 | 156 |
173
- | surprise | 0.483 | 0.504 | 0.493 | 141 |
174
- | neutral | 0.555 | 0.811 | 0.659 | 1787 |
175
-
176
-
177
-
178
- ### Entropy-based uncertainty quantification
179
-
180
- **Model uncertainty quantification on GoEmotions test set**
181
- Flattened emotion predictions
182
- | Mean probability vs Epistemic | Mean probability vs Aleatoric |
183
- | :---: | :---: |
184
- | ![Epistemic Scatter](outputs/epistemic_unc_scatter.png) | ![Aleatoric Scatter](outputs/aleatoric_unc_scatter.png) |
185
-
186
-
187
- **Demonstration of model uncertainty utilization**
188
- Compute F1 score while removing the most uncertain (epistemic) x % of positive and negative classified test samples
189
- ![F1 Rejection curve](outputs/f1_rejection_epistemic.png)
190
-
191
-
192
- **Emotion uncertainty distribution**
193
- | Epistemic | Aleatoric |
194
- | :---: | :---: |
195
- | ![Epistemic Ridge](outputs/ridge_epistemic.png) | ![Aleatoric Ridge](outputs/ridge_aleatoric.png) |
196
-
197
- ## Workflow
198
- ![EmCoder Workflow](outputs/workflow.png)
199
-
200
-
201
- ### Note
202
- Note that this model was trained on GoEmotions dataset (social networks domain) and it may not generalize well to other domains.
203
-
204
-
205
- ## Citation
206
- If you use this model, please cite it as follows:
207
-
208
- ```bibtex
209
- @software{jez2026emcoder,
210
- author = {Václav Jež},
211
- title = {EmCoder: Probabilistic Emotion Recognition & Uncertainty Quantification},
212
- year = {2026},
213
- publisher = {GitHub},
214
- journal = {GitHub repository},
215
- howpublished = {\url{https://github.com/yezdata/emcoder}},
216
- version = {1.0.0}
217
- }
218
- ```