chintagunta85 commited on
Commit
35406a1
1 Parent(s): 8207e5a

Upload ncbi_disease.py

Browse files
Files changed (1) hide show
  1. ncbi_disease.py +148 -0
ncbi_disease.py ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """NCBI disease corpus: a resource for disease name recognition and concept normalization"""
18
+
19
+ import datasets
20
+
21
+
22
+ logger = datasets.logging.get_logger(__name__)
23
+
24
+
25
+ _CITATION = """\
26
+ @article{dougan2014ncbi,
27
+ title={NCBI disease corpus: a resource for disease name recognition and concept normalization},
28
+ author={Dogan, Rezarta Islamaj and Leaman, Robert and Lu, Zhiyong},
29
+ journal={Journal of biomedical informatics},
30
+ volume={47},
31
+ pages={1--10},
32
+ year={2014},
33
+ publisher={Elsevier}
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ This paper presents the disease name and concept annotations of the NCBI disease corpus, a collection of 793 PubMed
39
+ abstracts fully annotated at the mention and concept level to serve as a research resource for the biomedical natural
40
+ language processing community. Each PubMed abstract was manually annotated by two annotators with disease mentions
41
+ and their corresponding concepts in Medical Subject Headings (MeSH®) or Online Mendelian Inheritance in Man (OMIM®).
42
+ Manual curation was performed using PubTator, which allowed the use of pre-annotations as a pre-step to manual annotations.
43
+ Fourteen annotators were randomly paired and differing annotations were discussed for reaching a consensus in two
44
+ annotation phases. In this setting, a high inter-annotator agreement was observed. Finally, all results were checked
45
+ against annotations of the rest of the corpus to assure corpus-wide consistency.
46
+
47
+ For more details, see: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3951655/
48
+
49
+ The original dataset can be downloaded from: https://www.ncbi.nlm.nih.gov/CBBresearch/Dogan/DISEASE/NCBI_corpus.zip
50
+ This dataset has been converted to CoNLL format for NER using the following tool: https://github.com/spyysalo/standoff2conll
51
+ Note: there is a duplicate document (PMID 8528200) in the original data, and the duplicate is recreated in the converted data.
52
+ """
53
+
54
+ _HOMEPAGE = "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3951655/"
55
+ _URL = "https://github.com/spyysalo/ncbi-disease/raw/master/conll/"
56
+ _TRAINING_FILE = "train.tsv"
57
+ _DEV_FILE = "devel.tsv"
58
+ _TEST_FILE = "test.tsv"
59
+
60
+
61
+ class NCBIDiseaseConfig(datasets.BuilderConfig):
62
+ """BuilderConfig for NCBIDisease"""
63
+
64
+ def __init__(self, **kwargs):
65
+ """BuilderConfig for NCBIDisease.
66
+ Args:
67
+ **kwargs: keyword arguments forwarded to super.
68
+ """
69
+ super(NCBIDiseaseConfig, self).__init__(**kwargs)
70
+
71
+
72
+ class NCBIDisease(datasets.GeneratorBasedBuilder):
73
+ """NCBIDisease dataset."""
74
+
75
+ BUILDER_CONFIGS = [
76
+ NCBIDiseaseConfig(name="ncbi_disease", version=datasets.Version("1.0.0"), description="NCBIDisease dataset"),
77
+ ]
78
+
79
+ def _info(self):
80
+ custom_names = ['O','B-GENE','I-GENE','B-CHEMICAL','I-CHEMICAL','B-DISEASE','I-DISEASE',
81
+ 'B-DNA', 'I-DNA', 'B-RNA', 'I-RNA', 'B-CELL_LINE', 'I-CELL_LINE', 'B-CELL_TYPE', 'I-CELL_TYPE',
82
+ 'B-PROTEIN', 'I-PROTEIN', 'B-SPECIES', 'I-SPECIES']
83
+ return datasets.DatasetInfo(
84
+ description=_DESCRIPTION,
85
+ features=datasets.Features(
86
+ {
87
+ "id": datasets.Value("string"),
88
+ "tokens": datasets.Sequence(datasets.Value("string")),
89
+ "ner_tags": datasets.Sequence(
90
+ datasets.features.ClassLabel(
91
+ names=custom_names
92
+ )
93
+ ),
94
+ }
95
+ ),
96
+ supervised_keys=None,
97
+ homepage=_HOMEPAGE,
98
+ citation=_CITATION,
99
+ )
100
+
101
+ def _split_generators(self, dl_manager):
102
+ """Returns SplitGenerators."""
103
+ urls_to_download = {
104
+ "train": f"{_URL}{_TRAINING_FILE}",
105
+ "dev": f"{_URL}{_DEV_FILE}",
106
+ "test": f"{_URL}{_TEST_FILE}",
107
+ }
108
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
109
+
110
+ return [
111
+ datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
112
+ datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
113
+ datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
114
+ ]
115
+
116
+ def _generate_examples(self, filepath):
117
+ logger.info("⏳ Generating examples from = %s", filepath)
118
+ with open(filepath, encoding="utf-8") as f:
119
+ guid = 0
120
+ tokens = []
121
+ ner_tags = []
122
+ for line in f:
123
+ if line == "" or line == "\n":
124
+ if tokens:
125
+ yield guid, {
126
+ "id": str(guid),
127
+ "tokens": tokens,
128
+ "ner_tags": ner_tags,
129
+ }
130
+ guid += 1
131
+ tokens = []
132
+ ner_tags = []
133
+ else:
134
+ # tokens are tab separated
135
+ splits = line.split("\t")
136
+ tokens.append(splits[0])
137
+ if(splits[1].rstrip()=="B-Disease"):
138
+ ner_tags.append("B-DISEASE")
139
+ elif(splits[1].rstrip()=="I-Disease"):
140
+ ner_tags.append("I-DISEASE")
141
+ else:
142
+ ner_tags.append(splits[1].rstrip())
143
+ # last example
144
+ yield guid, {
145
+ "id": str(guid),
146
+ "tokens": tokens,
147
+ "ner_tags": ner_tags,
148
+ }