MicahB commited on
Commit
c81c37a
1 Parent(s): 34dc39b

Create model

Browse files
README.md ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ tags:
4
+ - text-classification
5
+ - pytorch
6
+ - roberta
7
+ - emotions
8
+ - multi-class-classification
9
+ - multi-label-classification
10
+ datasets:
11
+ - go_emotions
12
+ license: mit
13
+ widget:
14
+ - text: I am not having a great day.
15
+ ---
16
+
17
+ #### Overview
18
+
19
+ Model trained from [roberta-base](https://huggingface.co/roberta-base) on the [go_emotions](https://huggingface.co/datasets/go_emotions) dataset for multi-label classification.
20
+
21
+ ##### ONNX version also available
22
+
23
+ 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](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.
24
+
25
+ #### Dataset used for the model
26
+
27
+ [go_emotions](https://huggingface.co/datasets/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.
28
+
29
+ #### How the model was created
30
+
31
+ 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.
32
+
33
+ #### Inference
34
+
35
+ There are multiple ways to use this model in Huggingface Transformers. Possibly the simplest is using a pipeline:
36
+
37
+ ```python
38
+ from transformers import pipeline
39
+
40
+ classifier = pipeline(task="text-classification", model="SamLowe/roberta-base-go_emotions", top_k=None)
41
+
42
+ sentences = ["I am not having a great day"]
43
+
44
+ model_outputs = classifier(sentences)
45
+ print(model_outputs[0])
46
+ # produces a list of dicts for each of the labels
47
+ ```
48
+
49
+ #### Evaluation / metrics
50
+
51
+ Evaluation of the model is available at
52
+
53
+ - https://github.com/samlowe/go_emotions-dataset/blob/main/eval-roberta-base-go_emotions.ipynb
54
+
55
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/samlowe/go_emotions-dataset/blob/main/eval-roberta-base-go_emotions.ipynb)
56
+
57
+ ##### Summary
58
+
59
+ 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:
60
+
61
+ - Accuracy: 0.474
62
+ - Precision: 0.575
63
+ - Recall: 0.396
64
+ - F1: 0.450
65
+
66
+ 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.
67
+
68
+ With a threshold of 0.5 applied to binarize the model outputs, as per the above notebook, the metrics per label are:
69
+
70
+ | | accuracy | precision | recall | f1 | mcc | support | threshold |
71
+ | -------------- | -------- | --------- | ------ | ----- | ----- | ------- | --------- |
72
+ | admiration | 0.946 | 0.725 | 0.675 | 0.699 | 0.670 | 504 | 0.5 |
73
+ | amusement | 0.982 | 0.790 | 0.871 | 0.829 | 0.821 | 264 | 0.5 |
74
+ | anger | 0.970 | 0.652 | 0.379 | 0.479 | 0.483 | 198 | 0.5 |
75
+ | annoyance | 0.940 | 0.472 | 0.159 | 0.238 | 0.250 | 320 | 0.5 |
76
+ | approval | 0.942 | 0.609 | 0.302 | 0.404 | 0.403 | 351 | 0.5 |
77
+ | caring | 0.973 | 0.448 | 0.319 | 0.372 | 0.364 | 135 | 0.5 |
78
+ | confusion | 0.972 | 0.500 | 0.431 | 0.463 | 0.450 | 153 | 0.5 |
79
+ | curiosity | 0.950 | 0.537 | 0.356 | 0.428 | 0.412 | 284 | 0.5 |
80
+ | desire | 0.987 | 0.630 | 0.410 | 0.496 | 0.502 | 83 | 0.5 |
81
+ | disappointment | 0.974 | 0.625 | 0.199 | 0.302 | 0.343 | 151 | 0.5 |
82
+ | disapproval | 0.950 | 0.494 | 0.307 | 0.379 | 0.365 | 267 | 0.5 |
83
+ | disgust | 0.982 | 0.707 | 0.333 | 0.453 | 0.478 | 123 | 0.5 |
84
+ | embarrassment | 0.994 | 0.750 | 0.243 | 0.367 | 0.425 | 37 | 0.5 |
85
+ | excitement | 0.983 | 0.603 | 0.340 | 0.435 | 0.445 | 103 | 0.5 |
86
+ | fear | 0.992 | 0.758 | 0.603 | 0.671 | 0.672 | 78 | 0.5 |
87
+ | gratitude | 0.990 | 0.960 | 0.881 | 0.919 | 0.914 | 352 | 0.5 |
88
+ | grief | 0.999 | 0.000 | 0.000 | 0.000 | 0.000 | 6 | 0.5 |
89
+ | joy | 0.978 | 0.647 | 0.559 | 0.600 | 0.590 | 161 | 0.5 |
90
+ | love | 0.982 | 0.773 | 0.832 | 0.802 | 0.793 | 238 | 0.5 |
91
+ | nervousness | 0.996 | 0.600 | 0.130 | 0.214 | 0.278 | 23 | 0.5 |
92
+ | optimism | 0.972 | 0.667 | 0.376 | 0.481 | 0.488 | 186 | 0.5 |
93
+ | pride | 0.997 | 0.000 | 0.000 | 0.000 | 0.000 | 16 | 0.5 |
94
+ | realization | 0.974 | 0.541 | 0.138 | 0.220 | 0.264 | 145 | 0.5 |
95
+ | relief | 0.998 | 0.000 | 0.000 | 0.000 | 0.000 | 11 | 0.5 |
96
+ | remorse | 0.991 | 0.553 | 0.750 | 0.636 | 0.640 | 56 | 0.5 |
97
+ | sadness | 0.977 | 0.621 | 0.494 | 0.550 | 0.542 | 156 | 0.5 |
98
+ | surprise | 0.981 | 0.750 | 0.404 | 0.525 | 0.542 | 141 | 0.5 |
99
+ | neutral | 0.782 | 0.694 | 0.604 | 0.646 | 0.492 | 1787 | 0.5 |
100
+
101
+ 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):
102
+
103
+ | | accuracy | precision | recall | f1 | mcc | support | threshold |
104
+ | -------------- | -------- | --------- | ------ | ----- | ----- | ------- | --------- |
105
+ | admiration | 0.940 | 0.651 | 0.776 | 0.708 | 0.678 | 504 | 0.25 |
106
+ | amusement | 0.982 | 0.781 | 0.890 | 0.832 | 0.825 | 264 | 0.45 |
107
+ | anger | 0.959 | 0.454 | 0.601 | 0.517 | 0.502 | 198 | 0.15 |
108
+ | annoyance | 0.864 | 0.243 | 0.619 | 0.349 | 0.328 | 320 | 0.10 |
109
+ | approval | 0.926 | 0.432 | 0.442 | 0.437 | 0.397 | 351 | 0.30 |
110
+ | caring | 0.972 | 0.426 | 0.385 | 0.405 | 0.391 | 135 | 0.40 |
111
+ | confusion | 0.974 | 0.548 | 0.412 | 0.470 | 0.462 | 153 | 0.55 |
112
+ | curiosity | 0.943 | 0.473 | 0.711 | 0.568 | 0.552 | 284 | 0.25 |
113
+ | desire | 0.985 | 0.518 | 0.530 | 0.524 | 0.516 | 83 | 0.25 |
114
+ | disappointment | 0.974 | 0.562 | 0.298 | 0.390 | 0.398 | 151 | 0.40 |
115
+ | disapproval | 0.941 | 0.414 | 0.468 | 0.439 | 0.409 | 267 | 0.30 |
116
+ | disgust | 0.978 | 0.523 | 0.463 | 0.491 | 0.481 | 123 | 0.20 |
117
+ | embarrassment | 0.994 | 0.567 | 0.459 | 0.507 | 0.507 | 37 | 0.10 |
118
+ | excitement | 0.981 | 0.500 | 0.417 | 0.455 | 0.447 | 103 | 0.35 |
119
+ | fear | 0.991 | 0.712 | 0.667 | 0.689 | 0.685 | 78 | 0.40 |
120
+ | gratitude | 0.990 | 0.957 | 0.889 | 0.922 | 0.917 | 352 | 0.45 |
121
+ | grief | 0.999 | 0.333 | 0.333 | 0.333 | 0.333 | 6 | 0.05 |
122
+ | joy | 0.978 | 0.623 | 0.646 | 0.634 | 0.623 | 161 | 0.40 |
123
+ | love | 0.982 | 0.740 | 0.899 | 0.812 | 0.807 | 238 | 0.25 |
124
+ | nervousness | 0.996 | 0.571 | 0.348 | 0.432 | 0.444 | 23 | 0.25 |
125
+ | optimism | 0.971 | 0.580 | 0.565 | 0.572 | 0.557 | 186 | 0.20 |
126
+ | pride | 0.998 | 0.875 | 0.438 | 0.583 | 0.618 | 16 | 0.10 |
127
+ | realization | 0.961 | 0.270 | 0.262 | 0.266 | 0.246 | 145 | 0.15 |
128
+ | relief | 0.992 | 0.152 | 0.636 | 0.246 | 0.309 | 11 | 0.05 |
129
+ | remorse | 0.991 | 0.541 | 0.946 | 0.688 | 0.712 | 56 | 0.10 |
130
+ | sadness | 0.977 | 0.599 | 0.583 | 0.591 | 0.579 | 156 | 0.40 |
131
+ | surprise | 0.977 | 0.543 | 0.674 | 0.601 | 0.593 | 141 | 0.15 |
132
+ | neutral | 0.758 | 0.598 | 0.810 | 0.688 | 0.513 | 1787 | 0.25 |
133
+
134
+ This improves the overall metrics:
135
+
136
+ - Precision: 0.542
137
+ - Recall: 0.577
138
+ - F1: 0.541
139
+
140
+ Or if calculated weighted by the relative size of the support of each label:
141
+
142
+ - Precision: 0.572
143
+ - Recall: 0.677
144
+ - F1: 0.611
145
+
146
+ #### Commentary on the dataset
147
+
148
+ Some labels (E.g. gratitude) when considered independently perform very strongly with F1 exceeding 0.9, whilst others (E.g. relief) perform very poorly.
149
+
150
+ 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).
151
+
152
+ 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.
config.json ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "SamLowe/roberta-base-go_emotions",
3
+ "architectures": [
4
+ "RobertaForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "admiration",
15
+ "1": "amusement",
16
+ "2": "anger",
17
+ "3": "annoyance",
18
+ "4": "approval",
19
+ "5": "caring",
20
+ "6": "confusion",
21
+ "7": "curiosity",
22
+ "8": "desire",
23
+ "9": "disappointment",
24
+ "10": "disapproval",
25
+ "11": "disgust",
26
+ "12": "embarrassment",
27
+ "13": "excitement",
28
+ "14": "fear",
29
+ "15": "gratitude",
30
+ "16": "grief",
31
+ "17": "joy",
32
+ "18": "love",
33
+ "19": "nervousness",
34
+ "20": "optimism",
35
+ "21": "pride",
36
+ "22": "realization",
37
+ "23": "relief",
38
+ "24": "remorse",
39
+ "25": "sadness",
40
+ "26": "surprise",
41
+ "27": "neutral"
42
+ },
43
+ "initializer_range": 0.02,
44
+ "intermediate_size": 3072,
45
+ "label2id": {
46
+ "admiration": 0,
47
+ "amusement": 1,
48
+ "anger": 2,
49
+ "annoyance": 3,
50
+ "approval": 4,
51
+ "caring": 5,
52
+ "confusion": 6,
53
+ "curiosity": 7,
54
+ "desire": 8,
55
+ "disappointment": 9,
56
+ "disapproval": 10,
57
+ "disgust": 11,
58
+ "embarrassment": 12,
59
+ "excitement": 13,
60
+ "fear": 14,
61
+ "gratitude": 15,
62
+ "grief": 16,
63
+ "joy": 17,
64
+ "love": 18,
65
+ "nervousness": 19,
66
+ "neutral": 27,
67
+ "optimism": 20,
68
+ "pride": 21,
69
+ "realization": 22,
70
+ "relief": 23,
71
+ "remorse": 24,
72
+ "sadness": 25,
73
+ "surprise": 26
74
+ },
75
+ "layer_norm_eps": 1e-05,
76
+ "max_position_embeddings": 514,
77
+ "model_type": "roberta",
78
+ "num_attention_heads": 12,
79
+ "num_hidden_layers": 12,
80
+ "pad_token_id": 1,
81
+ "position_embedding_type": "absolute",
82
+ "problem_type": "multi_label_classification",
83
+ "transformers_version": "4.43.4",
84
+ "type_vocab_size": 1,
85
+ "use_cache": true,
86
+ "vocab_size": 50265
87
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
onnx/model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9030077129762d29c9362fef3a177954607311862e3e7abcfa35ed1b3f28a074
3
+ size 498950580
onnx/model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2bfb174aca41977c5a02dad5c058c5e517e84d8e3ed6d88fbc70522216153289
3
+ size 125924855
quantize_config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "per_channel": true,
3
+ "reduce_range": true,
4
+ "per_model_config": {
5
+ "model": {
6
+ "op_types": [
7
+ "Shape",
8
+ "Gather",
9
+ "Equal",
10
+ "Pow",
11
+ "Sub",
12
+ "Not",
13
+ "Div",
14
+ "ConstantOfShape",
15
+ "Expand",
16
+ "Unsqueeze",
17
+ "Reshape",
18
+ "Gemm",
19
+ "Constant",
20
+ "Slice",
21
+ "CumSum",
22
+ "Erf",
23
+ "MatMul",
24
+ "Cast",
25
+ "Sqrt",
26
+ "Mul",
27
+ "Add",
28
+ "Softmax",
29
+ "Concat",
30
+ "Tanh",
31
+ "Where",
32
+ "Transpose",
33
+ "ReduceMean"
34
+ ],
35
+ "weight_type": "QInt8"
36
+ }
37
+ }
38
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "<s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "<mask>",
25
+ "lstrip": true,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "</s>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "<unk>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "0": {
5
+ "content": "<s>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "1": {
13
+ "content": "<pad>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": true
19
+ },
20
+ "2": {
21
+ "content": "</s>",
22
+ "lstrip": false,
23
+ "normalized": false,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": true
27
+ },
28
+ "3": {
29
+ "content": "<unk>",
30
+ "lstrip": false,
31
+ "normalized": false,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": true
35
+ },
36
+ "50264": {
37
+ "content": "<mask>",
38
+ "lstrip": true,
39
+ "normalized": false,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": true
43
+ }
44
+ },
45
+ "bos_token": "<s>",
46
+ "clean_up_tokenization_spaces": true,
47
+ "cls_token": "<s>",
48
+ "eos_token": "</s>",
49
+ "errors": "replace",
50
+ "mask_token": "<mask>",
51
+ "max_length": 128,
52
+ "model_max_length": 512,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "<pad>",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "</s>",
58
+ "stride": 0,
59
+ "tokenizer_class": "RobertaTokenizer",
60
+ "trim_offsets": true,
61
+ "truncation_side": "right",
62
+ "truncation_strategy": "longest_first",
63
+ "unk_token": "<unk>"
64
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff