hakunanatasha commited on
Commit
df1f0cd
1 Parent(s): 76a875c

adds modified blurb files

Browse files
Files changed (4) hide show
  1. LICENSE +26 -0
  2. README.md +52 -0
  3. bigbiohub.py +153 -0
  4. blurb.py +354 -0
LICENSE ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: National Library of Medicine Terms and Conditions
2
+ short_name: NLM_LICENSE
3
+
4
+
5
+ National Library of Medicine Terms and Conditions
6
+
7
+ INTRODUCTION
8
+
9
+ Downloading data from the National Library of Medicine FTP servers indicates your acceptance of the following Terms and Conditions: No charges, usage fees or royalties are paid to NLM for this data.
10
+
11
+ GENERAL TERMS AND CONDITIONS
12
+
13
+ Users of the data agree to:
14
+ acknowledge NLM as the source of the data by including the phrase "Courtesy of the U.S. National Library of Medicine" in a clear and conspicuous manner,
15
+ properly use registration and/or trademark symbols when referring to NLM products, and
16
+ not indicate or imply that NLM has endorsed its products/services/applications.
17
+
18
+ Users who republish or redistribute the data (services, products or raw data) agree to:
19
+ maintain the most current version of all distributed data, or
20
+ make known in a clear and conspicuous manner that the products/services/applications do not reflect the most current/accurate data available from NLM.
21
+
22
+ These data are produced with a reasonable standard of care, but NLM makes no warranties express or implied, including no warranty of merchantability or fitness for particular purpose, regarding the accuracy or completeness of the data. Users agree to hold NLM and the U.S. Government harmless from any liability resulting from errors in the data. NLM disclaims any liability for any consequences due to use, misuse, or interpretation of information contained or not contained in the data.
23
+
24
+ NLM does not provide legal advice regarding copyright, fair use, or other aspects of intellectual property rights. See the NLM Copyright page.
25
+
26
+ NLM reserves the right to change the type and format of its machine-readable data. NLM will take reasonable steps to inform users of any changes to the format of the data before the data are distributed via the announcement section or subscription to email and RSS updates.
README.md ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: other
4
+ multilinguality: monolingual
5
+ pretty_name: BioASQ Task B
6
+ ---
7
+
8
+
9
+ # Dataset Card for BioASQ Task B
10
+
11
+ ## Dataset Description
12
+
13
+ - **Homepage:** http://participants-area.bioasq.org/datasets/
14
+ - **Pubmed:** True
15
+ - **Public:** False
16
+ - **Tasks:** Question Answering
17
+
18
+
19
+ The BioASQ corpus contains multiple question
20
+ answering tasks annotated by biomedical experts, including yes/no, factoid, list,
21
+ and summary questions. Pertaining to our objective of comparing neural language
22
+ models, we focus on the the yes/no questions (Task 7b), and leave the inclusion
23
+ of other tasks to future work. Each question is paired with a reference text
24
+ containing multiple sentences from a PubMed abstract and a yes/no answer. We use
25
+ the official train/dev/test split of 670/75/140 questions.
26
+
27
+ See 'Domain-Specific Language Model Pretraining for Biomedical
28
+ Natural Language Processing'
29
+
30
+
31
+ ## Citation Information
32
+
33
+ ```
34
+ @article{tsatsaronis2015overview,
35
+ title = {
36
+ An overview of the BIOASQ large-scale biomedical semantic indexing and
37
+ question answering competition
38
+ },
39
+ author = {
40
+ Tsatsaronis, George and Balikas, Georgios and Malakasiotis, Prodromos
41
+ and Partalas, Ioannis and Zschunke, Matthias and Alvers, Michael R and
42
+ Weissenborn, Dirk and Krithara, Anastasia and Petridis, Sergios and
43
+ Polychronopoulos, Dimitris and others
44
+ },
45
+ year = 2015,
46
+ journal = {BMC bioinformatics},
47
+ publisher = {BioMed Central Ltd},
48
+ volume = 16,
49
+ number = 1,
50
+ pages = 138
51
+ }
52
+ ```
bigbiohub.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from enum import Enum
3
+ import datasets
4
+ from types import SimpleNamespace
5
+
6
+
7
+ BigBioValues = SimpleNamespace(NULL="<BB_NULL_STR>")
8
+
9
+
10
+ @dataclass
11
+ class BigBioConfig(datasets.BuilderConfig):
12
+ """BuilderConfig for BigBio."""
13
+
14
+ name: str = None
15
+ version: datasets.Version = None
16
+ description: str = None
17
+ schema: str = None
18
+ subset_id: str = None
19
+
20
+
21
+ class Tasks(Enum):
22
+ NAMED_ENTITY_RECOGNITION = "NER"
23
+ NAMED_ENTITY_DISAMBIGUATION = "NED"
24
+ EVENT_EXTRACTION = "EE"
25
+ RELATION_EXTRACTION = "RE"
26
+ COREFERENCE_RESOLUTION = "COREF"
27
+ QUESTION_ANSWERING = "QA"
28
+ TEXTUAL_ENTAILMENT = "TE"
29
+ SEMANTIC_SIMILARITY = "STS"
30
+ TEXT_PAIRS_CLASSIFICATION = "TXT2CLASS"
31
+ PARAPHRASING = "PARA"
32
+ TRANSLATION = "TRANSL"
33
+ SUMMARIZATION = "SUM"
34
+ TEXT_CLASSIFICATION = "TXTCLASS"
35
+
36
+
37
+ entailment_features = datasets.Features(
38
+ {
39
+ "id": datasets.Value("string"),
40
+ "premise": datasets.Value("string"),
41
+ "hypothesis": datasets.Value("string"),
42
+ "label": datasets.Value("string"),
43
+ }
44
+ )
45
+
46
+ pairs_features = datasets.Features(
47
+ {
48
+ "id": datasets.Value("string"),
49
+ "document_id": datasets.Value("string"),
50
+ "text_1": datasets.Value("string"),
51
+ "text_2": datasets.Value("string"),
52
+ "label": datasets.Value("string"),
53
+ }
54
+ )
55
+
56
+ qa_features = datasets.Features(
57
+ {
58
+ "id": datasets.Value("string"),
59
+ "question_id": datasets.Value("string"),
60
+ "document_id": datasets.Value("string"),
61
+ "question": datasets.Value("string"),
62
+ "type": datasets.Value("string"),
63
+ "choices": [datasets.Value("string")],
64
+ "context": datasets.Value("string"),
65
+ "answer": datasets.Sequence(datasets.Value("string")),
66
+ }
67
+ )
68
+
69
+ text_features = datasets.Features(
70
+ {
71
+ "id": datasets.Value("string"),
72
+ "document_id": datasets.Value("string"),
73
+ "text": datasets.Value("string"),
74
+ "labels": [datasets.Value("string")],
75
+ }
76
+ )
77
+
78
+ text2text_features = datasets.Features(
79
+ {
80
+ "id": datasets.Value("string"),
81
+ "document_id": datasets.Value("string"),
82
+ "text_1": datasets.Value("string"),
83
+ "text_2": datasets.Value("string"),
84
+ "text_1_name": datasets.Value("string"),
85
+ "text_2_name": datasets.Value("string"),
86
+ }
87
+ )
88
+
89
+ kb_features = datasets.Features(
90
+ {
91
+ "id": datasets.Value("string"),
92
+ "document_id": datasets.Value("string"),
93
+ "passages": [
94
+ {
95
+ "id": datasets.Value("string"),
96
+ "type": datasets.Value("string"),
97
+ "text": datasets.Sequence(datasets.Value("string")),
98
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
99
+ }
100
+ ],
101
+ "entities": [
102
+ {
103
+ "id": datasets.Value("string"),
104
+ "type": datasets.Value("string"),
105
+ "text": datasets.Sequence(datasets.Value("string")),
106
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
107
+ "normalized": [
108
+ {
109
+ "db_name": datasets.Value("string"),
110
+ "db_id": datasets.Value("string"),
111
+ }
112
+ ],
113
+ }
114
+ ],
115
+ "events": [
116
+ {
117
+ "id": datasets.Value("string"),
118
+ "type": datasets.Value("string"),
119
+ # refers to the text_bound_annotation of the trigger
120
+ "trigger": {
121
+ "text": datasets.Sequence(datasets.Value("string")),
122
+ "offsets": datasets.Sequence([datasets.Value("int32")]),
123
+ },
124
+ "arguments": [
125
+ {
126
+ "role": datasets.Value("string"),
127
+ "ref_id": datasets.Value("string"),
128
+ }
129
+ ],
130
+ }
131
+ ],
132
+ "coreferences": [
133
+ {
134
+ "id": datasets.Value("string"),
135
+ "entity_ids": datasets.Sequence(datasets.Value("string")),
136
+ }
137
+ ],
138
+ "relations": [
139
+ {
140
+ "id": datasets.Value("string"),
141
+ "type": datasets.Value("string"),
142
+ "arg1_id": datasets.Value("string"),
143
+ "arg2_id": datasets.Value("string"),
144
+ "normalized": [
145
+ {
146
+ "db_name": datasets.Value("string"),
147
+ "db_id": datasets.Value("string"),
148
+ }
149
+ ],
150
+ }
151
+ ],
152
+ }
153
+ )
blurb.py ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ BLURB is a collection of resources for biomedical natural language processing.
17
+ In general domains, such as newswire and the Web, comprehensive benchmarks and
18
+ leaderboards such as GLUE have greatly accelerated progress in open-domain NLP.
19
+ In biomedicine, however, such resources are ostensibly scarce. In the past,
20
+ there have been a plethora of shared tasks in biomedical NLP, such as
21
+ BioCreative, BioNLP Shared Tasks, SemEval, and BioASQ, to name just a few. These
22
+ efforts have played a significant role in fueling interest and progress by the
23
+ research community, but they typically focus on individual tasks. The advent of
24
+ neural language models, such as BERT provides a unifying foundation to leverage
25
+ transfer learning from unlabeled text to support a wide range of NLP
26
+ applications. To accelerate progress in biomedical pretraining strategies and
27
+ task-specific methods, it is thus imperative to create a broad-coverage
28
+ benchmark encompassing diverse biomedical tasks.
29
+
30
+ Inspired by prior efforts toward this direction (e.g., BLUE), we have created
31
+ BLURB (short for Biomedical Language Understanding and Reasoning Benchmark).
32
+ BLURB comprises of a comprehensive benchmark for PubMed-based biomedical NLP
33
+ applications, as well as a leaderboard for tracking progress by the community.
34
+ BLURB includes thirteen publicly available datasets in six diverse tasks. To
35
+ avoid placing undue emphasis on tasks with many available datasets, such as
36
+ named entity recognition (NER), BLURB reports the macro average across all tasks
37
+ as the main score. The BLURB leaderboard is model-agnostic. Any system capable
38
+ of producing the test predictions using the same training and development data
39
+ can participate. The main goal of BLURB is to lower the entry barrier in
40
+ biomedical NLP and help accelerate progress in this vitally important field for
41
+ positive societal and human impact."""
42
+
43
+ import re
44
+ import pandas
45
+
46
+ #from .bigbiohub import kb_features
47
+ from .bigbiohub import BigBioConfig
48
+ from .bigbiohub import Tasks
49
+
50
+ _DATASETNAME = "blurb"
51
+ _DISPLAYNAME = "BLURB"
52
+
53
+ _LANGUAGES = [Lang.EN]
54
+ _PUBMED = True
55
+ _LOCAL = False
56
+ _CITATION = """\
57
+ @article{gu2021domain,
58
+ title = {
59
+ Domain-specific language model pretraining for biomedical natural
60
+ language processing
61
+ },
62
+ author = {
63
+ Gu, Yu and Tinn, Robert and Cheng, Hao and Lucas, Michael and
64
+ Usuyama, Naoto and Liu, Xiaodong and Naumann, Tristan and Gao,
65
+ Jianfeng and Poon, Hoifung
66
+ },
67
+ year = 2021,
68
+ journal = {ACM Transactions on Computing for Healthcare (HEALTH)},
69
+ publisher = {ACM New York, NY},
70
+ volume = 3,
71
+ number = 1,
72
+ pages = {1--23}
73
+ }
74
+ """
75
+
76
+
77
+ _BC2GM_DESCRIPTION = """\
78
+ The BioCreative II Gene Mention task. The training corpus for the current task \
79
+ consists mainly of the training and testing corpora (text collections) from the \
80
+ BCI task, and the testing corpus for the current task consists of an additional \
81
+ 5,000 sentences that were held 'in reserve' from the previous task. In the \
82
+ current corpus, tokenization is not provided; instead participants are asked to \
83
+ identify a gene mention in a sentence by giving its start and end characters. As \
84
+ before, the training set consists of a set of sentences, and for each sentence a \
85
+ set of gene mentions (GENE annotations).
86
+
87
+ - Homepage: https://biocreative.bioinformatics.udel.edu/tasks/biocreative-ii/task-1a-gene-mention-tagging/
88
+ - Repository: https://github.com/cambridgeltl/MTL-Bioinformatics-2016/raw/master/data/
89
+ - Paper: Overview of BioCreative II gene mention recognition
90
+ https://link.springer.com/article/10.1186/gb-2008-9-s2-s2
91
+ """
92
+
93
+ _BC5_CHEM_DESCRIPTION = """\
94
+ The corpus consists of three separate sets of articles with diseases, chemicals \
95
+ and their relations annotated. The training (500 articles) and development (500 \
96
+ articles) sets were released to task participants in advance to support \
97
+ text-mining method development. The test set (500 articles) was used for final \
98
+ system performance evaluation.
99
+
100
+ - Homepage: https://biocreative.bioinformatics.udel.edu/resources/corpora/biocreative-v-cdr-corpus
101
+ - Repository: https://github.com/cambridgeltl/MTL-Bioinformatics-2016/raw/master/data/
102
+ - Paper: BioCreative V CDR task corpus: a resource for chemical disease relation extraction
103
+ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4860626/
104
+ """
105
+
106
+ _BC5_DISEASE_DESCRIPTION = """\
107
+ The corpus consists of three separate sets of articles with diseases, chemicals \
108
+ and their relations annotated. The training (500 articles) and development (500 \
109
+ articles) sets were released to task participants in advance to support \
110
+ text-mining method development. The test set (500 articles) was used for final \
111
+ system performance evaluation.
112
+
113
+ - Homepage: https://biocreative.bioinformatics.udel.edu/resources/corpora/biocreative-v-cdr-corpus
114
+ - Repository: https://github.com/cambridgeltl/MTL-Bioinformatics-2016/raw/master/data/
115
+ - Paper: BioCreative V CDR task corpus: a resource for chemical disease relation extraction
116
+ https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4860626/
117
+ """
118
+
119
+ _JNLPBA_DESCRIPTION = """\
120
+ The BioNLP / JNLPBA Shared Task 2004 involves the identification and classification \
121
+ of technical terms referring to concepts of interest to biologists in the domain of \
122
+ molecular biology. The task was organized by GENIA Project based on the annotations \
123
+ of the GENIA Term corpus (version 3.02).
124
+
125
+ - Homepage: http://www.geniaproject.org/shared-tasks/bionlp-jnlpba-shared-task-2004
126
+ - Repository: https://github.com/cambridgeltl/MTL-Bioinformatics-2016/raw/master/data/
127
+ - Paper: Introduction to the Bio-entity Recognition Task at JNLPBA
128
+ https://aclanthology.org/W04-1213
129
+ """
130
+
131
+ _NCBI_DISEASE_DESCRIPTION = """\
132
+ [T]he NCBI disease corpus contains 6,892 disease mentions, which are mapped to \
133
+ 790 unique disease concepts. Of these, 88% link to a MeSH identifier, while the \
134
+ rest contain an OMIM identifier. We were able to link 91% of the mentions to a \
135
+ single disease concept, while the rest are described as a combination of \
136
+ concepts.
137
+
138
+ - Homepage: https://www.ncbi.nlm.nih.gov/CBBresearch/Dogan/DISEASE/
139
+ - Repository: https://github.com/cambridgeltl/MTL-Bioinformatics-2016/raw/master/data/
140
+ - Paper: NCBI disease corpus: a resource for disease name recognition and concept normalization
141
+ https://pubmed.ncbi.nlm.nih.gov/24393765/
142
+ """
143
+
144
+ _EBM_PICO_DESCRIPTION = """"""
145
+
146
+ _CHEMPROT_DESCRIPTION = """"""
147
+ _DDI_DESCRIPTION = """"""
148
+ _GAD_DESCRIPTION = """"""
149
+
150
+ _BIOSSES_DESCRIPTION = """"""
151
+
152
+ _HOC_DESCRIPTION = """"""
153
+
154
+ _PUBMEDQA_DESCRIPTION = """"""
155
+ _BIOASQ_DESCRIPTION = """"""
156
+
157
+ _DESCRIPTION = {
158
+ "bc2gm": _BC2GM_DESCRIPTION,
159
+ "bc5disease": _BC5_DISEASE_DESCRIPTION,
160
+ "bc5chem": _BC5_CHEM_DESCRIPTION,
161
+ "jnlpba": _JNLPBA_DESCRIPTION,
162
+ "ncbi_disease": _NCBI_DISEASE_DESCRIPTION,
163
+ }
164
+
165
+ _HOMEPAGE = "https://microsoft.github.io/BLURB/tasks.html"
166
+
167
+ _LICENSE = "MIXED" # Licenses.GPL_3p0
168
+
169
+
170
+ _URLs = {
171
+ "bc2gm": [
172
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC2GM-IOB/train.tsv",
173
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC2GM-IOB/devel.tsv",
174
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC2GM-IOB/test.tsv",
175
+ ],
176
+ "bc5disease": [
177
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-disease-IOB/train.tsv",
178
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-disease-IOB/devel.tsv",
179
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-disease-IOB/test.tsv",
180
+ ],
181
+ "bc5chem": [
182
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-chem-IOB/train.tsv",
183
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-chem-IOB/devel.tsv",
184
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/BC5CDR-chem-IOB/test.tsv",
185
+ ],
186
+ "jnlpba": [
187
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/JNLPBA/train.tsv",
188
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/JNLPBA/devel.tsv",
189
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/JNLPBA/test.tsv",
190
+ ],
191
+ "ncbi_disease": [
192
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/NCBI-disease-IOB/train.tsv",
193
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/NCBI-disease-IOB/devel.tsv",
194
+ "https://raw.githubusercontent.com/cambridgeltl/MTL-Bioinformatics-2016/master/data/NCBI-disease-IOB/test.tsv",
195
+ ],
196
+ }
197
+
198
+ _SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION]
199
+ _SOURCE_VERSION = "1.0.0"
200
+ _BIGBIO_VERSION = "1.0.0"
201
+
202
+
203
+ class BlurbDataset(datasets.GeneratorBasedBuilder):
204
+ """BIOSSES : Biomedical Semantic Similarity Estimation System"""
205
+
206
+ DEFAULT_CONFIG_NAME = "biosses_source"
207
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
208
+ BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
209
+
210
+ BUILDER_CONFIGS = [
211
+ BigBioConfig(
212
+ name="bc5chem",
213
+ version=SOURCE_VERSION,
214
+ description="BC5CDR Chemical IO Tagging",
215
+ schema="ner",
216
+ subset_id="bc5chem",
217
+ ),
218
+ BigBioConfig(
219
+ name="bc5disease",
220
+ version=SOURCE_VERSION,
221
+ description="BC5CDR Chemical IO Tagging",
222
+ schema="ner",
223
+ subset_id="bc5disease",
224
+ ),
225
+ BigBioConfig(
226
+ name="bc2gm",
227
+ version=SOURCE_VERSION,
228
+ description="BC2 Gene IO Tagging",
229
+ schema="ner",
230
+ subset_id="bc2gm",
231
+ ),
232
+ BigBioConfig(
233
+ name="jnlpba",
234
+ version=SOURCE_VERSION,
235
+ description="JNLPBA Protein, DNA, RNA, Cell Type, Cell Line IO Tagging",
236
+ schema="ner",
237
+ subset_id="jnlpba",
238
+ ),
239
+ BigBioConfig(
240
+ name="ncbi_disease",
241
+ version=SOURCE_VERSION,
242
+ description="NCBI Disease IO Tagging",
243
+ schema="ner",
244
+ subset_id="ncbi_disease",
245
+ ),
246
+ ]
247
+
248
+ def _info(self):
249
+
250
+ ner_features = datasets.Features(
251
+ {
252
+ "id": datasets.Value("string"),
253
+ "tokens": datasets.Sequence(datasets.Value("string")),
254
+ "word_idx": datasets.Value("int32"),
255
+ "type": datasets.Value("string"),
256
+ "tags": datasets.Sequence(
257
+ datasets.features.ClassLabel(
258
+ names=[
259
+ "O",
260
+ "I",
261
+ ]
262
+ )
263
+ ),
264
+ }
265
+ )
266
+ if self.config.schema == "ner":
267
+ return datasets.DatasetInfo(
268
+ description=_DESCRIPTION[self.config.name],
269
+ features=ner_features,
270
+ supervised_keys=None,
271
+ homepage=_HOMEPAGE,
272
+ license=str(_LICENSE),
273
+ citation=_CITATION,
274
+ )
275
+
276
+ def _split_generators(self, dl_manager):
277
+
278
+ my_urls = _URLs[self.config.name]
279
+ dl_dir = dl_manager.download_and_extract(my_urls)
280
+
281
+ return [
282
+ datasets.SplitGenerator(
283
+ name=datasets.Split.TRAIN,
284
+ gen_kwargs={
285
+ "filepath": dl_dir[0],
286
+ "split": "train",
287
+ },
288
+ ),
289
+ datasets.SplitGenerator(
290
+ name=datasets.Split.VALIDATION,
291
+ gen_kwargs={
292
+ "filepath": dl_dir[1],
293
+ "split": "validation",
294
+ },
295
+ ),
296
+ datasets.SplitGenerator(
297
+ name=datasets.Split.TEST,
298
+ gen_kwargs={
299
+ "filepath": dl_dir[2],
300
+ "split": "test",
301
+ },
302
+ ),
303
+ ]
304
+
305
+ def _load_iob(self, fpath):
306
+ """
307
+ Assumes input CoNLL file is a single entity type.
308
+ """
309
+ with open(fpath, "r") as file:
310
+ tagged = []
311
+ for line in file:
312
+ if line.strip() == "":
313
+ toks, tags = zip(*tagged)
314
+ # transform tags
315
+ tags = [t[0] if t[0] in ["I", "O"] else "I" for t in tags]
316
+ yield (toks, tags)
317
+ tagged = []
318
+ continue
319
+ tagged.append(re.split("\s", line.strip()))
320
+
321
+ if tagged:
322
+ toks, tags = zip(*tagged)
323
+ tags = [t[0] for t in tags]
324
+ yield (toks, tags)
325
+
326
+ def _generate_examples(self, filepath, split):
327
+
328
+ if self.config.schema == "ner":
329
+
330
+ # Types for each NER dataset. Note BLURB's JNLPBA collapses all mentions into a
331
+ # single entity type, which creates some ambiguity for prompting based on type
332
+ ner_types = {
333
+ "bc2gm": "gene",
334
+ "bc5chem": "chemical",
335
+ "bc5disease": "disease",
336
+ "jnlpba": "protein, DNA, RNA, cell line, or cell type",
337
+ "ncbi_disease": "disease",
338
+ }
339
+
340
+ uid = 0
341
+ for item in self._load_iob(filepath):
342
+ if len(item) != 2:
343
+ print("ERROR", len(item), item, split)
344
+ continue
345
+ toks, tags = item
346
+ for word_idx in range(len(toks)):
347
+ yield uid, {
348
+ "id": uid,
349
+ "tokens": toks,
350
+ "type": ner_types[self.config.name],
351
+ "tags": tags,
352
+ "word_idx": word_idx,
353
+ }
354
+ uid += 1