karantonis commited on
Commit
7c43e3d
·
1 Parent(s): 6f5dfd2

app is done

Browse files
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
3
+ import torch
4
+ import json
5
+
6
+ model = DistilBertForSequenceClassification.from_pretrained('./arxiv_classifier')
7
+ tokenizer = DistilBertTokenizer.from_pretrained('./arxiv_classifier')
8
+
9
+ with open('./arxiv_classifier/index_to_category.json', 'r', encoding='utf-8') as f:
10
+ index_to_category = json.load(f)
11
+
12
+ def predict(title, summary):
13
+ inputs = tokenizer(title + " " + summary, return_tensors="pt", padding=True, truncation=True)
14
+ outputs = model(**inputs)
15
+ predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16
+ return predictions
17
+
18
+ st.set_page_config(page_title="ArXiv Article Classifier", layout="centered")
19
+
20
+ st.title("ArXiv Article Classifier")
21
+ st.write("Введите заголовок и аннотацию статьи, чтобы получить предсказание категории.")
22
+
23
+ title = st.text_input("Заголовок статьи", placeholder="Введите заголовок статьи здесь")
24
+ summary = st.text_area("Аннотация статьи", placeholder="Введите аннотацию статьи здесь")
25
+
26
+ # Кнопка для классификации
27
+ if st.button("Классифицировать"):
28
+ if title.strip() == "" and summary.strip() == "":
29
+ st.error("Пожалуйста, введите заголовок или аннотацию статьи.")
30
+ else:
31
+ with st.spinner("Классификация..."):
32
+ predictions = predict(title, summary)
33
+ sorted_indices = torch.argsort(predictions[0], descending=True)
34
+ cumulative_probability = 0.0
35
+ st.subheader("Результаты классификации:")
36
+ for idx in sorted_indices:
37
+ probability = predictions[0][idx].item()
38
+ cumulative_probability += probability
39
+ category_name = index_to_category.get(str(idx.item()), "Unknown")
40
+ st.write(f"Категория {category_name}: {probability:.2f}")
41
+ if cumulative_probability >= 0.95:
42
+ break
43
+
44
+ st.markdown(
45
+ """
46
+ <style>
47
+ .stButton>button {
48
+ background-color: #4CAF50;
49
+ color: white;
50
+ padding: 10px 24px;
51
+ border: none;
52
+ border-radius: 4px;
53
+ cursor: pointer;
54
+ }
55
+ .stButton>button:hover {
56
+ background-color: #45a049;
57
+ }
58
+ </style>
59
+ """,
60
+ unsafe_allow_html=True
61
+ )
arxiv_classifier/config.json ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertForSequenceClassification"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "hidden_dim": 3072,
10
+ "id2label": {
11
+ "0": "LABEL_0",
12
+ "1": "LABEL_1",
13
+ "2": "LABEL_2",
14
+ "3": "LABEL_3",
15
+ "4": "LABEL_4",
16
+ "5": "LABEL_5",
17
+ "6": "LABEL_6",
18
+ "7": "LABEL_7",
19
+ "8": "LABEL_8",
20
+ "9": "LABEL_9",
21
+ "10": "LABEL_10",
22
+ "11": "LABEL_11",
23
+ "12": "LABEL_12",
24
+ "13": "LABEL_13",
25
+ "14": "LABEL_14",
26
+ "15": "LABEL_15",
27
+ "16": "LABEL_16",
28
+ "17": "LABEL_17",
29
+ "18": "LABEL_18",
30
+ "19": "LABEL_19",
31
+ "20": "LABEL_20",
32
+ "21": "LABEL_21",
33
+ "22": "LABEL_22",
34
+ "23": "LABEL_23",
35
+ "24": "LABEL_24",
36
+ "25": "LABEL_25",
37
+ "26": "LABEL_26",
38
+ "27": "LABEL_27",
39
+ "28": "LABEL_28",
40
+ "29": "LABEL_29",
41
+ "30": "LABEL_30",
42
+ "31": "LABEL_31"
43
+ },
44
+ "initializer_range": 0.02,
45
+ "label2id": {
46
+ "LABEL_0": 0,
47
+ "LABEL_1": 1,
48
+ "LABEL_10": 10,
49
+ "LABEL_11": 11,
50
+ "LABEL_12": 12,
51
+ "LABEL_13": 13,
52
+ "LABEL_14": 14,
53
+ "LABEL_15": 15,
54
+ "LABEL_16": 16,
55
+ "LABEL_17": 17,
56
+ "LABEL_18": 18,
57
+ "LABEL_19": 19,
58
+ "LABEL_2": 2,
59
+ "LABEL_20": 20,
60
+ "LABEL_21": 21,
61
+ "LABEL_22": 22,
62
+ "LABEL_23": 23,
63
+ "LABEL_24": 24,
64
+ "LABEL_25": 25,
65
+ "LABEL_26": 26,
66
+ "LABEL_27": 27,
67
+ "LABEL_28": 28,
68
+ "LABEL_29": 29,
69
+ "LABEL_3": 3,
70
+ "LABEL_30": 30,
71
+ "LABEL_31": 31,
72
+ "LABEL_4": 4,
73
+ "LABEL_5": 5,
74
+ "LABEL_6": 6,
75
+ "LABEL_7": 7,
76
+ "LABEL_8": 8,
77
+ "LABEL_9": 9
78
+ },
79
+ "max_position_embeddings": 512,
80
+ "model_type": "distilbert",
81
+ "n_heads": 12,
82
+ "n_layers": 6,
83
+ "output_past": true,
84
+ "pad_token_id": 0,
85
+ "problem_type": "single_label_classification",
86
+ "qa_dropout": 0.1,
87
+ "seq_classif_dropout": 0.2,
88
+ "sinusoidal_pos_embds": false,
89
+ "tie_weights_": true,
90
+ "torch_dtype": "float32",
91
+ "transformers_version": "4.50.3",
92
+ "vocab_size": 28996
93
+ }
arxiv_classifier/index_to_category.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "0": "cs.SI",
3
+ "1": "cs.SD",
4
+ "2": "cs.RO",
5
+ "3": "cs.DC",
6
+ "4": "cs.OS",
7
+ "5": "stat.ML",
8
+ "6": "cs.CR",
9
+ "7": "cs.SE",
10
+ "8": "cs.LG",
11
+ "9": "eess.AS",
12
+ "10": "cs.NI",
13
+ "11": "astro-ph.IM",
14
+ "12": "astro-ph.EP",
15
+ "13": "eess.SY",
16
+ "14": "cs.MM",
17
+ "15": "cs.CV",
18
+ "16": "cs.GR",
19
+ "17": "cs.AI",
20
+ "18": "math.OC",
21
+ "19": "cs.GT",
22
+ "20": "cs.CL",
23
+ "21": "cs.HC",
24
+ "22": "cs.DB",
25
+ "23": "q-bio.QM",
26
+ "24": "cs.DS",
27
+ "25": "cs.CY",
28
+ "26": "cs.DM",
29
+ "27": "cs.MA",
30
+ "28": "eess.SP",
31
+ "29": "q-bio.BM",
32
+ "30": "cs.IR",
33
+ "31": "eess.IV"
34
+ }
arxiv_classifier/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:344b60cef9157ff25876033fd760d0e2a44b92ad6500127c6e570b957962725b
3
+ size 263236976
arxiv_classifier/special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
arxiv_classifier/tokenizer_config.json ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
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
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 512,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "DistilBertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
arxiv_classifier/vocab.txt ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ transformers
3
+ torch