SamLowe/roberta-base-go_emotions

By SamLowe

🎯 Task: Text Classification⚖️ mit📦 transformers

Model Card

Overview

Model trained from roberta-base on the go_emotions dataset for multi-label classification.

ONNX version also available

A version of this model in ONNX format (including an INT8 quantized ONNX version) is now available at https://huggingface.co/SamLowe/roberta-base-go_emotions-onnx. These are faster for inference, esp for smaller batch sizes, massively reduce the size of the dependencies required for inference, make inference of the model more multi-platform, and in the case of the quantized version reduce the model file/download size by 75% whilst retaining almost all the accuracy if you only need inference.

Dataset used for the model

go_emotions is based on Reddit data and has 28 labels. It is a multi-label dataset where one or multiple labels may apply for any given input text, hence this model is a multi-label classification model with 28 'probability' float outputs for any given input text. Typically a threshold of 0.5 is applied to the probabilities for the prediction for each label.

How the model was created

The model was trained using AutoModelForSequenceClassification.from_pretrained with problem_type="multi_label_classification" for 3 epochs with a learning rate of 2e-5 and weight decay of 0.01.

Inference

There are multiple ways to use this model in Huggingface Transformers. Possibly the simplest is using a pipeline:

from transformers import pipeline

classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)

sentences = ["I am not having a great day"]

model_outputs = classifier(sentences)
print(model_outputs[0])
# produces a list of dicts for each of the labels

Evaluation / metrics

Evaluation of the model is available at

Open In Colab

Summary

As provided in the above notebook, evaluation of the multi-label output (of the 28 dim output via a threshold of 0.5 to binarize each) using the dataset test split gives:

  • Accuracy: 0.474
  • Precision: 0.575
  • Recall: 0.396
  • F1: 0.450

But the metrics are more meaningful when measured per label given the multi-label nature (each label is effectively an independent binary classification) and the fact that there is drastically different representations of the labels in the dataset.

With a threshold of 0.5 applied to binarize the model outputs, as per the above notebook, the metrics per label are:

accuracyprecisionrecallf1mccsupportthreshold
admiration0.9460.7250.6750.6990.6705040.5
amusement0.9820.7900.8710.8290.8212640.5
anger0.9700.6520.3790.4790.4831980.5
annoyance0.9400.4720.1590.2380.2503200.5
approval0.9420.6090.3020.4040.4033510.5
caring0.9730.4480.3190.3720.3641350.5
confusion0.9720.5000.4310.4630.4501530.5
curiosity0.9500.5370.3560.4280.4122840.5
desire0.9870.6300.4100.4960.502830.5
disappointment0.9740.6250.1990.3020.3431510.5
disapproval0.9500.4940.3070.3790.3652670.5
disgust0.9820.7070.3330.4530.4781230.5
embarrassment0.9940.7500.2430.3670.425370.5
excitement0.9830.6030.3400.4350.4451030.5
fear0.9920.7580.6030.6710.672780.5
gratitude0.9900.9600.8810.9190.9143520.5
grief0.9990.0000.0000.0000.00060.5
joy0.9780.6470.5590.6000.5901610.5
love0.9820.7730.8320.8020.7932380.5
nervousness0.9960.6000.1300.2140.278230.5
optimism0.9720.6670.3760.4810.4881860.5
pride0.9970.0000.0000.0000.000160.5
realization0.9740.5410.1380.2200.2641450.5
relief0.9980.0000.0000.0000.000110.5
remorse0.9910.5530.7500.6360.640560.5
sadness0.9770.6210.4940.5500.5421560.5
surprise0.9810.7500.4040.5250.5421410.5
neutral0.7820.6940.6040.6460.49217870.5

Optimizing the threshold per label for the one that gives the optimum F1 metrics gives slightly better metrics - sacrificing some precision for a greater gain in recall, hence to the benefit of F1 (how this was done is shown in the above notebook):

accuracyprecisionrecallf1mccsupportthreshold
admiration0.9400.6510.7760.7080.6785040.25
amusement0.9820.7810.8900.8320.8252640.45
anger0.9590.4540.6010.5170.5021980.15
annoyance0.8640.2430.6190.3490.3283200.10
approval0.9260.4320.4420.4370.3973510.30
caring0.9720.4260.3850.4050.3911350.40
confusion0.9740.5480.4120.4700.4621530.55
curiosity0.9430.4730.7110.5680.5522840.25
desire0.9850.5180.5300.5240.516830.25
disappointment0.9740.5620.2980.3900.3981510.40
disapproval0.9410.4140.4680.4390.4092670.30
disgust0.9780.5230.4630.4910.4811230.20
embarrassment0.9940.5670.4590.5070.507370.10
excitement0.9810.5000.4170.4550.4471030.35
fear0.9910.7120.6670.6890.685780.40
gratitude0.9900.9570.8890.9220.9173520.45
grief0.9990.3330.3330.3330.33360.05
joy0.9780.6230.6460.6340.6231610.40
love0.9820.7400.8990.8120.8072380.25
nervousness0.9960.5710.3480.4320.444230.25
optimism0.9710.5800.5650.5720.5571860.20
pride0.9980.8750.4380.5830.618160.10
realization0.9610.2700.2620.2660.2461450.15
relief0.9920.1520.6360.2460.309110.05
remorse0.9910.5410.9460.6880.712560.10
sadness0.9770.5990.5830.5910.5791560.40
surprise0.9770.5430.6740.6010.5931410.15
neutral0.7580.5980.8100.6880.51317870.25

This improves the overall metrics:

  • Precision: 0.542
  • Recall: 0.577
  • F1: 0.541

Or if calculated weighted by the relative size of the support of each label:

  • Precision: 0.572
  • Recall: 0.677
  • F1: 0.611

Commentary on the dataset

Some labels (E.g. gratitude) when considered independently perform very strongly with F1 exceeding 0.9, whilst others (E.g. relief) perform very poorly.

This is a challenging dataset. Labels such as relief do have much fewer examples in the training data (less than 100 out of the 40k+, and only 11 in the test split).

But there is also some ambiguity and/or labelling errors visible in the training data of go_emotions that is suspected to constrain the performance. Data cleaning on the dataset to reduce some of the mistakes, ambiguity, conflicts and duplication in the labelling would produce a higher performing model.

Architecture & Tags

transformerspytorchsafetensorsrobertatext-classificationemotionsmulti-class-classificationmulti-label-classificationendoi:10.57967/hf/3548autotrain_compatibleendpoints_compatibleregion:us