fyaronskiy
commited on
Commit
•
ce12729
1
Parent(s):
3bbbbde
Update README.md
Browse files
README.md
CHANGED
@@ -26,6 +26,7 @@ dataset for multilabel classification. Model can be used to extract all emotions
|
|
26 |
# Usage
|
27 |
Using model with Huggingface Transformers:
|
28 |
```python
|
|
|
29 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
30 |
tokenizer = AutoTokenizer.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
31 |
model = AutoModelForSequenceClassification.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
@@ -42,13 +43,12 @@ def predict_emotions(text):
|
|
42 |
inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
|
43 |
with torch.no_grad():
|
44 |
logits = model(**inputs).logits
|
45 |
-
probas = torch.sigmoid(logits).squeeze(dim=0)
|
46 |
-
|
47 |
-
|
48 |
-
class_binary_labels = (probas > np.array(best_thresholds)).astype(int)
|
49 |
return [ID2LABEL[label_id] for label_id, value in enumerate(class_binary_labels) if value == 1]
|
50 |
|
51 |
print(predict_emotions('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
|
|
|
52 |
#['admiration', 'love']
|
53 |
```
|
54 |
|
|
|
26 |
# Usage
|
27 |
Using model with Huggingface Transformers:
|
28 |
```python
|
29 |
+
import torch
|
30 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
31 |
tokenizer = AutoTokenizer.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
32 |
model = AutoModelForSequenceClassification.from_pretrained("fyaronskiy/ruRoberta-large-ru-go-emotions")
|
|
|
43 |
inputs = tokenizer(text, truncation=True, add_special_tokens=True, max_length=128, return_tensors='pt')
|
44 |
with torch.no_grad():
|
45 |
logits = model(**inputs).logits
|
46 |
+
probas = torch.sigmoid(logits).squeeze(dim=0)
|
47 |
+
class_binary_labels = (probas > torch.tensor(best_thresholds)).int()
|
|
|
|
|
48 |
return [ID2LABEL[label_id] for label_id, value in enumerate(class_binary_labels) if value == 1]
|
49 |
|
50 |
print(predict_emotions('У вас отличный сервис и лучший кофе в городе, обожаю вашу кофейню!'))
|
51 |
+
|
52 |
#['admiration', 'love']
|
53 |
```
|
54 |
|