CoolFace
Modelpublic

fyaronskiy/deberta-v1-base-russian-go-emotions

sourceHugging Facemitupdated 2y agoView on Hugging Face
3likes131downloads
Model Card

This is the model for detecting 27 types of emotions in russian texts. Leaderboard of opensource models:

ModelF1 macroF1 macro weightedPrecision macroRecall macroSize
seara/rubert-tiny2-ru-go-emotions0.330.480.510.2929.2M
seara/rubert-base-cased-ru-go-emotions0.360.490.520.31178M
fyaronskiy/ruRoberta-large-ru-go-emotions default thresholds = 0.50.410.520.580.36355M
fyaronskiy/ruRoberta-large-ru-go-emotions best thresholds0.480.580.460.55355M
fyaronskiy/deberta-v1-base-russian-go-emotions0.480.570.460.54125M

Summary

This is deepvk/deberta-v1-base model finetuned on ru_go_emotions dataset for multilabel classification. Model can be used to extract all emotions from text or detect certain emotions. Thresholds are selected on validation set by maximizing f1 macro over all labels.

The quality of the model varies greatly across all classes (look at the table with metrics below). There are classes like amusement, gratitude, fear where the model shows high recognition quality, and classes that pose difficulties for the model - relief, realization.

Usage

Using model with Huggingface Transformers:

python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("fyaronskiy/deepvk_deberta-v1-base__bs32_max_len128_ep10_lr5e-05_lr_sheduler_linear")
model = AutoModelForSequenceClassification.from_pretrained("fyaronskiy/deepvk_deberta-v1-base__bs32_max_len128_ep10_lr5e-05_lr_sheduler_linear")

best_thresholds = [0.5510204081632653, 0.18367346938775508, 0.1020408163265306, 0.1020408163265306, 0.18367346938775508, 0.22448979591836732, 0.2040816326530612, 0.4081632653061224, 0.2040816326530612, 0.22448979591836732, 0.24489795918367346, 0.3061224489795918, 0.16326530612244897, 0.2857142857142857, 0.3877551020408163, 0.32653061224489793, 0.02040816326530612, 0.16326530612244897, 0.44897959183673464, 0.1020408163265306, 0.22448979591836732, 0.04081632653061224, 0.12244897959183673, 0.061224489795918366, 0.14285714285714285, 0.42857142857142855, 0.3061224489795918, 0.26530612244897955]
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']
ID2LABEL = dict(enumerate(LABELS))

Here is how you can extract emotions contained in text:

python
def detect_emotions(text):
  inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
  with torch.no_grad():
      logits = model(**inputs).logits
  probas = torch.sigmoid(logits).squeeze(dim=0)  
  class_binary_labels = (probas > torch.tensor(best_thresholds)).int()
  return [ID2LABEL[label_id] for label_id, value in enumerate(class_binary_labels) if value == 1]

print(detect_emotions('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
#['admiration', 'love']

This is the way to get all emotions and their scores:

python
def predict(text):
    inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
    with torch.no_grad():
        logits = model(**inputs).logits
    probas = torch.sigmoid(logits).squeeze(dim=0).tolist()
    probas = [round(proba, 3) for proba in probas]    
    
    labels2probas = dict(zip(LABELS, probas))
    probas_dict_sorted = dict(sorted(labels2probas.items(), key=lambda x: x[1], reverse=True))
    return probas_dict_sorted

print(predict('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
'''{'admiration': 0.842,
'love': 0.675,
'approval': 0.039,
'gratitude': 0.034,
'joy': 0.025,
'excitement': 0.009,
'neutral': 0.007,
'curiosity': 0.005,
'confusion': 0.003,
'optimism': 0.003,
'caring': 0.002,
'desire': 0.002,
'realization': 0.002,
'surprise': 0.002,
'amusement': 0.001,
'anger': 0.001,
'annoyance': 0.001,
'disappointment': 0.001,
'disapproval': 0.001,
'pride': 0.001,
'sadness': 0.001,
'disgust': 0.0,
'embarrassment': 0.0,
'fear': 0.0,
'grief': 0.0,
'nervousness': 0.0,
'relief': 0.0,
'remorse': 0.0}
'''

Eval results on test split of ru-go-emotions

precisionrecallf1-scoresupportthreshold
admiration0.690.670.685040.55
amusement0.720.910.812640.18
anger0.350.530.421980.1
annoyance0.240.460.323200.1
approval0.330.440.383510.18
caring0.370.50.421350.22
confusion0.430.420.421530.2
curiosity0.440.710.542840.41
desire0.460.430.45830.2
disappointment0.30.310.311510.22
disapproval0.370.570.452670.24
disgust0.450.410.431230.31
embarrassment0.620.350.45370.16
excitement0.30.340.321030.29
fear0.670.620.64780.39
gratitude0.920.870.893520.33
grief0.020.330.0460.02
joy0.410.660.511610.16
love0.710.830.762380.45
nervousness0.240.350.28230.1
optimism0.580.550.571860.22
pride0.580.440.5160.04
realization0.250.230.241450.12
relief0.270.360.31110.06
remorse0.490.910.63560.14
sadness0.530.530.531560.43
surprise0.490.540.511410.31
neutral0.590.780.6717870.27
micro avg0.50.640.566329
macro avg0.460.540.486329
weighted avg0.530.640.576329
samples avg0.550.670.586329

Training hyperparameters

The following hyperparameters were used during training:

  • —learning_rate: 5e-05
  • —trainbatchsize: 32
  • —seed: 28
  • —optimizer: Use adamw_torch with betas=(0.9,0.999) and epsilon=1e-08
  • —lrschedulertype: linear
  • —lrschedulerwarmup_ratio: 0.05
  • —num_epochs: 7