Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
language:
|
4 |
+
- ru
|
5 |
+
---
|
6 |
+
|
7 |
+
# Based on [xlm-roberta-base](https://huggingface.co/xlm-roberta-base)
|
8 |
+
# Использование
|
9 |
+
```python
|
10 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
11 |
+
import torch
|
12 |
+
|
13 |
+
del_symbs = ["?","!",".",","]
|
14 |
+
classes = ["dialog","trouble","quest","about_user","about_model","instruction"]
|
15 |
+
|
16 |
+
device = torch.device("cuda")
|
17 |
+
model_name = 'TeraSpace/replica_classification'
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
19 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels = len(classes)).to(device)
|
20 |
+
|
21 |
+
while True:
|
22 |
+
text = input("=>").lower()
|
23 |
+
for del_symb in del_symbs:
|
24 |
+
text = text.replace(del_symb,"")
|
25 |
+
|
26 |
+
inputs = tokenizer(text, truncation=True, max_length=512, padding='max_length',
|
27 |
+
return_tensors='pt').to(device)
|
28 |
+
with torch.no_grad():
|
29 |
+
logits = model(**inputs).logits
|
30 |
+
probas = list(torch.sigmoid(logits)[0].cpu().detach().numpy())
|
31 |
+
|
32 |
+
out = classes[probas.index(max(probas))]
|
33 |
+
print(out)
|
34 |
+
```
|