Kdnv commited on
Commit
56c8e26
·
1 Parent(s): ae2bdaf

natasha model

Browse files
models/model_n/config.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "cointegrated/rubert-tiny-toxicity",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "emb_size": 312,
9
+ "gradient_checkpointing": false,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 312,
13
+ "id2label": {
14
+ "0": "non-toxic",
15
+ "1": "insult",
16
+ "2": "obscenity",
17
+ "3": "threat",
18
+ "4": "dangerous"
19
+ },
20
+ "initializer_range": 0.02,
21
+ "intermediate_size": 600,
22
+ "label2id": {
23
+ "dangerous": 4,
24
+ "insult": 1,
25
+ "non-toxic": 0,
26
+ "obscenity": 2,
27
+ "threat": 3
28
+ },
29
+ "layer_norm_eps": 1e-12,
30
+ "max_position_embeddings": 512,
31
+ "model_type": "bert",
32
+ "num_attention_heads": 12,
33
+ "num_hidden_layers": 3,
34
+ "pad_token_id": 0,
35
+ "position_embedding_type": "absolute",
36
+ "problem_type": "multi_label_classification",
37
+ "torch_dtype": "float32",
38
+ "transformers_version": "4.42.4",
39
+ "type_vocab_size": 2,
40
+ "use_cache": true,
41
+ "vocab_size": 29564
42
+ }
models/model_n/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d58739fa66f1975dc1b7e930f6b146283f0593cca1d74a52ddc9643736d0c092
3
+ size 47149380
models/model_n/special_tokens_map.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "mask_token": {
10
+ "content": "[MASK]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "[PAD]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "sep_token": {
24
+ "content": "[SEP]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "unk_token": {
31
+ "content": "[UNK]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ }
37
+ }
models/model_n/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
models/model_n/tokenizer_config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": false,
48
+ "mask_token": "[MASK]",
49
+ "max_length": 512,
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "stride": 0,
55
+ "strip_accents": null,
56
+ "tokenize_chinese_chars": true,
57
+ "tokenizer_class": "BertTokenizer",
58
+ "truncation_side": "right",
59
+ "truncation_strategy": "longest_first",
60
+ "unk_token": "[UNK]"
61
+ }
models/model_n/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
pages/kdnv_model.py CHANGED
@@ -7,7 +7,7 @@ import textwrap
7
  @st.cache_resource()
8
  def load_model():
9
  model = GPT2LMHeadModel.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
10
- model.load_state_dict(torch.load('models/kdnv_model.pt', map_location=torch.device('cpu')))
11
  return model
12
 
13
 
 
7
  @st.cache_resource()
8
  def load_model():
9
  model = GPT2LMHeadModel.from_pretrained('sberbank-ai/rugpt3small_based_on_gpt2')
10
+ model.load_state_dict(torch.load('models/kdnv_model.pt', map_location=torch.device('cpu'), weights_only=True))
11
  return model
12
 
13
 
pages/natasha_model.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ from transformers import BertTokenizer, BertForSequenceClassification
4
+
5
+ # Путь к директории, где сохранена обученная модель
6
+ model_directory = './models/model_n'
7
+
8
+ # Загрузка модели и токенизатора из указанной директории
9
+ tokenizer = BertTokenizer.from_pretrained(model_directory)
10
+ model = BertForSequenceClassification.from_pretrained(model_directory)
11
+
12
+ # # Загрузка модели и токенизатора
13
+ # tokenizer = BertTokenizer.from_pretrained("cointegrated/rubert-tiny-toxicity")
14
+ # model = BertForSequenceClassification.from_pretrained("cointegrated/rubert-tiny-toxicity")
15
+
16
+ # Перевод модели в режим оценки
17
+ model.eval()
18
+
19
+ # Функция для оценки токсичности
20
+ def predict_toxicity(text):
21
+ inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
22
+ with torch.no_grad():
23
+ outputs = model(**inputs)
24
+ logits = outputs.logits
25
+ probabilities = torch.nn.functional.softmax(logits, dim=-1)
26
+ return probabilities[0][1].item() # Вероятность токсичности
27
+
28
+ # Streamlit интерфейс
29
+ st.title("Оценка степени токсичности")
30
+
31
+ # Поле ввода для пользовательского сообщения
32
+ user_input = st.text_area("Введите текст для оценки токсичности:")
33
+
34
+ # Кнопка для оценки
35
+ if st.button("Оценить токсичность"):
36
+ if user_input:
37
+ toxicity_score = predict_toxicity(user_input)
38
+ st.write(f"Вероятность токсичности: {toxicity_score:.2f}")
39
+ else:
40
+ st.write("Пожалуйста, введите текст для оценки.")