Модель тональности для темы S7 Airlines.
1import json, torch
2from transformers import AutoTokenizer, AutoModel
3from torch import nn
4
5LABEL_MAP = {0: -1, 1: 0, 2: 1} # index → tone
6
7tokenizer = AutoTokenizer.from_pretrained("DanielNRU/S7-sentiment-rubert-20260809")
8# model = RuBERTSentimentClassifier("DeepPavlov/rubert-base-cased")
9# model.load_state_dict(torch.load("best_pytorch_model.bin", map_location="cpu"))
10model.eval()
11
12text = "Задержали рейс на 3 часа без предупреждения"
13enc = tokenizer(
14 "S7 Airlines",
15 text,
16 max_length=512,
17 truncation=True,
18 padding="max_length",
19 return_tensors="pt",
20)
21with torch.no_grad():
22 logits = model(enc["input_ids"], enc["attention_mask"])
23 label = logits.argmax(-1).item()
24print("Тональность:", LABEL_MAP[label]) # -1 / 0 / +1