Downloads · 30 days
780
0% of all-time downloads
Aniemore/rubert-tiny2-russian-emotion-detection
rubert-tiny2-russian-emotion-detection is a text classification model from Aniemore. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
Emotion detection in Russian text over seven classes, fine-tuned from cointegrated/rubert-tiny2 on Aniemore/cedr-m7 (29M parameters).
Downloads · 30 days
780
0% of all-time downloads
All-time downloads
293K
Public
Parameters
29.2M
234 MB on disk
Likes
14
Public
Click a slice to open those files.
.bin117 MB · 49%
How the weights are stored.
F3229.2M · 100%
From the Hugging Face model README
Emotion detection in Russian text over seven classes, fine-tuned from cointegrated/rubert-tiny2 on Aniemore/cedr-m7 (29M parameters).
The head is multi-label: seven independent sigmoids, not a softmax over seven classes, so a sentence may carry more than one emotion or none at all. That is why the headline number below is ROC AUC, which needs no threshold.
| Metric | Value |
|---|---|
| ROC AUC, macro | 0.8696 |
| ROC AUC, micro | 0.9347 |
| ROC AUC, weighted | 0.9194 |
| Weighted accuracy (top-1) | 0.7662 |
| Unweighted accuracy (macro recall) | 0.6050 |
| macro-F1 @ 0.5 | 0.6015 |
| micro-F1 @ 0.5 | 0.7663 |
| Subset accuracy (exact set) | 0.7481 |
ROC AUC is threshold-free: it asks whether the model ranks the sentences carrying an emotion above the ones that do not. macro-F1 is taken at a fixed threshold of 0.5; a different operating point moves it, so tune the threshold on your own data before reading it as a ceiling. Weighted accuracy is top-1: the highest-scoring label counted against the gold set, which is a fair reading here because 1865 of the 1882 test rows carry exactly one label.
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.
Evaluated on the official 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.
import torch
from transformers import BertForSequenceClassification, AutoTokenizer
LABELS = ['neutral', 'happiness', 'sadness', 'enthusiasm', 'fear', 'anger', 'disgust']
tokenizer = AutoTokenizer.from_pretrained('Aniemore/rubert-tiny2-russian-emotion-detection')
model = BertForSequenceClassification.from_pretrained('Aniemore/rubert-tiny2-russian-emotion-detection')
@torch.no_grad()
def predict_emotion(text: str) -> str:
"""
We take the input text, tokenize it, pass it through the model, and then return the predicted label
:param text: The text to be classified
:type text: str
:return: The predicted emotion
"""
inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
outputs = model(**inputs)
predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
predicted = torch.argmax(predicted, dim=1).numpy()
return LABELS[predicted[0]]
@torch.no_grad()
def predict_emotions(text: str) -> list:
"""
It takes a string of text, tokenizes it, feeds it to the model, and returns a dictionary of emotions and their
probabilities
:param text: The text you want to classify
:type text: str
:return: A dictionary of emotions and their probabilities.
"""
inputs = tokenizer(text, max_length=512, padding=True, truncation=True, return_tensors='pt')
outputs = model(**inputs)
predicted = torch.nn.functional.softmax(outputs.logits, dim=1)
emotions_list = {}
for i in range(len(predicted.numpy()[0].tolist())):
emotions_list[LABELS[i]] = predicted.numpy()[0].tolist()[i]
return emotions_list
simple_prediction = predict_emotion("Какой же сегодня прекрасный день, братья")
not_simple_prediction = predict_emotions("Какой же сегодня прекрасный день, братья")
print(simple_prediction)
print(not_simple_prediction)
# happiness
# {'neutral': 0.0004941817605867982, 'happiness': 0.9979524612426758, 'sadness': 0.0002536600804887712, 'enthusiasm': 0.0005498139653354883, 'fear': 0.00025326196919195354, 'anger': 0.0003583927755244076, 'disgust': 0.00013807788491249084}
🤗
@misc{Aniemore,
author = {Артем Аментес, Илья Лубенец, Никита Давидчук},
title = {Открытая библиотека искусственного интеллекта для анализа и выявления эмоциональных оттенков речи человека},
year = {2022},
publisher = {Hugging Face},
journal = {Hugging Face Hub},
howpublished = {\url{https://huggingface.com/aniemore/Aniemore}},
email = {[email protected]}
}