File size: 2,326 Bytes
59c4b3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab4a797
59c4b3a
 
 
caf57f7
ab4a797
59c4b3a
 
 
 
 
 
 
 
 
 
 
 
 
b96b9c6
59c4b3a
 
 
 
 
ab4a797
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---

language: ru
tags:
- toxicity
- binary-classification
- russian
- RoBERTa
license: mit
---


# Toxicity Classifier for Russian Texts

## Model description

This model is a fine-tuned version of **[ai-forever/ru-en-RoSBERTa](https://huggingface.co/ai-forever/ru-en-RoSBERTa)** for binary classification of Russian texts into **toxic** (1) and **non-toxic** (0).

It was trained on a balanced dataset of ~74k examples (split 80/10/10) derived from several public sources:
- Toxic: ok.ru comments, inappropriate messages, multilingual toxicity data.
- Non-toxic: voice assistant commands, intent datasets, QA pairs.

Only the classification head was trained; the encoder weights were frozen.

## Metrics (on test set)

| Metric     | Value  |
|------------|--------|
| Accuracy   | 0.9992 |
| Precision  | 0.9992 |
| Recall     | 0.9992 |
| F1         | 0.9992 |
| MCC        | 0.9984 |
| ROC AUC    | 1.0000 |

Confusion matrix:
[[3713 3]
[ 3 3713]]

## How to use

```python

from transformers import AutoModelForSequenceClassification, AutoTokenizer

import torch



model_name = "RooLeX/Homework2-llm-toxicity"

tokenizer = AutoTokenizer.from_pretrained(model_name)

model = AutoModelForSequenceClassification.from_pretrained(model_name)



def predict_toxicity(text):

    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=64)

    with torch.no_grad():

        outputs = model(**inputs)

    probs = torch.softmax(outputs.logits, dim=-1)

    return int(torch.argmax(probs)), probs[0, 1].item()



# Пример

print(predict_toxicity("Ты идиот!"))  # (1, ~0.9998)

print(predict_toxicity("Здравствуйте, чем могу помочь?"))  # (0, ~0.0000)

```

## Training details
- Base model: ai-forever/ru-en-RoSBERTa
- Max sequence length: 64 tokens
- Batch size: 64
- Learning rate: 2e-4
- Optimizer: AdamW
- Scheduler: CosineAnnealingWarmRestarts
- Early stopping with patience=3 on validation loss

## Limitations
- The model was trained on a limited set of domains (social media, customer support, QA). Performance may degrade on very different styles.
- It works only for Russian language.
- May misinterpret sarcasm or cultural references.

## Authors
RooLeX

## Contact
Hugging Face: RooLeX