Views
No views yet
1# Correct prediction (100% accuracy):
2Target: "0 1 10"
3Prediction: "0 1 10"
4
5# Incorrect predictions (0% accuracy):
6Target: "0 1 10"
7Prediction: "0 1" # Partial match is considered incorrect
8Target: "0 1 10"
9Prediction: "0 1 10 2" # Extra label is considered incorrect1import torch
2from transformers import RobertaTokenizer, RobertaForSequenceClassification
3
4
5model_name = 'ai-forever/ruRoberta-large'
6device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
7
8tokenizer = RobertaTokenizer.from_pretrained(model_name)
9class_descriptions = pd.read_csv('files/trends_description.csv')
10
11class BERTClass(torch.nn.Module):
12 def __init__(self):
13 super(BERTClass, self).__init__()
14 self.bert_model = RobertaForSequenceClassification.from_pretrained(
15 'metanovus/ruroberta-ecom-tech-best',
16 return_dict=True,
17 problem_type='multi_label_classification',
18 num_labels=50
19 )
20
21 def forward(self, input_ids, attn_mask, token_type_ids):
22 output = self.bert_model(
23 input_ids,
24 attention_mask=attn_mask,
25 token_type_ids=token_type_ids
26 )
27 return output.logits
28
29model = BERTClass().to(device)