Sentence Similarity
sentence-transformers
Safetensors
English
roberta
feature-extraction
emotion
contrastive-learning
multi-label
text-embeddings-inference
Instructions to use foudil/lens-emotion-encoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use foudil/lens-emotion-encoder with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("foudil/lens-emotion-encoder") sentences = [ "That is a happy person", "That is a happy dog", "That is a very happy person", "Today is a sunny day" ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [4, 4] - Notebooks
- Google Colab
- Kaggle
add creds
Browse files
README.md
CHANGED
|
@@ -11,13 +11,16 @@ library_name: sentence-transformers
|
|
| 11 |
language:
|
| 12 |
- en
|
| 13 |
license: apache-2.0
|
|
|
|
|
|
|
|
|
|
| 14 |
---
|
| 15 |
|
| 16 |
# EmotionEncoder
|
| 17 |
|
| 18 |
-
**EmotionEncoder**
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
```python
|
| 23 |
from sentence_transformers import SentenceTransformer
|
|
@@ -44,7 +47,7 @@ Existing approaches to emotion in text fall into two camps, and both have a geom
|
|
| 44 |
|
| 45 |
**Classification models** (e.g. `roberta-base-go_emotions`) are trained with cross-entropy to separate emotion categories. They discriminate well — but cross-entropy optimises decision boundaries, not distances. The resulting embedding space isn't designed to answer "how emotionally similar are these two texts?"
|
| 46 |
|
| 47 |
-
**VAD regression models** map text to valence–arousal–dominance coordinates. They're continuous by construction, but three scalars
|
| 48 |
|
| 49 |
EmotionEncoder is trained with a **multi-label supervised contrastive objective** that directly shapes the embedding geometry: texts that share emotional content are pulled together, texts that don't are pushed apart, and the strength of attraction is proportional to how much emotional overlap they have. The result is a space that is simultaneously discriminative and calibrated — something neither of the above achieves alone.
|
| 50 |
|
|
@@ -54,12 +57,12 @@ EmotionEncoder is trained with a **multi-label supervised contrastive objective*
|
|
| 54 |
|
| 55 |
| | |
|
| 56 |
|---|---|
|
| 57 |
-
| **Base model** | `SamLowe/roberta-base-go_emotions` |
|
| 58 |
| **Architecture** | RoBERTa-base + masked mean pooling + 2-layer MLP projection head |
|
| 59 |
| **Output dimension** | 128 |
|
| 60 |
| **Similarity function** | Cosine similarity |
|
| 61 |
| **Max sequence length** | 100 tokens |
|
| 62 |
-
| **Training data** | GoEmotions (~54k Reddit comments, 28 emotion labels, multi-label) |
|
| 63 |
| **Training objective** | Multi-label SupCon with any-overlap pair weighting |
|
| 64 |
| **Language** | English |
|
| 65 |
|
|
@@ -99,6 +102,14 @@ Evaluated on three datasets with varying label schemas against two baselines:
|
|
| 99 |
|
| 100 |
EmotionEncoder exceeds the backbone on both out-of-domain datasets on every metric — the label schemas there (4–6 labels) are completely different from GoEmotions (28 labels), so this is genuine transfer, not overfitting to the training distribution. On Brier score it matches `all-mpnet-base-v2` in-domain (within 0.001) and beats it on tweet_eval, while reducing the backbone's Brier by 23% on GoEmotions.
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
---
|
| 103 |
|
| 104 |
## Usage
|
|
@@ -164,14 +175,44 @@ for a, b in pairs:
|
|
| 164 |
|
| 165 |
## Limitations
|
| 166 |
|
| 167 |
-
**English Reddit** Register generalisation is not established and should be validated on your domain before deployment.
|
| 168 |
|
| 169 |
**GoEmotions label noise.** Inter-annotator agreement varies across emotion categories. Categories with low agreement or few examples yield less reliable geometry.
|
| 170 |
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
---
|
| 173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
|
|
|
| 175 |
|
| 176 |
## Framework versions
|
| 177 |
|
|
|
|
| 11 |
language:
|
| 12 |
- en
|
| 13 |
license: apache-2.0
|
| 14 |
+
base_model: SamLowe/roberta-base-go_emotions
|
| 15 |
+
datasets:
|
| 16 |
+
- go_emotions
|
| 17 |
---
|
| 18 |
|
| 19 |
# EmotionEncoder
|
| 20 |
|
| 21 |
+
**EmotionEncoder** is a RoBERTa-base encoder fine-tuned with a multi-label supervised contrastive objective on GoEmotions. It maps English text into a 128-dimensional space where **cosine similarity = emotional similarity**: texts that share emotional content sit close together, texts that don't are pushed apart.
|
| 22 |
|
| 23 |
+
It is not a classifier. There are no output labels, no softmax, no categories to pick from. You get a vector, and that vector's geometry is the model's understanding of emotion.
|
| 24 |
|
| 25 |
```python
|
| 26 |
from sentence_transformers import SentenceTransformer
|
|
|
|
| 47 |
|
| 48 |
**Classification models** (e.g. `roberta-base-go_emotions`) are trained with cross-entropy to separate emotion categories. They discriminate well — but cross-entropy optimises decision boundaries, not distances. The resulting embedding space isn't designed to answer "how emotionally similar are these two texts?"
|
| 49 |
|
| 50 |
+
**VAD regression models** map text to valence–arousal–dominance coordinates. They're continuous by construction, but three scalars cannot resolve categorical distinctions that share VAD coordinates. Fear and anger both sit in the high-arousal, negative-valence quadrant; they are not the same emotion, and downstream systems that need to tell them apart will not get that signal from a VAD scalar.
|
| 51 |
|
| 52 |
EmotionEncoder is trained with a **multi-label supervised contrastive objective** that directly shapes the embedding geometry: texts that share emotional content are pulled together, texts that don't are pushed apart, and the strength of attraction is proportional to how much emotional overlap they have. The result is a space that is simultaneously discriminative and calibrated — something neither of the above achieves alone.
|
| 53 |
|
|
|
|
| 57 |
|
| 58 |
| | |
|
| 59 |
|---|---|
|
| 60 |
+
| **Base model** | [`SamLowe/roberta-base-go_emotions`](https://huggingface.co/SamLowe/roberta-base-go_emotions) |
|
| 61 |
| **Architecture** | RoBERTa-base + masked mean pooling + 2-layer MLP projection head |
|
| 62 |
| **Output dimension** | 128 |
|
| 63 |
| **Similarity function** | Cosine similarity |
|
| 64 |
| **Max sequence length** | 100 tokens |
|
| 65 |
+
| **Training data** | [GoEmotions](https://huggingface.co/datasets/go_emotions) (~54k Reddit comments, 28 emotion labels, multi-label) |
|
| 66 |
| **Training objective** | Multi-label SupCon with any-overlap pair weighting |
|
| 67 |
| **Language** | English |
|
| 68 |
|
|
|
|
| 102 |
|
| 103 |
EmotionEncoder exceeds the backbone on both out-of-domain datasets on every metric — the label schemas there (4–6 labels) are completely different from GoEmotions (28 labels), so this is genuine transfer, not overfitting to the training distribution. On Brier score it matches `all-mpnet-base-v2` in-domain (within 0.001) and beats it on tweet_eval, while reducing the backbone's Brier by 23% on GoEmotions.
|
| 104 |
|
| 105 |
+
### What the OOD transfer does and does not show
|
| 106 |
+
|
| 107 |
+
The OOD numbers support the claim that the learned geometry captures something more general than the GoEmotions label schema. The dair-ai/emotion (6 labels, Twitter) and tweet_eval/emotion (4 labels, Twitter) schemas were not seen during training, and the encoder's geometry recovers their structure better than either baseline.
|
| 108 |
+
|
| 109 |
+
They do **not** show that the model has learned a domain-invariant or theory-grounded emotion representation. Both OOD datasets remain English social-media text, sharing register and surface conventions with the GoEmotions training distribution. Performance on emotionally-loaded text in a clinical interview, a legal document, a literary passage, or a non-English-translated source is not established by these probes.
|
| 110 |
+
|
| 111 |
+
The intended interpretation is conservative: the encoder generalises across emotion label schemas of varying granularity within an English social-media-adjacent register, and should be validated on any domain that departs meaningfully from that.
|
| 112 |
+
|
| 113 |
---
|
| 114 |
|
| 115 |
## Usage
|
|
|
|
| 175 |
|
| 176 |
## Limitations
|
| 177 |
|
| 178 |
+
**English Reddit register.** Training data is drawn from Reddit. Register generalisation beyond English social media is not established and should be validated on your domain before deployment.
|
| 179 |
|
| 180 |
**GoEmotions label noise.** Inter-annotator agreement varies across emotion categories. Categories with low agreement or few examples yield less reliable geometry.
|
| 181 |
|
| 182 |
+
**Calibration residual.** Boundary ECE on GoEmotions is 0.421 vs. 0.416 for the mpnet calibration reference. Post-hoc temperature or Platt scaling can close this if precise probability estimates matter.
|
| 183 |
+
|
| 184 |
+
**No valence axis.** The model encodes full emotional profiles, not sentiment polarity. It is not optimised as a sentiment analyser.
|
| 185 |
|
| 186 |
---
|
| 187 |
|
| 188 |
+
## Citation
|
| 189 |
+
|
| 190 |
+
If you use this model, please cite the GoEmotions corpus and the SupCon objective on which it is based:
|
| 191 |
+
|
| 192 |
+
```bibtex
|
| 193 |
+
@inproceedings{demszky-etal-2020-goemotions,
|
| 194 |
+
title = {{GoEmotions}: A Dataset of Fine-Grained Emotions},
|
| 195 |
+
author = {Demszky, Dorottya and Movshovitz-Attias, Dana and Ko, Jeongwoo and Cowen, Alan and Nemade, Gaurav and Ravi, Sujith},
|
| 196 |
+
booktitle = {Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics},
|
| 197 |
+
year = {2020},
|
| 198 |
+
publisher = {Association for Computational Linguistics},
|
| 199 |
+
pages = {4040--4054},
|
| 200 |
+
doi = {10.18653/v1/2020.acl-main.372},
|
| 201 |
+
url = {https://aclanthology.org/2020.acl-main.372/}
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
@inproceedings{khosla-etal-2020-supcon,
|
| 205 |
+
title = {Supervised Contrastive Learning},
|
| 206 |
+
author = {Khosla, Prannay and Teterwak, Piotr and Wang, Chen and Sarna, Aaron and Tian, Yonglong and Isola, Phillip and Maschinot, Aaron and Liu, Ce and Krishnan, Dilip},
|
| 207 |
+
booktitle = {Advances in Neural Information Processing Systems},
|
| 208 |
+
volume = {33},
|
| 209 |
+
year = {2020},
|
| 210 |
+
pages = {18661--18673},
|
| 211 |
+
url = {https://proceedings.neurips.cc/paper/2020/hash/d89a66c7c80a29b1bdbab0f2a1a94af8-Abstract.html}
|
| 212 |
+
}
|
| 213 |
+
```
|
| 214 |
|
| 215 |
+
---
|
| 216 |
|
| 217 |
## Framework versions
|
| 218 |
|