igorithm commited on
Commit
92deaca
·
1 Parent(s): 9a9d9d2

Add pipeline

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ trained_model/model.safetensors filter=lfs diff=lfs merge=lfs -text
bert_paper_classifier.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import Pipeline
2
+ from collections.abc import Iterable
3
+ import torch
4
+
5
+ class SciBertPaperClassifierPipeline(Pipeline):
6
+ def _sanitize_parameters(self, **kwargs):
7
+ return {}, {}, {}
8
+
9
+ def preprocess(self, inputs):
10
+ if not isinstance(inputs, Iterable):
11
+ inputs = [inputs]
12
+ texts = [
13
+ f"AUTHORS: {' '.join(paper.authors) if isinstance(paper.authors, list) else paper.authors} "
14
+ f"TITLE: {paper.title} ABSTRACT: {paper.abstract}"
15
+ for paper in inputs
16
+ ]
17
+ inputs = self.tokenizer(
18
+ texts, truncation=True, padding=True, max_length=256, return_tensors="pt"
19
+ ).to(self.device)
20
+ return inputs
21
+
22
+ def _forward(self, model_inputs):
23
+ with torch.no_grad():
24
+ outputs = self.model(**model_inputs)
25
+ return outputs
26
+
27
+ def postprocess(self, model_outputs):
28
+ probs = torch.nn.functional.softmax(model_outputs.logits, dim=-1)
29
+ results = []
30
+ for prob in probs:
31
+ result = [
32
+ {self.model.config.id2label[label_idx]: score.item()}
33
+ for label_idx, score in enumerate(prob)
34
+ ]
35
+ results.append(result)
36
+ if 1 == len(results):
37
+ return results[0]
38
+ return results
trained_model/config.json ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "acc-phys",
12
+ "1": "adap-org",
13
+ "2": "alg-geom",
14
+ "3": "ao-sci",
15
+ "4": "astro-ph",
16
+ "5": "atom-ph",
17
+ "6": "chao-dyn",
18
+ "7": "chem-ph",
19
+ "8": "cmp-lg",
20
+ "9": "comp-gas",
21
+ "10": "cond-mat",
22
+ "11": "cs",
23
+ "12": "dg-ga",
24
+ "13": "econ",
25
+ "14": "eess",
26
+ "15": "funct-an",
27
+ "16": "gr-qc",
28
+ "17": "hep-ex",
29
+ "18": "hep-lat",
30
+ "19": "hep-ph",
31
+ "20": "hep-th",
32
+ "21": "math",
33
+ "22": "math-ph",
34
+ "23": "mtrl-th",
35
+ "24": "nlin",
36
+ "25": "nucl-ex",
37
+ "26": "nucl-th",
38
+ "27": "patt-sol",
39
+ "28": "physics",
40
+ "29": "plasm-ph",
41
+ "30": "q-alg",
42
+ "31": "q-bio",
43
+ "32": "q-fin",
44
+ "33": "quant-ph",
45
+ "34": "solv-int",
46
+ "35": "stat",
47
+ "36": "supr-con"
48
+ },
49
+ "initializer_range": 0.02,
50
+ "intermediate_size": 3072,
51
+ "label2id": {
52
+ "acc-phys": 0,
53
+ "adap-org": 1,
54
+ "alg-geom": 2,
55
+ "ao-sci": 3,
56
+ "astro-ph": 4,
57
+ "atom-ph": 5,
58
+ "chao-dyn": 6,
59
+ "chem-ph": 7,
60
+ "cmp-lg": 8,
61
+ "comp-gas": 9,
62
+ "cond-mat": 10,
63
+ "cs": 11,
64
+ "dg-ga": 12,
65
+ "econ": 13,
66
+ "eess": 14,
67
+ "funct-an": 15,
68
+ "gr-qc": 16,
69
+ "hep-ex": 17,
70
+ "hep-lat": 18,
71
+ "hep-ph": 19,
72
+ "hep-th": 20,
73
+ "math": 21,
74
+ "math-ph": 22,
75
+ "mtrl-th": 23,
76
+ "nlin": 24,
77
+ "nucl-ex": 25,
78
+ "nucl-th": 26,
79
+ "patt-sol": 27,
80
+ "physics": 28,
81
+ "plasm-ph": 29,
82
+ "q-alg": 30,
83
+ "q-bio": 31,
84
+ "q-fin": 32,
85
+ "quant-ph": 33,
86
+ "solv-int": 34,
87
+ "stat": 35,
88
+ "supr-con": 36
89
+ },
90
+ "layer_norm_eps": 1e-12,
91
+ "max_position_embeddings": 512,
92
+ "model_type": "bert",
93
+ "num_attention_heads": 12,
94
+ "num_hidden_layers": 12,
95
+ "pad_token_id": 0,
96
+ "position_embedding_type": "absolute",
97
+ "problem_type": "single_label_classification",
98
+ "torch_dtype": "float32",
99
+ "transformers_version": "4.51.0",
100
+ "type_vocab_size": 2,
101
+ "use_cache": true,
102
+ "vocab_size": 31090
103
+ }
trained_model/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:012246932c7f834f77cb6ccc1fd6045e2ab13c386de6b8f67d7d6d4f90b734a8
3
+ size 439811204
trained_model/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
+ }
trained_model/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
trained_model/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
+ "101": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "102": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "103": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "104": {
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": true,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
51
+ "never_split": null,
52
+ "pad_token": "[PAD]",
53
+ "sep_token": "[SEP]",
54
+ "strip_accents": null,
55
+ "tokenize_chinese_chars": true,
56
+ "tokenizer_class": "BertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
trained_model/vocab.txt ADDED
The diff for this file is too large to render. See raw diff