Text Classification
Transformers
Safetensors
English
emcoder
emotion-recognition
bayesian-deep-learning
mc-dropout
uncertainty-quantification
multi-label-classification
custom_code
Eval Results (legacy)
Run this model with HF Jobs
Run yezdata/EmCoder on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/yezdata/EmCoder. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/yezdata/EmCoder on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use yezdata/EmCoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yezdata/EmCoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="yezdata/EmCoder", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForSequenceClassification model = AutoModelForSequenceClassification.from_pretrained("yezdata/EmCoder", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files123---license: cc-by-nc-nd-4.0---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310---language:- enlicense: cc-by-nc-nd-4.0library_name: generictags:- emotion-recognition- bayesian-deep-learning- mc-dropout- uncertainty-quantification- multi-label-classificationdatasets:- go_emotionsmetrics:- precision- recall- f1model-index:- name: EmCoder (v1)results:- task:type: text-classificationname: Multi-label Emotion Classificationdataset:name: GoEmotionstype: go_emotionssplit: testmetrics:- name: Macro F1type: f1value: 0.440- name: Macro Precisiontype: precisionvalue: 0.408- name: Macro Recalltype: recallvalue: 0.495---# EmCoder> **Probabilistic Emotion Recognition & Uncertainty Quantification**<br>**28 Emotion multi-label classifier trained with MC Dropout methodology**Unlike standard classifiers, EmCoder quantifies what it doesn't know using Monte Carlo Dropout, making it suitable for high-stakes AI pipelines.<br>EmCoder is optimized for **MC Dropout inference**.## SOTA benchmark### Evaluation on the GoEmotions test split (macro avg metrics)EmCoder achieves competitive F1-scores while being ~35% smaller than RoBERTa-base and ~45% smaller than ModernBERT, offering a superior efficiency-to-uncertainty ratio.| Model | Precision | Recall | F1-Score | Params || :--- | :--- | :--- | :--- | :--- || **EmCoder (v1)** | **0.408** | **0.495** | **0.440** | **82.1M** || Google BERT (Original) | 0.400 | 0.630 | 0.460 | 110M || RoBERTa-base | 0.575 | 0.396 | 0.450 | 125M || ModernBERT-base | 0.652 | 0.443 | 0.500 | 149M |## How to use> Since `.safetensors` files only store model weights and not the class logic, you need to use the provided `emcoder.py` to enable **MC Dropout inference**.<br>EmCoder v1.0 requires the `roberta-base` tokenizer for correct token-to-embedding mapping.### 1. Setup & Tokenization```pythonfrom transformers import AutoTokenizerfrom emcoder import EmCoder # Ensure emcoder.py is in your directory# Load the same tokenizer used during trainingtokenizer = AutoTokenizer.from_pretrained("roberta-base")EMCODER_PATH = "path/to/emcoder"# Initialize with same config as trainingmodel = EmCoder.from_pretrained(EMCODER_PATH)```### 2. Bayesian inferenceTo obtain probabilistic outputs and uncertainty metrics, use the mc_forward method:```pythonimport torch# Perform 50 stochastic passesN_SAMPLES = 50model.eval()inputs = tokenizer("I am so happy you are here!", return_tensors="pt")logits_mc = model.mc_forward(inputs['input_ids'], inputs['attention_mask'], n_samples=N_SAMPLES) # Automatically keeps Dropout active, even when in model.eval# Bayesian Post-processing# logits_mc shape: (n_samples, batch_size, 28)probs_all = torch.sigmoid(logits_mc)mean_probs = probs_all.mean(dim=0) # Mean Predicted Probabilityuncertainty = probs_all.std(dim=0) # Epistemic Uncertainty (Standard Deviation)```## Model Architecture```mermaidflowchart LRsubgraph InputGroup["Input Operations"]direction TBMCD_Loop(["MC-Inference Loop: N_samples"]):::LoopNodeids["Batch IDs"]mask["Batch Mask"]endsubgraph EmCoderCore["EmCoder Core"]direction LRtok_emb["Token Embedding"]ln_in["Input LayerNorm"]Transformer["Transformer Encoder"]final_norm["Final LayerNorm"]Dropout1[("MC-Dropout")]Dropout2[("MC-Dropout")]endsubgraph Row1[" "]direction LRInputGroupEmCoderCoreendsubgraph MLP["Classifier MLP"]L_lin["Linear 1"]Dropout3[("MC-Dropout")]GELU["GELU"]F_lin["Final Linear"]endsubgraph ClassifierHead[" "]direction TBpool["Masked Mean Pooling"]MLPendsubgraph Row2[" "]direction LRClassifierHeadOut(["Class LogitsMC(n_samples, B, 28)"])Avg["Bayesian Post-processing"]endtok_emb ==> ln_inln_in -.-> Dropout1Dropout1 ==> TransformerTransformer -.-> Dropout2Dropout2 ==> final_normMCD_Loop -.-> idsids ==> tok_embfinal_norm ==> poolmask ==> poolpool ==> L_linL_lin -.-> Dropout3Dropout3 ==> GELUGELU ==> F_linF_lin ==> OutOut ==> Avgmask ==> TransformerclassDef MCD fill:#424242,stroke:#fbc02d,stroke-width:2px,stroke-dasharray: 5 5,color:#fffclassDef OutNode fill:#0d47a1,stroke:#1976d2,stroke-width:3px,color:#fff,font-weight:boldclassDef BayesNode fill:#3e2723,stroke:#8d6e63,stroke-width:2px,stroke-dasharray: 3 3,color:#fffclassDef LoopNode fill:#263238,stroke:#78909c,stroke-width:2px,color:#fff,font-style:italicclassDef LightNode fill:#212121,stroke:#90a4ae,color:#fffclass MCD_Loop LoopNodeclass ids,mask,tok_emb,ln_in,Transformer,final_norm,L_lin,GELU,F_lin,pool LightNodeclass Dropout1,Dropout2,Dropout3 MCDclass Out OutNodeclass Avg BayesNodestyle InputGroup fill:#1a1a1a,stroke:#444,color:#fffstyle EmCoderCore fill:#2d1a2d,stroke:#6a1b9a,color:#fffstyle MLP fill:#212121,stroke:#455a64,color:#fffstyle ClassifierHead fill:#012a4a,stroke:#01497c,color:#fffstyle Row1 fill:none,stroke:nonestyle Row2 fill:none,stroke:nonelinkStyle 2 stroke:#fbc02d,stroke-width:2px,fill:nonelinkStyle 5 stroke:#fbc02d,stroke-width:2px,fill:nonelinkStyle 11 stroke:#fbc02d,stroke-width:2px,fill:none```### OptimizationThe model is trained using a Weighted Bayesian Binary Cross Entropy loss:$$\mathcal{L}_{Bayesian} = \frac{1}{T} \sum_{t=1}^{T} \text{BCEWithLogits}(z^{(t)}, y; w)$$Where weights $w$ are calculated using a logarithmic class-balancing scale to handle extreme label imbalance:$$w_{c} = \max\left( 0.1, \min\left( 20, 1 + \ln \left( \frac{N_{neg,c} + \epsilon}{N_{pos,c} + \epsilon} \right) \right) \right)$$## Performance**Using threshold of 0.5 for binarizing predictions**| | precision | recall | f1-score | support ||:---------------|------------:|---------:|-----------:|----------:|| micro avg | 0.494 | 0.596 | 0.54 | 6329 || macro avg | 0.408 | 0.495 | 0.44 | 6329 || weighted avg | 0.492 | 0.596 | 0.535 | 6329 || samples avg | 0.525 | 0.616 | 0.544 | 6329 ||----------------|-------------|----------|------------|-----------|| admiration | 0.541 | 0.673 | 0.599 | 504 || amusement | 0.688 | 0.909 | 0.783 | 264 || anger | 0.419 | 0.47 | 0.443 | 198 || annoyance | 0.31 | 0.25 | 0.277 | 320 || approval | 0.304 | 0.271 | 0.287 | 351 || caring | 0.229 | 0.281 | 0.252 | 135 || confusion | 0.26 | 0.497 | 0.342 | 153 || curiosity | 0.432 | 0.764 | 0.552 | 284 || desire | 0.453 | 0.518 | 0.483 | 83 || disappointment | 0.176 | 0.152 | 0.163 | 151 || disapproval | 0.279 | 0.404 | 0.33 | 267 || disgust | 0.447 | 0.545 | 0.491 | 123 || embarrassment | 0.325 | 0.351 | 0.338 | 37 || excitement | 0.288 | 0.427 | 0.344 | 103 || fear | 0.47 | 0.692 | 0.56 | 78 || gratitude | 0.834 | 0.943 | 0.885 | 352 || grief | 0 | 0 | 0 | 6 || joy | 0.445 | 0.652 | 0.529 | 161 || love | 0.724 | 0.895 | 0.801 | 238 || nervousness | 0.24 | 0.261 | 0.25 | 23 || optimism | 0.483 | 0.543 | 0.511 | 186 || pride | 0.667 | 0.375 | 0.48 | 16 || realization | 0.226 | 0.166 | 0.191 | 145 || relief | 0.222 | 0.182 | 0.2 | 11 || remorse | 0.516 | 0.857 | 0.644 | 56 || sadness | 0.405 | 0.545 | 0.464 | 156 || surprise | 0.429 | 0.539 | 0.478 | 141 || neutral | 0.602 | 0.695 | 0.645 | 1787 |**Model uncertainty estimation****Confusion matrix**## Workflow```mermaidflowchart LRclassDef StageNode fill:#121212,stroke:#546e7a,color:#fff;classDef HighlightNode fill:#4e342e,stroke:#ff7043,stroke-width:2px,color:#fff,font-weight:bold;subgraph PT ["Phase 1: Pre-training"]direction TBOWT[(OpenWebText)]:::StageNode --> MLM[Masked Language Modeling]:::StageNodeMLM --> Core[Save EmCoderCore]:::StageNodeendsubgraph FT ["Phase 2: Fine-tuning"]direction TBCore --> Init[Init ClassificationHead]:::StageNodeGE[(GoEmotions)]:::StageNode --> WBT[Bayesian Fine-tuning]:::HighlightNodeWBT --> LogW[Log-weighted BCE Loss]:::StageNodeLogW --> Freeze[Step 0-500: Encoder Frozen]:::StageNodeendsubgraph EV ["Phase 3: Testing & Inference"]direction TBFreeze --> MCD[MC Dropout Inference]:::HighlightNodeMCD --> Unc[Uncertainty Estimation]:::HighlightNodesubgraph Metrics ["Analysis"]Unc --> EPI[Epistemic: Model Confidence]:::StageNodeUnc --> ALE[Aleatoric: Data Ambiguity]:::StageNodeUnc --> CM[Test set metrics]:::StageNodeendendstyle PT fill:#0d1b2a,stroke:#1b263b,color:#fffstyle FT fill:#2e1500,stroke:#5d2a00,color:#fffstyle EV fill:#1b2e1b,stroke:#2d4a2d,color:#fffstyle Metrics fill:#000,stroke:#333,color:#ffflinkStyle default stroke:#aaa,stroke-width:2px;```### NoteNote that this model was trained on GoEmotions dataset (social networks domain) and it may not generalize well to other domains.## CitationIf you use this model, please cite it as follows:```bibtex@software{jez2026emcoder,author = {Václav Jež},title = {EmCoder: Probabilistic Emotion Recognition & Uncertainty Quantification},year = {2026},publisher = {GitHub},journal = {GitHub repository},howpublished = {\url{https://github.com/yezdata/emcoder}},version = {1.0.0}}```
README.md+308-1