Update README.md
Browse files
README.md
CHANGED
@@ -1,199 +1,127 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
-
# Model Card for Model ID
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
license: mit
|
4 |
+
datasets:
|
5 |
+
- seara/ru_go_emotions
|
6 |
+
language:
|
7 |
+
- ru
|
8 |
+
metrics:
|
9 |
+
- f1
|
10 |
---
|
11 |
|
|
|
12 |
|
13 |
+
This is [ruRoberta-large](https://huggingface.co/ai-forever/ruRoberta-large) model finetuned on [ru_go_emotions](https://huggingface.co/datasets/seara/ru_go_emotions)
|
14 |
+
dataset for multilabel classification. Model can be used to extract all emotions from text or detect certain emotions.
|
15 |
+
|
16 |
+
# Usage
|
17 |
+
Using model with Huggingface Transformers:
|
18 |
+
```python
|
19 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
21 |
+
model = AutoModelForSequenceClassification.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
22 |
+
|
23 |
+
best_thresholds = [0.36734693877551017, 0.2857142857142857, 0.2857142857142857, 0.16326530612244897, 0.14285714285714285, 0.14285714285714285, 0.18367346938775508, 0.3469387755102041, 0.32653061224489793, 0.22448979591836732, 0.2040816326530612, 0.2857142857142857, 0.18367346938775508, 0.2857142857142857, 0.24489795918367346, 0.7142857142857142, 0.02040816326530612, 0.3061224489795918, 0.44897959183673464, 0.061224489795918366, 0.18367346938775508, 0.04081632653061224, 0.08163265306122448, 0.1020408163265306, 0.22448979591836732, 0.3877551020408163, 0.3469387755102041, 0.24489795918367346]
|
24 |
+
LABELS = ['admiration', 'amusement', 'anger', 'annoyance', 'approval', 'caring', 'confusion', 'curiosity', 'desire', 'disappointment', 'disapproval', 'disgust', 'embarrassment', 'excitement', 'fear', 'gratitude', 'grief', 'joy', 'love', 'nervousness', 'optimism', 'pride', 'realization', 'relief', 'remorse', 'sadness', 'surprise', 'neutral']
|
25 |
+
ID2LABEL = dict(enumerate(LABELS))
|
26 |
+
```
|
27 |
+
|
28 |
+
Here is how you can extract emotions contained in text:
|
29 |
+
|
30 |
+
```python
|
31 |
+
def predict_emotions(text):
|
32 |
+
inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
|
33 |
+
with torch.no_grad():
|
34 |
+
logits = model(**inputs).logits
|
35 |
+
probas = torch.sigmoid(logits).squeeze(dim=0)
|
36 |
+
probas = probas.cpu().numpy()
|
37 |
+
|
38 |
+
class_binary_labels = (probas > np.array(best_thresholds)).astype(int)
|
39 |
+
return [ID2LABEL[label_id] for label_id, value in enumerate(class_binary_labels) if value == 1]
|
40 |
+
|
41 |
+
print(predict_emotions('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
|
42 |
+
#['admiration', 'love']
|
43 |
+
```
|
44 |
+
|
45 |
+
This is the way to get all emotions and their scores:
|
46 |
+
|
47 |
+
```python
|
48 |
+
def predict(text):
|
49 |
+
inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
|
50 |
+
with torch.no_grad():
|
51 |
+
logits = model(**inputs).logits
|
52 |
+
probas = torch.sigmoid(logits).squeeze(dim=0).tolist()
|
53 |
+
probas = [round(proba, 3) for proba in probas]
|
54 |
+
|
55 |
+
labels2probas = dict(zip(LABELS, probas))
|
56 |
+
probas_dict_sorted = dict(sorted(labels2probas.items(), key=lambda x: x[1], reverse=True))
|
57 |
+
return probas_dict_sorted
|
58 |
+
|
59 |
+
print(predict('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
|
60 |
+
'''{'admiration': 0.81,
|
61 |
+
'love': 0.538,
|
62 |
+
'joy': 0.041,
|
63 |
+
'gratitude': 0.031,
|
64 |
+
'approval': 0.026,
|
65 |
+
'excitement': 0.023,
|
66 |
+
'neutral': 0.009,
|
67 |
+
'curiosity': 0.006,
|
68 |
+
'amusement': 0.005,
|
69 |
+
'desire': 0.005,
|
70 |
+
'realization': 0.005,
|
71 |
+
'caring': 0.004,
|
72 |
+
'confusion': 0.004,
|
73 |
+
'surprise': 0.004,
|
74 |
+
'disappointment': 0.003,
|
75 |
+
'disapproval': 0.003,
|
76 |
+
'anger': 0.002,
|
77 |
+
'annoyance': 0.002,
|
78 |
+
'disgust': 0.002,
|
79 |
+
'fear': 0.002,
|
80 |
+
'grief': 0.002,
|
81 |
+
'optimism': 0.002,
|
82 |
+
'pride': 0.002,
|
83 |
+
'relief': 0.002,
|
84 |
+
'sadness': 0.002,
|
85 |
+
'embarrassment': 0.001,
|
86 |
+
'nervousness': 0.001,
|
87 |
+
'remorse': 0.001}
|
88 |
+
'''
|
89 |
+
```
|
90 |
+
|
91 |
+
# Eval results on test split of ru-go-emotions
|
92 |
+
|
93 |
+
precision recall f1-score support threshold
|
94 |
+
|
95 |
+
admiration 0.63 0.75 0.69 504 0.37
|
96 |
+
amusement 0.76 0.91 0.83 264 0.29
|
97 |
+
anger 0.47 0.32 0.38 198 0.29
|
98 |
+
annoyance 0.33 0.39 0.36 320 0.16
|
99 |
+
approval 0.27 0.58 0.37 351 0.14
|
100 |
+
caring 0.32 0.59 0.41 135 0.14
|
101 |
+
confusion 0.41 0.52 0.46 153 0.18
|
102 |
+
curiosity 0.45 0.73 0.55 284 0.35
|
103 |
+
desire 0.54 0.31 0.40 83 0.33
|
104 |
+
disappointment 0.31 0.34 0.33 151 0.22
|
105 |
+
disapproval 0.31 0.57 0.40 267 0.20
|
106 |
+
disgust 0.44 0.40 0.42 123 0.29
|
107 |
+
embarrassment 0.48 0.38 0.42 37 0.18
|
108 |
+
excitement 0.29 0.43 0.34 103 0.29
|
109 |
+
fear 0.56 0.78 0.65 78 0.24
|
110 |
+
gratitude 0.95 0.85 0.89 352 0.71
|
111 |
+
grief 0.03 0.33 0.05 6 0.02
|
112 |
+
joy 0.48 0.58 0.53 161 0.31
|
113 |
+
love 0.73 0.84 0.78 238 0.45
|
114 |
+
nervousness 0.24 0.48 0.32 23 0.06
|
115 |
+
optimism 0.57 0.54 0.56 186 0.18
|
116 |
+
pride 0.67 0.38 0.48 16 0.04
|
117 |
+
realization 0.18 0.31 0.23 145 0.08
|
118 |
+
relief 0.30 0.27 0.29 11 0.10
|
119 |
+
remorse 0.53 0.84 0.65 56 0.22
|
120 |
+
sadness 0.56 0.53 0.55 156 0.39
|
121 |
+
surprise 0.55 0.57 0.56 141 0.35
|
122 |
+
neutral 0.59 0.79 0.68 1787 0.24
|
123 |
+
|
124 |
+
micro avg 0.50 0.66 0.57 6329
|
125 |
+
macro avg 0.46 0.55 0.48 6329
|
126 |
+
weighted avg 0.53 0.66 0.58 6329
|
127 |
+
samples avg 0.55 0.68 0.59 6329
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|