Update README.md
Browse files
README.md
CHANGED
|
@@ -14,7 +14,23 @@ pipeline_tag: text-classification
|
|
| 14 |
|
| 15 |
Detect implicit toxicity in Russian (details will be later :))
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
## Model Details
|
| 20 |
|
|
|
|
| 14 |
|
| 15 |
Detect implicit toxicity in Russian (details will be later :))
|
| 16 |
|
| 17 |
+
```
|
| 18 |
+
import torch
|
| 19 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
| 20 |
+
|
| 21 |
+
text = <your_text>
|
| 22 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 23 |
+
model_name = 'arinakosovskaia/implicit_toxicity'
|
| 24 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
| 25 |
+
model = BertForSequenceClassification.from_pretrained(model_name).to(device)
|
| 26 |
+
|
| 27 |
+
encoded_text = tokenizer.encode(text, return_tensors='pt').to(device)
|
| 28 |
+
outputs = model(encoded_text)
|
| 29 |
+
|
| 30 |
+
logits = outputs[0]
|
| 31 |
+
prob = torch.nn.functional.softmax(logits, dim=1)[:, 1]
|
| 32 |
+
prob.cpu().detach().numpy()[0]
|
| 33 |
+
```
|
| 34 |
|
| 35 |
## Model Details
|
| 36 |
|