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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2022 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 |
+
The main aim of MESINESP2 is to promote the development of practically relevant
|
17 |
+
semantic indexing tools for biomedical content in non-English language. We have
|
18 |
+
generated a manually annotated corpus, where domain experts have labeled a set
|
19 |
+
of scientific literature, clinical trials, and patent abstracts. All the
|
20 |
+
documents were labeled with DeCS descriptors, which is a structured controlled
|
21 |
+
vocabulary created by BIREME to index scientific publications on BvSalud, the
|
22 |
+
largest database of scientific documents in Spanish, which hosts records from
|
23 |
+
the databases LILACS, MEDLINE, IBECS, among others.
|
24 |
+
|
25 |
+
MESINESP track at BioASQ9 explores the efficiency of systems for assigning DeCS
|
26 |
+
to different types of biomedical documents. To that purpose, we have divided the
|
27 |
+
task into three subtracks depending on the document type. Then, for each one we
|
28 |
+
generated an annotated corpus which was provided to participating teams:
|
29 |
+
|
30 |
+
- [Subtrack 1 corpus] MESINESP-L – Scientific Literature: It contains all
|
31 |
+
Spanish records from LILACS and IBECS databases at the Virtual Health Library
|
32 |
+
(VHL) with non-empty abstract written in Spanish.
|
33 |
+
- [Subtrack 2 corpus] MESINESP-T- Clinical Trials contains records from Registro
|
34 |
+
Español de Estudios Clínicos (REEC). REEC doesn't provide documents with the
|
35 |
+
structure title/abstract needed in BioASQ, for that reason we have built
|
36 |
+
artificial abstracts based on the content available in the data crawled using
|
37 |
+
the REEC API.
|
38 |
+
- [Subtrack 3 corpus] MESINESP-P – Patents: This corpus includes patents in
|
39 |
+
Spanish extracted from Google Patents which have the IPC code “A61P” and
|
40 |
+
“A61K31”. In addition, we also provide a set of complementary data such as:
|
41 |
+
the DeCS terminology file, a silver standard with the participants' predictions
|
42 |
+
to the task background set and the entities of medications, diseases, symptoms
|
43 |
+
and medical procedures extracted from the BSC NERs documents.
|
44 |
+
"""
|
45 |
+
|
46 |
+
import json
|
47 |
+
import os
|
48 |
+
from typing import Dict, List, Tuple
|
49 |
+
|
50 |
+
import datasets
|
51 |
+
|
52 |
+
from .bigbiohub import text.features
|
53 |
+
from .bigbiohub import BigBioConfig
|
54 |
+
from .bigbiohub import Tasks
|
55 |
+
|
56 |
+
_LANGUAGES = ['Spanish']
|
57 |
+
_PUBMED = False
|
58 |
+
_LOCAL = False
|
59 |
+
_CITATION = """\
|
60 |
+
@conference {396,
|
61 |
+
title = {Overview of BioASQ 2021-MESINESP track. Evaluation of
|
62 |
+
advance hierarchical classification techniques for scientific
|
63 |
+
literature, patents and clinical trials.},
|
64 |
+
booktitle = {Proceedings of the 9th BioASQ Workshop
|
65 |
+
A challenge on large-scale biomedical semantic indexing
|
66 |
+
and question answering},
|
67 |
+
year = {2021},
|
68 |
+
url = {http://ceur-ws.org/Vol-2936/paper-11.pdf},
|
69 |
+
author = {Gasco, Luis and Nentidis, Anastasios and Krithara, Anastasia
|
70 |
+
and Estrada-Zavala, Darryl and Toshiyuki Murasaki, Renato and Primo-Pe{\~n}a,
|
71 |
+
Elena and Bojo-Canales, Cristina and Paliouras, Georgios and Krallinger, Martin}
|
72 |
+
}
|
73 |
+
|
74 |
+
"""
|
75 |
+
|
76 |
+
_DATASETNAME = "bioasq_2021_mesinesp"
|
77 |
+
_DISPLAYNAME = "MESINESP 2021"
|
78 |
+
|
79 |
+
_DESCRIPTION = """\
|
80 |
+
The main aim of MESINESP2 is to promote the development of practically relevant \
|
81 |
+
semantic indexing tools for biomedical content in non-English language. We have \
|
82 |
+
generated a manually annotated corpus, where domain experts have labeled a set \
|
83 |
+
of scientific literature, clinical trials, and patent abstracts. All the \
|
84 |
+
documents were labeled with DeCS descriptors, which is a structured controlled \
|
85 |
+
vocabulary created by BIREME to index scientific publications on BvSalud, the \
|
86 |
+
largest database of scientific documents in Spanish, which hosts records from \
|
87 |
+
the databases LILACS, MEDLINE, IBECS, among others.
|
88 |
+
|
89 |
+
MESINESP track at BioASQ9 explores the efficiency of systems for assigning DeCS \
|
90 |
+
to different types of biomedical documents. To that purpose, we have divided the \
|
91 |
+
task into three subtracks depending on the document type. Then, for each one we \
|
92 |
+
generated an annotated corpus which was provided to participating teams:
|
93 |
+
|
94 |
+
- [Subtrack 1 corpus] MESINESP-L – Scientific Literature: It contains all \
|
95 |
+
Spanish records from LILACS and IBECS databases at the Virtual Health Library \
|
96 |
+
(VHL) with non-empty abstract written in Spanish.
|
97 |
+
- [Subtrack 2 corpus] MESINESP-T- Clinical Trials contains records from Registro \
|
98 |
+
Español de Estudios Clínicos (REEC). REEC doesn't provide documents with the \
|
99 |
+
structure title/abstract needed in BioASQ, for that reason we have built \
|
100 |
+
artificial abstracts based on the content available in the data crawled using \
|
101 |
+
the REEC API.
|
102 |
+
- [Subtrack 3 corpus] MESINESP-P – Patents: This corpus includes patents in \
|
103 |
+
Spanish extracted from Google Patents which have the IPC code “A61P” and \
|
104 |
+
“A61K31”. In addition, we also provide a set of complementary data such as: \
|
105 |
+
the DeCS terminology file, a silver standard with the participants' predictions \
|
106 |
+
to the task background set and the entities of medications, diseases, symptoms \
|
107 |
+
and medical procedures extracted from the BSC NERs documents.
|
108 |
+
"""
|
109 |
+
|
110 |
+
_HOMEPAGE = "https://zenodo.org/record/5602914#.YhSXJ5PMKWt"
|
111 |
+
|
112 |
+
_LICENSE = 'Creative Commons Attribution 4.0 International'
|
113 |
+
|
114 |
+
_URLS = {
|
115 |
+
_DATASETNAME: {
|
116 |
+
"subtrack1": "https://zenodo.org/record/5602914/files/Subtrack1-Scientific_Literature.zip?download=1",
|
117 |
+
"subtrack2": "https://zenodo.org/record/5602914/files/Subtrack2-Clinical_Trials.zip?download=1",
|
118 |
+
"subtrack3": "https://zenodo.org/record/5602914/files/Subtrack3-Patents.zip?download=1",
|
119 |
+
},
|
120 |
+
}
|
121 |
+
|
122 |
+
_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]
|
123 |
+
|
124 |
+
_SOURCE_VERSION = "1.0.6"
|
125 |
+
_BIGBIO_VERSION = "1.0.0"
|
126 |
+
|
127 |
+
|
128 |
+
class Bioasq2021MesinespDataset(datasets.GeneratorBasedBuilder):
|
129 |
+
"""\
|
130 |
+
A dataset to promote the development of practically relevant
|
131 |
+
semantic indexing tools for biomedical content in non-English language.
|
132 |
+
"""
|
133 |
+
|
134 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
135 |
+
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
136 |
+
|
137 |
+
BUILDER_CONFIGS = [
|
138 |
+
BigBioConfig(
|
139 |
+
name="bioasq_2021_mesinesp_subtrack1_all_source",
|
140 |
+
version=SOURCE_VERSION,
|
141 |
+
description="bioasq_2021_mesinesp source schema subtrack1",
|
142 |
+
schema="source",
|
143 |
+
subset_id="bioasq_2021_mesinesp_subtrack1_all",
|
144 |
+
),
|
145 |
+
BigBioConfig(
|
146 |
+
name="bioasq_2021_mesinesp_subtrack1_only_articles_source",
|
147 |
+
version=SOURCE_VERSION,
|
148 |
+
description="bioasq_2021_mesinesp source schema subtrack1",
|
149 |
+
schema="source",
|
150 |
+
subset_id="bioasq_2021_mesinesp_subtrack1_only_articles",
|
151 |
+
),
|
152 |
+
BigBioConfig(
|
153 |
+
name="bioasq_2021_mesinesp_subtrack2_source",
|
154 |
+
version=SOURCE_VERSION,
|
155 |
+
description="bioasq_2021_mesinesp source schema subtrack2",
|
156 |
+
schema="source",
|
157 |
+
subset_id="bioasq_2021_mesinesp_subtrack2",
|
158 |
+
),
|
159 |
+
BigBioConfig(
|
160 |
+
name="bioasq_2021_mesinesp_subtrack3_source",
|
161 |
+
version=SOURCE_VERSION,
|
162 |
+
description="bioasq_2021_mesinesp source schema subtrack3",
|
163 |
+
schema="source",
|
164 |
+
subset_id="bioasq_2021_mesinesp_subtrack3",
|
165 |
+
),
|
166 |
+
BigBioConfig(
|
167 |
+
name="bioasq_2021_mesinesp_subtrack1_all_bigbio_text",
|
168 |
+
version=BIGBIO_VERSION,
|
169 |
+
description="bioasq_2021_mesinesp BigBio schema subtrack1",
|
170 |
+
schema="bigbio_text",
|
171 |
+
subset_id="bioasq_2021_mesinesp_subtrack1_all",
|
172 |
+
),
|
173 |
+
BigBioConfig(
|
174 |
+
name="bioasq_2021_mesinesp_subtrack1_only_articles_bigbio_text",
|
175 |
+
version=BIGBIO_VERSION,
|
176 |
+
description="bioasq_2021_mesinesp BigBio schema subtrack1",
|
177 |
+
schema="bigbio_text",
|
178 |
+
subset_id="bioasq_2021_mesinesp_subtrack1_only_articles",
|
179 |
+
),
|
180 |
+
BigBioConfig(
|
181 |
+
name="bioasq_2021_mesinesp_subtrack2_bigbio_text",
|
182 |
+
version=BIGBIO_VERSION,
|
183 |
+
description="bioasq_2021_mesinesp BigBio schema subtrack2",
|
184 |
+
schema="bigbio_text",
|
185 |
+
subset_id="bioasq_2021_mesinesp_subtrack2",
|
186 |
+
),
|
187 |
+
BigBioConfig(
|
188 |
+
name="bioasq_2021_mesinesp_subtrack3_bigbio_text",
|
189 |
+
version=BIGBIO_VERSION,
|
190 |
+
description="bioasq_2021_mesinesp BigBio schema subtrack3",
|
191 |
+
schema="bigbio_text",
|
192 |
+
subset_id="bioasq_2021_mesinesp_subtrack3",
|
193 |
+
),
|
194 |
+
]
|
195 |
+
|
196 |
+
DEFAULT_CONFIG_NAME = "bioasq_2021_mesinesp_source"
|
197 |
+
|
198 |
+
def _info(self) -> datasets.DatasetInfo:
|
199 |
+
|
200 |
+
if self.config.schema == "source":
|
201 |
+
features = datasets.Features(
|
202 |
+
{
|
203 |
+
"abstractText": datasets.Value("string"),
|
204 |
+
"db": datasets.Value("string"),
|
205 |
+
"decsCodes": datasets.Sequence(datasets.Value("string")),
|
206 |
+
"id": datasets.Value("string"),
|
207 |
+
"journal": datasets.Value("string"),
|
208 |
+
"title": datasets.Value("string"),
|
209 |
+
"year": datasets.Value("string"),
|
210 |
+
}
|
211 |
+
)
|
212 |
+
elif self.config.schema == "bigbio_text":
|
213 |
+
features = text.features
|
214 |
+
|
215 |
+
return datasets.DatasetInfo(
|
216 |
+
description=_DESCRIPTION,
|
217 |
+
features=features,
|
218 |
+
homepage=_HOMEPAGE,
|
219 |
+
license=str(_LICENSE),
|
220 |
+
citation=_CITATION,
|
221 |
+
)
|
222 |
+
|
223 |
+
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
224 |
+
"""Returns SplitGenerators."""
|
225 |
+
|
226 |
+
if "subtrack1" in self.config.name:
|
227 |
+
track = "1"
|
228 |
+
elif "subtrack2" in self.config.name:
|
229 |
+
track = "2"
|
230 |
+
else:
|
231 |
+
track = "3"
|
232 |
+
|
233 |
+
urls = _URLS[_DATASETNAME][f"subtrack{track}"]
|
234 |
+
if self.config.data_dir is None:
|
235 |
+
try:
|
236 |
+
data_dir = dl_manager.download_and_extract(urls)
|
237 |
+
except ConnectionError:
|
238 |
+
raise ConnectionError(
|
239 |
+
"Could not download. Save locally and use `data_dir` kwarg"
|
240 |
+
)
|
241 |
+
else:
|
242 |
+
data_dir = self.config.data_dir
|
243 |
+
|
244 |
+
if track == "1":
|
245 |
+
top_folder = "Subtrack1-Scientific_Literature"
|
246 |
+
elif track == "2":
|
247 |
+
top_folder = "Subtrack2-Clinical_Trials"
|
248 |
+
else:
|
249 |
+
top_folder = "Subtrack3-Patents"
|
250 |
+
if track == "1":
|
251 |
+
if "all" in self.config.name:
|
252 |
+
train_filepath = "training_set_subtrack1_all.json"
|
253 |
+
else:
|
254 |
+
train_filepath = "training_set_subtrack1_only_articles.json"
|
255 |
+
else:
|
256 |
+
train_filepath = f"training_set_subtrack{track}.json"
|
257 |
+
|
258 |
+
dev_filepath = f"development_set_subtrack{track}.json"
|
259 |
+
test_filepath = f"test_set_subtrack{track}.json"
|
260 |
+
|
261 |
+
split_gens = [
|
262 |
+
datasets.SplitGenerator(
|
263 |
+
name=datasets.Split.TRAIN,
|
264 |
+
gen_kwargs={
|
265 |
+
"filepath": os.path.join(
|
266 |
+
data_dir, top_folder, "Train", train_filepath
|
267 |
+
),
|
268 |
+
},
|
269 |
+
),
|
270 |
+
datasets.SplitGenerator(
|
271 |
+
name=datasets.Split.VALIDATION,
|
272 |
+
gen_kwargs={
|
273 |
+
"filepath": os.path.join(
|
274 |
+
data_dir, top_folder, "Development", dev_filepath
|
275 |
+
),
|
276 |
+
},
|
277 |
+
),
|
278 |
+
datasets.SplitGenerator(
|
279 |
+
name=datasets.Split.TEST,
|
280 |
+
gen_kwargs={
|
281 |
+
"filepath": os.path.join(
|
282 |
+
data_dir, top_folder, "Test", test_filepath
|
283 |
+
),
|
284 |
+
},
|
285 |
+
),
|
286 |
+
]
|
287 |
+
|
288 |
+
# track 3 doesn't have Train data
|
289 |
+
if track == "3":
|
290 |
+
return split_gens[1:]
|
291 |
+
|
292 |
+
return split_gens
|
293 |
+
|
294 |
+
def _generate_examples(self, filepath) -> Tuple[int, Dict]:
|
295 |
+
"""Yields examples as (key, example) tuples."""
|
296 |
+
|
297 |
+
if self.config.schema == "source":
|
298 |
+
|
299 |
+
with open(filepath) as fp:
|
300 |
+
data = json.load(fp)
|
301 |
+
|
302 |
+
for key, example in enumerate(data["articles"]):
|
303 |
+
yield key, example
|
304 |
+
|
305 |
+
elif self.config.schema == "bigbio_text":
|
306 |
+
with open(filepath) as fp:
|
307 |
+
data = json.load(fp)
|
308 |
+
|
309 |
+
for key, example in enumerate(data["articles"]):
|
310 |
+
yield key, {
|
311 |
+
"id": example["id"],
|
312 |
+
"document_id": "NULL",
|
313 |
+
"text": example["abstractText"],
|
314 |
+
"labels": example["decsCodes"],
|
315 |
+
}
|