Token Classification
Transformers
PyTorch
English
roberta
ner
gene
protein
rna
bioinfomatics
Inference Endpoints
sschet commited on
Commit
ec26337
1 Parent(s): ff85a17

Upload 8 files

Browse files
README.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - ner
6
+ - gene
7
+ - protein
8
+ - rna
9
+ - bioinfomatics
10
+ license: apache-2.0
11
+ datasets:
12
+ - jnlpba
13
+ - tner/bc5cdr
14
+ - jnlpba
15
+ - bc2gm_corpus
16
+ - drAbreu/bc4chemd_ner
17
+ - linnaeus
18
+ - ncbi_disease
19
+ widget:
20
+ - text: "It consists of 25 exons encoding a 1,278-amino acid glycoprotein that is composed of 13 transmembrane domains"
21
+ ---
22
+
23
+ # NER to find Gene & Gene products
24
+ > The model was trained on jnlpba dataset, pretrained on this [pubmed-pretrained roberta model](/raynardj/roberta-pubmed)
25
+
26
+ All the labels, the possible token classes.
27
+ ```json
28
+ {"label2id": {
29
+ "DNA": 2,
30
+ "O": 0,
31
+ "RNA": 5,
32
+ "cell_line": 4,
33
+ "cell_type": 3,
34
+ "protein": 1
35
+ }
36
+ }
37
+ ```
38
+
39
+ Notice, we removed the 'B-','I-' etc from data label.🗡
40
+
41
+ ## This is the template we suggest for using the model
42
+ ```python
43
+ from transformers import pipeline
44
+
45
+ PRETRAINED = "raynardj/ner-gene-dna-rna-jnlpba-pubmed"
46
+ ner = pipeline(task="ner",model=PRETRAINED, tokenizer=PRETRAINED)
47
+ ner("Your text", aggregation_strategy="first")
48
+ ```
49
+ And here is to make your output more consecutive ⭐️
50
+
51
+ ```python
52
+ import pandas as pd
53
+ from transformers import AutoTokenizer
54
+ tokenizer = AutoTokenizer.from_pretrained(PRETRAINED)
55
+
56
+ def clean_output(outputs):
57
+ results = []
58
+ current = []
59
+ last_idx = 0
60
+ # make to sub group by position
61
+ for output in outputs:
62
+ if output["index"]-1==last_idx:
63
+ current.append(output)
64
+ else:
65
+ results.append(current)
66
+ current = [output, ]
67
+ last_idx = output["index"]
68
+ if len(current)>0:
69
+ results.append(current)
70
+
71
+ # from tokens to string
72
+ strings = []
73
+ for c in results:
74
+ tokens = []
75
+ starts = []
76
+ ends = []
77
+ for o in c:
78
+ tokens.append(o['word'])
79
+ starts.append(o['start'])
80
+ ends.append(o['end'])
81
+
82
+ new_str = tokenizer.convert_tokens_to_string(tokens)
83
+ if new_str!='':
84
+ strings.append(dict(
85
+ word=new_str,
86
+ start = min(starts),
87
+ end = max(ends),
88
+ entity = c[0]['entity']
89
+ ))
90
+ return strings
91
+
92
+ def entity_table(pipeline, **pipeline_kw):
93
+ if "aggregation_strategy" not in pipeline_kw:
94
+ pipeline_kw["aggregation_strategy"] = "first"
95
+ def create_table(text):
96
+ return pd.DataFrame(
97
+ clean_output(
98
+ pipeline(text, **pipeline_kw)
99
+ )
100
+ )
101
+ return create_table
102
+
103
+ # will return a dataframe
104
+ entity_table(ner)(YOUR_VERY_CONTENTFUL_TEXT)
105
+ ```
106
+
107
+ > check our NER model on
108
+ * [gene and gene products](/raynardj/ner-gene-dna-rna-jnlpba-pubmed)
109
+ * [chemical substance](/raynardj/ner-chemical-bionlp-bc5cdr-pubmed).
110
+ * [disease](/raynardj/ner-disease-ncbi-bionlp-bc5cdr-pubmed)
config.json ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "raynardj/roberta-pubmed",
3
+ "architectures": [
4
+ "RobertaForTokenClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "eos_token_id": 2,
9
+ "gradient_checkpointing": false,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "id2label": {
14
+ "0": "O",
15
+ "1": "protein",
16
+ "2": "DNA",
17
+ "3": "cell_type",
18
+ "4": "cell_line",
19
+ "5": "RNA"
20
+ },
21
+ "initializer_range": 0.02,
22
+ "intermediate_size": 3072,
23
+ "label2id": {
24
+ "DNA": 2,
25
+ "O": 0,
26
+ "RNA": 5,
27
+ "cell_line": 4,
28
+ "cell_type": 3,
29
+ "protein": 1
30
+ },
31
+ "layer_norm_eps": 1e-05,
32
+ "max_position_embeddings": 514,
33
+ "model_type": "roberta",
34
+ "num_attention_heads": 12,
35
+ "num_hidden_layers": 12,
36
+ "pad_token_id": 1,
37
+ "position_embedding_type": "absolute",
38
+ "torch_dtype": "float32",
39
+ "transformers_version": "4.9.1",
40
+ "type_vocab_size": 1,
41
+ "use_cache": true,
42
+ "vocab_size": 50265
43
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:255a480aa20741d98de5708721f9431b0b1394ed1f6e90d4094226ee45197733
3
+ size 496325623
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
1
+ {"unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>", "add_prefix_space": true, "errors": "replace", "sep_token": "</s>", "cls_token": "<s>", "pad_token": "<pad>", "mask_token": "<mask>", "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "raynardj/roberta-pubmed", "tokenizer_class": "RobertaTokenizer"}
vocab.json ADDED
The diff for this file is too large to render. See raw diff