Gloomreach commited on
Commit
a97c88f
·
verified ·
1 Parent(s): cd28ab1

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +86 -0
README.md ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: ru
3
+ license: mit
4
+ library_name: transformers
5
+ tags:
6
+ - toxicity
7
+ - russian
8
+ - text-classification
9
+ base_model: cointegrated/rubert-tiny2
10
+ metrics:
11
+ - accuracy
12
+ - f1
13
+ - precision
14
+ - recall
15
+ datasets:
16
+ - Gloomreach/ru-toxicity-int-ml
17
+ ---
18
+
19
+ # Multi-Task Toxicity Classifier (Russian)
20
+
21
+ Модель для одновременного определения трёх типов токсичности в русскоязычных текстах:
22
+ - profanity — ненормативная лексика
23
+ - threat — угрозы
24
+ - illegal — призывы к нарушению закона
25
+
26
+ ## Архитектура
27
+
28
+ Модель основана на cointegrated/rubert-tiny2 с тремя независимыми классификационными головами (Multi-Task Learning).
29
+
30
+
31
+ ## Обучение
32
+
33
+ **Датасет:** [Gloomreach/ru-toxicity-int-ml](https://huggingface.co/datasets/Gloomreach/ru-toxicity-int-ml)
34
+
35
+
36
+
37
+ ## Метрики качества
38
+
39
+ | Класс | Precision | Recall | F1-Score | Threshold |
40
+ |-----------|-----------|--------|----------|-----------|
41
+ | profanity | 0.937 | 0.966 | 0.951 | 0.1 |
42
+ | threat | 0.957 | 0.957 | 0.957 | 0.2 |
43
+ | illegal | 1.000 | 0.800 | 0.889 | 0.5 |
44
+
45
+
46
+ ## Использование
47
+
48
+ ### Через transformers
49
+
50
+ ```python
51
+ import torch
52
+ import torch.nn as nn
53
+ from transformers import AutoModel, AutoTokenizer
54
+
55
+ class MultiTaskToxicityEncoder(nn.Module):
56
+ def __init__(self, model_name="cointegrated/rubert-tiny2"):
57
+ super().__init__()
58
+ self.encoder = AutoModel.from_pretrained(model_name)
59
+ hidden_size = self.encoder.config.hidden_size
60
+ self.profanity_head = nn.Linear(hidden_size, 1)
61
+ self.threat_head = nn.Linear(hidden_size, 1)
62
+ self.illegal_head = nn.Linear(hidden_size, 1)
63
+
64
+ def forward(self, input_ids, attention_mask):
65
+ outputs = self.encoder(input_ids=input_ids, attention_mask=attention_mask)
66
+ cls_embedding = outputs.last_hidden_state[:, 0, :]
67
+ return (
68
+ self.profanity_head(cls_embedding),
69
+ self.threat_head(cls_embedding),
70
+ self.illegal_head(cls_embedding)
71
+ )
72
+
73
+ #загрузка модели
74
+ model = MultiTaskToxicityEncoder.from_pretrained("Gloomreach/ru-toxicity-multi-task-encoder")
75
+ tokenizer = AutoTokenizer.from_pretrained("cointegrated/rubert-tiny2")
76
+
77
+ text = "Пример текста для проверки"
78
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=128)
79
+
80
+ with torch.no_grad():
81
+ logits = model(inputs["input_ids"], inputs["attention_mask"])
82
+ probs = torch.sigmoid(torch.cat(logits, dim=1)).numpy()[0]
83
+
84
+ print(f"Profanity: {probs[0]:.2%}")
85
+ print(f"Threat: {probs[1]:.2%}")
86
+ print(f"Illegal: {probs[2]:.2%}")