qquarkq commited on
Commit
f2cd704
·
verified ·
1 Parent(s): 62d0350

Initial model upload with metrics and example usage

Browse files
Files changed (5) hide show
  1. README.md +94 -0
  2. config.json +14 -0
  3. pytorch_model.bin +3 -0
  4. tokenizer.json +0 -0
  5. tokenizer_config.json +24 -0
README.md ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ language: ru
4
+ license: mit
5
+ tags:
6
+ - toxicity
7
+ - multilabel
8
+ - russian
9
+ - multitask
10
+ - rubert
11
+ - profanity
12
+ - threat
13
+ - illegal
14
+ metrics:
15
+ - f1
16
+ - precision
17
+ - recall
18
+ - auc
19
+ pipeline_tag: text-classification
20
+ ---
21
+
22
+ # Multi-Task Toxicity Classifier
23
+
24
+ ## Описание
25
+
26
+ Модель для одновременного обнаружения трёх типов токсичности в русскоязычных текстах:
27
+ - **Profanity** (ненормативная лексика)
28
+ - **Threat** (угрозы)
29
+ - **Illegal** (запросы на нарушение закона)
30
+
31
+ Модель основана на энкодере `cointegrated/rubert-tiny2` с тремя независимыми классификационными головами.
32
+
33
+ ## Метрики на валидационной выборке
34
+
35
+ | Класс | Threshold | Precision | Recall | F1-Score |
36
+ |-------|-----------|-----------|--------|----------|
37
+ | Profanity | 0.63 | 0.9048 | 0.9429 | 0.9235 |
38
+ | Threat | 0.74 | 0.7462 | 0.8097 | 0.7766 |
39
+ | Illegal | 0.89 | 0.6038 | 0.6598 | 0.6305 |
40
+
41
+ **Macro F1-Score:** 0.7769
42
+
43
+
44
+ ## Использование
45
+
46
+ ```python
47
+ from transformers import AutoTokenizer, AutoModel
48
+ import torch
49
+ import json
50
+
51
+ # Загрузка модели и токенизатора
52
+ model = AutoModel.from_pretrained("qquarkq/multitask-toxicity-classifier")
53
+ tokenizer = AutoTokenizer.from_pretrained("qquarkq/multitask-toxicity-classifier")
54
+
55
+ # Загрузка конфигурации с порогами
56
+ with open("config.json", "r") as f:
57
+ config = json.load(f)
58
+ thresholds = config["thresholds"]
59
+
60
+ def predict_toxicity(text):
61
+ encoding = tokenizer(
62
+ text,
63
+ truncation=True,
64
+ padding='max_length',
65
+ max_length=128,
66
+ return_tensors='pt'
67
+ )
68
+
69
+ with torch.no_grad():
70
+ profanity_logits, threat_logits, illegal_logits = model(
71
+ encoding['input_ids'],
72
+ encoding['attention_mask']
73
+ )
74
+
75
+ profanity_prob = torch.sigmoid(profanity_logits).item()
76
+ threat_prob = torch.sigmoid(threat_logits).item()
77
+ illegal_prob = torch.sigmoid(illegal_logits).item()
78
+
79
+ profanity_pred = int(profanity_prob >= thresholds['profanity'])
80
+ threat_pred = int(threat_prob >= thresholds['threat'])
81
+ illegal_pred = int(illegal_prob >= thresholds['illegal'])
82
+ return {
83
+ 'profanity': profanity_prob,
84
+ 'threat': threat_prob,
85
+ 'illegal': illegal_prob
86
+ }
87
+
88
+ # Пример использования
89
+ text = "Ты полный идиот!"
90
+ result = predict_toxicity(text)
91
+ print(result)
92
+ ````
93
+ Датасет
94
+ Модель обучена на датасете [qquarkq/russian-toxic-multilabel-comments](https://huggingface.co/datasets/qquarkq/russian-toxic-multilabel-comments)
config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "cointegrated/rubert-tiny2",
3
+ "num_classes": 3,
4
+ "task_names": [
5
+ "profanity",
6
+ "threat",
7
+ "illegal"
8
+ ],
9
+ "thresholds": {
10
+ "profanity": 0.6299999999999997,
11
+ "threat": 0.7399999999999997,
12
+ "illegal": 0.8899999999999996
13
+ }
14
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f6f595c0887588c5075680dd7de573482c45e1cbe37bdd9dac3ef6215a44a76
3
+ size 116803262
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "backend": "tokenizers",
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": false,
6
+ "is_local": false,
7
+ "local_files_only": false,
8
+ "mask_token": "[MASK]",
9
+ "max_length": 512,
10
+ "model_max_length": 2048,
11
+ "never_split": null,
12
+ "pad_to_multiple_of": null,
13
+ "pad_token": "[PAD]",
14
+ "pad_token_type_id": 0,
15
+ "padding_side": "right",
16
+ "sep_token": "[SEP]",
17
+ "stride": 0,
18
+ "strip_accents": null,
19
+ "tokenize_chinese_chars": true,
20
+ "tokenizer_class": "BertTokenizer",
21
+ "truncation_side": "right",
22
+ "truncation_strategy": "longest_first",
23
+ "unk_token": "[UNK]"
24
+ }