Fine-tuned
ai-forever/sbert_large_nlu_ru
for multi-label emotion detection in Russian text.
Trained on
CEDR v1 with Focal Loss
and per-class decision thresholds.
1import json, torch, requests
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4model_id = "ilyali034/russian-emotion-classifier-sbert-large"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForSequenceClassification.from_pretrained(model_id)
7model.eval()
8
9cfg = json.loads(
10 requests.get(
11 f"https://huggingface.co/{model_id}/resolve/main/emotion_config.json"
12 ).text
13)
14labels_list = cfg["labels"]
15thresholds = cfg["thresholds"]
16
17def predict(text: str) -> dict:
18 inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
19 with torch.no_grad():
20 probs = torch.sigmoid(model(**inputs).logits)[0].cpu().numpy()
21 return {
22 lbl: round(float(p), 3)
23 for lbl, p in zip(labels_list, probs)
24 if p > thresholds[lbl]
25 }
26
27predict("Я очень рад, но немного боюсь")
28# {'joy': 0.912, 'fear': 0.701}
1@dataset{cedr_v1,
2 author = {SAGTeam},
3 title = {CEDR: Russian Emotion Dataset},
4 year = {2023},
5 url = {https://huggingface.co/datasets/sagteam/cedr_v1}
6}