How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-classification", model="CobuildX-AI/cbx-emotion-classifier-68M")
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForMaskedLM

tokenizer = AutoTokenizer.from_pretrained("CobuildX-AI/cbx-emotion-classifier-68M")
model = AutoModelForMaskedLM.from_pretrained("CobuildX-AI/cbx-emotion-classifier-68M", device_map="auto")
Quick Links

cbx-emotion-classifier-68M

An English emotion classifier. Give it a short text (a comment, post, message or review) and it returns the emotions it expresses, from Ekman's six basic emotions plus neutral: anger, disgust, fear, joy, sadness, surprise and neutral. A text can have more than one (for example joy and surprise). Trained on GoEmotions, about 54,000 Reddit comments labelled by people, with Google's grouping of its 27 emotions into these 7.

It has 68.1M parameters: the Ettin encoder 68m fine-tuned on GoEmotions. Other sizes: 17M. On a CPU (8 threads, fp32) one short text (13 tokens) takes about 11 ms and a full 128-token text about 31 ms.

Licence: Apache License, Version 2.0. Read Intended use and disclaimer before using it.

Labels

A text can have several labels (multi-label): the model gives each label its own probability, and a label is predicted when its probability reaches that label's threshold (tuned on the validation set). Scores per label on GoEmotions test (below).

Label Meaning F1 Precision Recall Threshold
anger anger, annoyance, disapproval 0.55 0.55 0.55 0.42
disgust disgust (often contempt for people or behaviour) 0.50 0.63 0.41 0.41
fear fear, nervousness 0.69 0.67 0.70 0.26
joy joy, amusement, approval, excitement, gratitude, love, optimism, relief, pride, admiration, desire, caring 0.82 0.81 0.83 0.43
sadness sadness, disappointment, embarrassment, grief, remorse 0.59 0.64 0.55 0.46
surprise surprise, realization, confusion, curiosity 0.62 0.57 0.68 0.26
neutral no emotion expressed 0.68 0.59 0.81 0.23

The meanings are the GoEmotions emotions that Google's mapping puts under each label, so joy stands for positive feeling in general (including approval and gratitude) and anger includes mild annoyance and disapproval. neutral can come together with an emotion, as in 3% of the training texts.

Quick start

pip install -r requirements.txt
python example.py
from cbx_emotion import EmotionClassifier

clf = EmotionClassifier(".")                  # folder with the model files; CPU or GPU
r = clf.classify("Thank you so much, this made my whole week!")
r["labels"], r["scores"]               # predicted labels and the probability of each label
clf.classify("some text", threshold=0.3)  # one threshold for every label instead of the tuned ones
clf.classify(["first text", "second text"])   # a list gives a list

python example.py prints (texts invented; any errors are the model's own):

joy 1.00                     Thank you so much, this made my whole week!
surprise 0.67                I can't believe they cancelled the show after one season. Ugh.
neutral 0.94                 The meeting has been moved to 3 pm on Thursday.
joy 0.86, surprise 0.58      Wait, you're telling me he actually won? Wow.
sadness 0.97                 I miss my grandmother every single day.
disgust 0.92, anger 0.52     That guy cut the whole queue and then yelled at the cashier. Disgusting behaviour.
fear 0.95                    I'm really nervous about my exam results tomorrow.

Input

  • One short English text. The model reads at most 128 tokens; longer text is cut ("truncated": True).
  • It was trained on Reddit comments, in which people's names are replaced by [NAME]; plain names work too.
  • The thresholds in cbx_config.json were tuned for the best macro F1 on the GoEmotions validation set. For more or fewer labels per text, pass your own threshold, or apply your own thresholds to scores.

Evaluation

GoEmotions test: The original GoEmotions test split: 5,427 Reddit comments, labelled by people and grouped into the 7 labels with Google's mapping (33% neutral; 8% of the comments have more than one label). Never used in training or for any choice. Macro F1 is the mean F1 over the 7 labels, neutral included.

Model GoEmotions test (macro F1)
this model (68M) 0.635
17M (same family) 0.609
TF-IDF + logistic regression (one per label) 0.571

More views of GoEmotions test:

Model macro F1, tuned thresholds macro F1 at 0.3 macro F1, 6 emotions micro F1
this model (68M) 0.635 0.637 0.627 0.698
17M (same family) 0.609 0.599 0.599 0.677
TF-IDF + logistic regression (one per label) 0.571 0.499 0.559 0.645

With the tuned thresholds, 1.0% of the test texts get no label (no probability reaches its threshold); labels is then empty.

For reference, the GoEmotions paper (Demszky et al., 2020, Table 6) reports macro F1 0.64 for BERT-base (110M parameters) on the same test set and grouping, with a fixed threshold of 0.3; this model scores 0.637 at 0.3. TF-IDF: word n-grams with one logistic regression per label, trained on the same data, thresholds tuned on validation the same way.

Training data

The GoEmotions train split (43,410 comments) with its human labels, mapped to the 7 labels with Google's mapping. No other data, no LLM labels and no generated text. Fine-tuned with one sigmoid output per label; the thresholds were then tuned per label on the validation split (5,426 comments).

Dataset Languages Licence Used for
GoEmotions, Demszky et al., ACL 2020 (Google Research) en Apache-2.0 training and testing

Limitations

  • The labels are noisy. GoEmotions raters often disagreed, and many texts are a judgement call. Most errors are between an emotion and neutral (mild joy, annoyance or surprise called neutral, and the reverse). The scores above are against those labels.
  • Small labels: disgust (F1 0.50) and fear (0.69) have few examples (123 and 98 in the test set), so they are less accurate and less precisely measured. disgust is often confused with anger.
  • Domain: English Reddit comments from 2005 to 2019, mostly US-centric. Expect lower accuracy on other kinds of text (support tickets, reviews, chat, formal writing), on other varieties of English and on other languages.
  • Context. The model sees one text. Sarcasm, irony, quotes and replies to content it cannot see are often misread.
  • Text, not people. It labels the emotion a text expresses, not what the writer actually feels.
  • Bias. Errors are not spread evenly across topics, dialects or groups of people; text about political, religious or identity topics may be judged less accurately.

Intended use and disclaimer

Intended use: measuring emotion in text at scale, for example in customer feedback, support conversations, reviews and social-media posts, where results are read in aggregate or checked by people. Not intended for decisions about individual people (hiring, education, credit, insurance, health, policing or monitoring employees or students), or for inferring anyone's mental state, without a person reviewing each case. The model makes mistakes (see Limitations). It is provided "as is", without warranties of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits your data and for complying with the laws that apply to your use.

Downloads last month
15
Safetensors
Model size
68.1M params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for CobuildX-AI/cbx-emotion-classifier-68M

Finetuned
(50)
this model