File size: 1,066 Bytes
ddf43c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
---
license: mit
language:
- ru
---

# Based on [xlm-roberta-base](https://huggingface.co/xlm-roberta-base)
# Использование
```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

del_symbs = ["?","!",".",","]
classes = ["dialog","trouble","quest","about_user","about_model","instruction"]

device = torch.device("cuda")
model_name = 'TeraSpace/replica_classification'
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels = len(classes)).to(device)

while True:
    text = input("=>").lower()
    for del_symb in del_symbs:
        text = text.replace(del_symb,"")
        
    inputs = tokenizer(text, truncation=True, max_length=512, padding='max_length',
                            return_tensors='pt').to(device)
    with torch.no_grad():
        logits = model(**inputs).logits
        probas = list(torch.sigmoid(logits)[0].cpu().detach().numpy())
        
    out = classes[probas.index(max(probas))]
    print(out)
```