khvatov's picture
Update README.md
70b91f2
|
raw
history blame
1.94 kB
---
license: mit
language:
- ru
tags:
- russian
- classification
- toxicity
widget:
- text: Нелепые лохи недовольны всегда и всем
---
Bert-based classifier (finetuned from [rubert-tiny2](https://huggingface.co/cointegrated/rubert-tiny2))
Merged datasets:
- [Russian Language Toxic Comments from 2ch.hk and pikabu.ru](https://www.kaggle.com/datasets/blackmoon/russian-language-toxic-comments)
- [Toxic Russian Comments from ok.ru](https://www.kaggle.com/datasets/alexandersemiletov/toxic-russian-comments)
The datasets split into train, val, test splits in 80-10-10 proportion
The metrics obtained from test dataset is as follows:
| |precision|recall|f1-score|support|
|--------|---------|------|--------|-------|
|0 |0.9827 |0.9827|0.9827 |21216 |
|1 |0.9272 |0.9274|0.9273 |5054 |
| | | | | |
|accuracy| | |0.9720 |26270 |
|macro avg|0.9550 |0.9550|0.9550 |26270 |
|weighted avg|0.9720 |0.9720|0.9720 |26270 |
### Usage
```Python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
PATH = 'khvatov/ru_toxicity_detector'
tokenizer = AutoTokenizer.from_pretrained(PATH)
model = AutoModelForSequenceClassification.from_pretrained(PATH)
# if torch.cuda.is_available():
# model.cuda()
model.to(torch.device("cpu"))
def get_toxicity_probs(text):
with torch.no_grad():
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True).to(model.device)
proba = torch.nn.functional.softmax(model(**inputs).logits, dim=1).cpu().numpy()
return proba[0]
TEXT = "Марк был хороший"
print(f'text = {TEXT}, probs={get_toxicity_probs(TEXT)}')
# text = Марк был хороший, probs=[0.9940585 0.00594147]
```
### Train
The model has been trained with Adam optimizer, the learning rate of 2e-5, and batch size of 32 for 3 epochs