Views
No views yet
cointegrated/rubert-tiny on Aniemore/cedr-m7 (12M parameters).| Metric | Value |
|---|---|
| ROC AUC, macro | 0.9008 |
| ROC AUC, micro | 0.9532 |
| ROC AUC, weighted | 0.9367 |
| Weighted accuracy (top-1) | 0.7965 |
| Unweighted accuracy (macro recall) | 0.6121 |
| macro-F1 @ 0.5 | 0.6036 |
| micro-F1 @ 0.5 | 0.7955 |
| Subset accuracy (exact set) | 0.7625 |
disgust has 3 examples in the test split. Its per-class numbers are noise, and they drag both macro averages. The macro figures are reported as measured rather than quietly dropping the class, but weigh them with that in mind.test split, 1882 rows, sources: twitter, LiveJournal and Lenta. Scores come from the model's own id2label order — it differs across this family, and reading the labels in the wrong order silently mislabels everything.1import torch
2from transformers import BertForSequenceClassification, AutoTokenizer
3
4LABELS = ['anger', 'disgust', 'enthusiasm', 'fear', 'happiness', 'neutral', 'sadness']
5tokenizer = AutoTokenizer.from_pretrained('Aniemore/rubert-tiny-emotion-russian-cedr-m7')
6model = BertForSequenceClassification.from_pretrained('Aniemore/rubert-tiny-emotion-russian-cedr-m7')
7
8@torch.no_grad()
9def predict_emotion(text: str) -> str:
10 """
11 We take the input text, tokenize it, pass it through the model, and then return the predicted label
12 :param text: The text to be classified
13 :type text: str
14 :return: The predicted emotion
15 """
16 inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
17 outputs = model(**inputs)
18 predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
19 predicted = torch.argmax(predicted, dim=1).numpy()
20
21 return LABELS[predicted[0]]
22
23@torch.no_grad()
24def predict_emotions(text: str) -> list:
25 """
26 It takes a string of text, tokenizes it, feeds it to the model, and returns a dictionary of emotions and their
27 probabilities
28 :param text: The text you want to classify
29 :type text: str
30 :return: A dictionary of emotions and their probabilities.
31 """
32 inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
33 outputs = model(**inputs)
34 predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
35 emotions_list = {}
36 for i in range(len(predicted.numpy()[0].tolist())):
37 emotions_list[LABELS[i]] = predicted.numpy()[0].tolist()[i]
38 return emotions_list1simple_prediction = predict_emotion("Какой же сегодня прекрасный день, братья")
2not_simple_prediction = predict_emotions("Какой же сегодня прекрасный день, братья")
3
4print(simple_prediction)
5print(not_simple_prediction)@misc{Aniemore,
author = {Артем Аментес, Илья Лубенец, Никита Давидчук},
title = {Открытая библиотека искусственного интеллекта для анализа и выявления эмоциональных оттенков речи человека},
year = {2022},
publisher = {Hugging Face},
journal = {Hugging Face Hub},
howpublished = {\url{https://huggingface.com/aniemore/Aniemore}},
email = {hello@socialcode.ru}
}