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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 |
+
BioASQ Task B On Biomedical Semantic QA (Involves IR, QA, Summarization qnd
|
17 |
+
More). This task uses benchmark datasets containing development and test
|
18 |
+
questions, in English, along with gold standard (reference) answers constructed
|
19 |
+
by a team of biomedical experts. The participants have to respond with relevant
|
20 |
+
concepts, articles, snippets and RDF triples, from designated resources, as well
|
21 |
+
as exact and 'ideal' answers.
|
22 |
+
|
23 |
+
Fore more information about the challenge, the organisers and the relevant
|
24 |
+
publications please visit: http://bioasq.org/
|
25 |
+
"""
|
26 |
+
import glob
|
27 |
+
import json
|
28 |
+
import os
|
29 |
+
import re
|
30 |
+
|
31 |
+
import datasets
|
32 |
+
from utils import schemas
|
33 |
+
from utils.configs import BigBioConfig
|
34 |
+
from utils.constants import Tasks
|
35 |
+
|
36 |
+
_CITATION = """\
|
37 |
+
@article{tsatsaronis2015overview,
|
38 |
+
title = {
|
39 |
+
An overview of the BIOASQ large-scale biomedical semantic indexing and
|
40 |
+
question answering competition
|
41 |
+
},
|
42 |
+
author = {
|
43 |
+
Tsatsaronis, George and Balikas, Georgios and Malakasiotis, Prodromos
|
44 |
+
and Partalas, Ioannis and Zschunke, Matthias and Alvers, Michael R and
|
45 |
+
Weissenborn, Dirk and Krithara, Anastasia and Petridis, Sergios and
|
46 |
+
Polychronopoulos, Dimitris and others
|
47 |
+
},
|
48 |
+
year = 2015,
|
49 |
+
journal = {BMC bioinformatics},
|
50 |
+
publisher = {BioMed Central Ltd},
|
51 |
+
volume = 16,
|
52 |
+
number = 1,
|
53 |
+
pages = 138
|
54 |
+
}
|
55 |
+
"""
|
56 |
+
|
57 |
+
_DATASETNAME = "bioasq"
|
58 |
+
|
59 |
+
_BIOASQ_10B_DESCRIPTION = """\
|
60 |
+
The data are intended to be used as training and development data for BioASQ
|
61 |
+
10, which will take place during 2022. There is one file containing the data:
|
62 |
+
- training10b.json
|
63 |
+
|
64 |
+
The file contains the data of the first nine editions of the challenge: 4234
|
65 |
+
questions [1] with their relevant documents, snippets, concepts and RDF
|
66 |
+
triples, exact and ideal answers.
|
67 |
+
|
68 |
+
Differences with BioASQ-training9b.json
|
69 |
+
- 492 new questions added from BioASQ9
|
70 |
+
- The question with id 56c1f01eef6e394741000046 had identical body with
|
71 |
+
602498cb1cb411341a00009e. All relevant elements from both questions
|
72 |
+
are available in the merged question with id 602498cb1cb411341a00009e.
|
73 |
+
- The question with id 5c7039207c78d69471000065 had identical body with
|
74 |
+
601c317a1cb411341a000014. All relevant elements from both questions
|
75 |
+
are available in the merged question with id 601c317a1cb411341a000014.
|
76 |
+
- The question with id 5e4b540b6d0a27794100001c had identical body with
|
77 |
+
602828b11cb411341a0000fc. All relevant elements from both questions
|
78 |
+
are available in the merged question with id 602828b11cb411341a0000fc.
|
79 |
+
- The question with id 5fdb42fba43ad31278000027 had identical body with
|
80 |
+
5d35eb01b3a638076300000f. All relevant elements from both questions
|
81 |
+
are available in the merged question with id 5d35eb01b3a638076300000f.
|
82 |
+
- The question with id 601d76311cb411341a000045 had identical body with
|
83 |
+
6060732b94d57fd87900003d. All relevant elements from both questions
|
84 |
+
are available in the merged question with id 6060732b94d57fd87900003d.
|
85 |
+
|
86 |
+
[1] 4234 questions : 1252 factoid, 1148 yesno, 1018 summary, 816 list
|
87 |
+
"""
|
88 |
+
|
89 |
+
_BIOASQ_9B_DESCRIPTION = """\
|
90 |
+
The data are intended to be used as training and development data for BioASQ 9,
|
91 |
+
which will take place during 2021. There is one file containing the data:
|
92 |
+
- training9b.json
|
93 |
+
|
94 |
+
The file contains the data of the first seven editions of the challenge: 3742
|
95 |
+
questions [1] with their relevant documents, snippets, concepts and RDF triples,
|
96 |
+
exact and ideal answers.
|
97 |
+
|
98 |
+
Differences with BioASQ-training8b.json
|
99 |
+
- 499 new questions added from BioASQ8
|
100 |
+
- The question with id 5e30e689fbd6abf43b00003a had identical body with
|
101 |
+
5880e417713cbdfd3d000001. All relevant elements from both questions
|
102 |
+
are available in the merged question with id 5880e417713cbdfd3d000001.
|
103 |
+
|
104 |
+
[1] 3742 questions : 1091 factoid, 1033 yesno, 899 summary, 719 list
|
105 |
+
"""
|
106 |
+
|
107 |
+
_BIOASQ_8B_DESCRIPTION = """\
|
108 |
+
The data are intended to be used as training and development data for BioASQ 8,
|
109 |
+
which will take place during 2020. There is one file containing the data:
|
110 |
+
- training8b.json
|
111 |
+
|
112 |
+
The file contains the data of the first seven editions of the challenge: 3243
|
113 |
+
questions [1] with their relevant documents, snippets, concepts and RDF triples,
|
114 |
+
exact and ideal answers.
|
115 |
+
|
116 |
+
Differences with BioASQ-training7b.json
|
117 |
+
- 500 new questions added from BioASQ7
|
118 |
+
- 4 questions were removed
|
119 |
+
- The question with id 5717fb557de986d80d000009 had identical body with
|
120 |
+
571e06447de986d80d000016. All relevant elements from both questions
|
121 |
+
are available in the merged question with id 571e06447de986d80d000016.
|
122 |
+
- The question with id 5c589ddb86df2b917400000b had identical body with
|
123 |
+
5c6b7a9e7c78d69471000029. All relevant elements from both questions
|
124 |
+
are available in the merged question with id 5c6b7a9e7c78d69471000029.
|
125 |
+
- The question with id 52ffb5d12059c6d71c00007c had identical body with
|
126 |
+
52e7870a98d023950500001a. All relevant elements from both questions
|
127 |
+
are available in the merged question with id 52e7870a98d023950500001a.
|
128 |
+
- The question with id 53359338d6d3ac6a3400004f had identical body with
|
129 |
+
589a246878275d0c4a000030. All relevant elements from both questions
|
130 |
+
are available in the merged question with id 589a246878275d0c4a000030.
|
131 |
+
|
132 |
+
**** UPDATE 25/02/2020 *****
|
133 |
+
The previous version of the dataset contained an inconsistency on question with
|
134 |
+
id "5c9904eaecadf2e73f00002e", where the "ideal_answer" field was missing.
|
135 |
+
This has been fixed.
|
136 |
+
"""
|
137 |
+
|
138 |
+
_BIOASQ_7B_DESCRIPTION = """\
|
139 |
+
The data are intended to be used as training and development data for BioASQ 7,
|
140 |
+
which will take place during 2019. There is one file containing the data:
|
141 |
+
- BioASQ-trainingDataset7b.json
|
142 |
+
|
143 |
+
The file contains the data of the first six editions of the challenge: 2747
|
144 |
+
questions [1] with their relevant documents, snippets, concepts and RDF triples,
|
145 |
+
exact and ideal answers.
|
146 |
+
|
147 |
+
Differences with BioASQ-trainingDataset6b.json
|
148 |
+
- 500 new questions added from BioASQ6
|
149 |
+
- 4 questions were removed
|
150 |
+
- The question with id 569ed752ceceede94d000004 had identical body with
|
151 |
+
a new question from BioASQ6. All relevant elements from both questions
|
152 |
+
are available in the merged question with id 5abd31e0fcf456587200002c
|
153 |
+
- 3 questions were removed as incomplete: 54d643023706e89528000007,
|
154 |
+
532819afd6d3ac6a3400000f, 517545168ed59a060a00002b
|
155 |
+
- 4 questions were revised for various confusions that have been identified
|
156 |
+
- In 2 questions the ideal answer has been revised :
|
157 |
+
51406e6223fec90375000009, 5172f8118ed59a060a000019
|
158 |
+
- In 4 questions the snippets and documents list has been revised :
|
159 |
+
51406e6223fec90375000009, 5172f8118ed59a060a000019,
|
160 |
+
51593dc8d24251bc05000099, 5158a5b8d24251bc05000097
|
161 |
+
- In 198 questions the documents list has updated with missing
|
162 |
+
documents from the relevant snippets list. [2]
|
163 |
+
|
164 |
+
[1] 2747 questions : 779 factoid, 745 yesno, 667 summary, 556 list
|
165 |
+
[2] 55031181e9bde69634000014, 51406e6223fec90375000009, 54d643023706e89528000007,
|
166 |
+
52bf1b0a03868f1b06000009, 52bf19c503868f1b06000001, 51593dc8d24251bc05000099,
|
167 |
+
530a5117970c65fa6b000007, 553a8d78f321868558000003, 531a3fe3b166e2b806000038,
|
168 |
+
532819afd6d3ac6a3400000f, 5158a5b8d24251bc05000097, 553653a5bc4f83e828000007,
|
169 |
+
535d2cf09a4572de6f000004, 53386282d6d3ac6a3400005a, 517a8ce98ed59a060a000045,
|
170 |
+
55391ce8bc4f83e828000018, 5547d700f35db75526000007, 5713bf261174fb1755000011,
|
171 |
+
6f15c5a2ac5ed1459000012, 52b2e498f828ad283c000010, 570a7594cf1c325851000026,
|
172 |
+
530cefaaad0bf1360c000012, 530f685c329f5fcf1e000002, 550c4011a103b78016000009,
|
173 |
+
552faababc4f83e828000005, 54cf48acf693c3b16b00000b, 550313aae9bde6963400001f,
|
174 |
+
551177626a8cde6b72000005, 54eded8c94afd6150400000c, 550c3754a103b78016000007,
|
175 |
+
56f555b609dd18d46b000007, 54c26e29f693c3b16b000003, 54da0c524b1fd0d33c00000b,
|
176 |
+
52bf1d3c03868f1b0600000d, 5343bdd6aeec6fbd07000001, 52cb9b9b03868f1b0600002d,
|
177 |
+
55423875ec76f5e50c000002, 571366ba1174fb1755000005, 56c4d14ab04e159d0e000003,
|
178 |
+
550c44d1a103b7801600000a, 5547a01cf35db75526000005, 55422640ccca0ce74b000004,
|
179 |
+
54ecb66d445c3b5a5f000002, 553656c4bc4f83e828000009, 5172f8118ed59a060a000019,
|
180 |
+
513711055274a5fb0700000e, 54d892ee014675820d000005, 52e6c92598d0239505000019,
|
181 |
+
5353aedb288f4dae47000006, 52bf1f1303868f1b06000014, 5519113b622b19434500000f,
|
182 |
+
52b2f1724003448f5500000b, 5525317687ecba3764000007, 554a0cadf35db7552600000f,
|
183 |
+
55152bd246478f2f2c000002, 516c3960298dcd4e51000073, 571e417bbb137a4b0c00000a,
|
184 |
+
551910d3622b194345000008, 54dc8ed6c0bb8dce23000002, 511a4ec01159fa8212000004,
|
185 |
+
54d8ea2c4b1fd0d33c000002, 5148e1d6d24251bc0500003a, 515dbb3b298dcd4e51000018,
|
186 |
+
56f7c15a09dd18d46b000012, 51475d5cd24251bc0500001b, 54db7c4ac0bb8dce23000001,
|
187 |
+
57152ebbcb4ef8864c000002, 57134d511174fb1755000002, 55149f156a8cde6b72000013,
|
188 |
+
56bcd422d36b5da378000005, 54ede5c394afd61504000006, 517545168ed59a060a00002b,
|
189 |
+
5710ed19a5ed216440000003, 53442472aeec6fbd07000008, 55088e412e93f0133a000001,
|
190 |
+
54d762653706e89528000014, 550aef0ec2af5d5b7000000a, 552435602c8b63434a000009,
|
191 |
+
552446612c8b63434a00000c, 54d901ec4b1fd0d33c000006, 54cf45e7f693c3b16b00000a,
|
192 |
+
52fc8b772059c6d71c00006e, 5314d05adae131f84700000d, 5512c91b6a8cde6b7200000b,
|
193 |
+
56c5a7605795f9a73e000002, 55030a6ce9bde6963400000f, 553fac39c6a5098552000001,
|
194 |
+
531a3a58b166e2b806000037, 5509bd6a1180f13250000002, 54f9c40ddd3fc62544000001,
|
195 |
+
553c8fd1f32186855800000a, 56bce51cd36b5da37800000a, 550316a6e9bde69634000029,
|
196 |
+
55031286e9bde6963400001b, 536e46f27d100faa09000012, 5502abd1e9bde69634000008,
|
197 |
+
551af9106b348bb82c000002, 54edeb4394afd6150400000b, 5717cdd2070aa3d072000001,
|
198 |
+
56c5ade15795f9a73e000003, 531464a6e3eabad021000014, 58a0d87a78275d0c4a000053,
|
199 |
+
58a3160d60087bc10a00000a, 58a5d54860087bc10a000025, 58a0da5278275d0c4a000054,
|
200 |
+
58a3264e60087bc10a00000d, 589c8ef878275d0c4a000042, 58a3428d60087bc10a00001b,
|
201 |
+
58a3196360087bc10a00000b, 58a341eb60087bc10a000018, 58a3275960087bc10a00000f,
|
202 |
+
58a342e760087bc10a00001c, 58bd645702b8c60953000010, 58bc8e5002b8c60953000006,
|
203 |
+
58bc8e7a02b8c60953000007, 58a1da4e78275d0c4a000059, 58bcb83d02b8c6095300000f,
|
204 |
+
58bc9a5002b8c60953000008, 589dee3778275d0c4a000050, 58a32efe60087bc10a000013,
|
205 |
+
58a327bf60087bc10a000011, 58bca08702b8c6095300000a, 58bc9dbb02b8c60953000009,
|
206 |
+
58c99fcc02b8c60953000029, 58bca2f302b8c6095300000c, 58cbf1f402b8c60953000036,
|
207 |
+
58cdb41302b8c60953000042, 58cdb80302b8c60953000043, 58cdbaf302b8c60953000044,
|
208 |
+
58cb305c02b8c60953000032, 58caf86f02b8c60953000030, 58c1b2f702b8c6095300001e,
|
209 |
+
58bde18b02b8c60953000014, 58eb7898eda5a57672000006, 58caf88c02b8c60953000031,
|
210 |
+
58e11bf76fddd3e83e00000c, 58cdbbd102b8c60953000045, 58df779d6fddd3e83e000001,
|
211 |
+
58dbb4f08acda3452900001a, 58dbb8968acda3452900001b, 58add7699ef3c34033000009,
|
212 |
+
58dbbbf08acda3452900001d, 58dbba438acda3452900001c, 58dd2cb08acda34529000029,
|
213 |
+
58eb9542eda5a57672000007, 58f3ca5c70f9fc6f0f00000d, 58e9e7aa3e8b6dc87c00000d,
|
214 |
+
58e3d9ab3e8b6dc87c000002, 58eb4ce7eda5a57672000004, 58f3c8f470f9fc6f0f00000c,
|
215 |
+
58f3c62970f9fc6f0f00000b, 58adca6d9ef3c34033000007, 58f4b3ee70f9fc6f0f000013,
|
216 |
+
593ff22b70f9fc6f0f000023, 5a679875b750ff4455000004, 5a774585faa1ab7d2e000005,
|
217 |
+
5a6f7245b750ff4455000050, 5a787544faa1ab7d2e00000b, 5a74d9980384be9551000008,
|
218 |
+
5a6a02a3b750ff4455000021, 5a6e47b1b750ff4455000049, 5a87124561bb38fb24000001,
|
219 |
+
5a6e42f1b750ff4455000046, 5a8b1264fcd1d6a10c00001d, 5a981e66fcd1d6a10c00002f,
|
220 |
+
5a8718c861bb38fb24000008, 5a7615af83b0d9ea6600001f, 5a87140a61bb38fb24000003,
|
221 |
+
5a77072c9e632bc06600000a, 5a897601fcd1d6a10c000008, 5a871a6861bb38fb24000009,
|
222 |
+
5a74e9ad0384be955100000a, 5a79d25dfaa1ab7d2e00000f, 5a6900ebb750ff445500001d,
|
223 |
+
5a87145861bb38fb24000004, 5a871b8d61bb38fb2400000a, 5a897a06fcd1d6a10c00000b,
|
224 |
+
5a8dc6b4fcd1d6a10c000026, 5a8712af61bb38fb24000002, 5a8714e261bb38fb24000005,
|
225 |
+
5aa304f1d6d6b54f79000004, 5a981bcffcd1d6a10c00002d, 5aa3fa73d6d6b54f79000008,
|
226 |
+
5aa55b45d6d6b54f7900000d, 5a981dd0fcd1d6a10c00002e, 5a9700adfcd1d6a10c00002c,
|
227 |
+
5a9d8ffe1d1251d03b000022, 5a96c74cfcd1d6a10c000029, 5aa50086d6d6b54f7900000c,
|
228 |
+
5a95765bfcd1d6a10c000028, 5a96f40cfcd1d6a10c00002b, 5ab144fefcf4565872000012,
|
229 |
+
5aa67b4fd6d6b54f7900000f, 5abd5a62fcf4565872000031, 5abbe429fcf456587200001c,
|
230 |
+
5aaef38dfcf456587200000f, 5abce6acfcf4565872000022, 5aae6499fcf456587200000c
|
231 |
+
"""
|
232 |
+
|
233 |
+
_BIOASQ_6B_DESCRIPTION = """\
|
234 |
+
The data are intended to be used as training and development data for BioASQ 6,
|
235 |
+
which will take place during 2018. There is one file containing the data:
|
236 |
+
- BioASQ-trainingDataset6b.json
|
237 |
+
|
238 |
+
Differences with BioASQ-trainingDataset5b.json
|
239 |
+
- 500 new questions added from BioASQ5
|
240 |
+
- 48 pairs of questions with identical bodies have been merged into one
|
241 |
+
question having only one question-id, but all the documents, snippets,
|
242 |
+
concepts, RDF triples and answers of both questions of the pair.
|
243 |
+
- This normalization lead to the removal of 48 deprecated question
|
244 |
+
ids [2] from the dataset and to the update of the 48 remaining
|
245 |
+
questions [3].
|
246 |
+
- In cases where a pair of questions with identical bodies had some
|
247 |
+
inconsistency (e.g. different question type), the inconsistency has
|
248 |
+
been solved merging the pair manually consulting the BioASQ expert team.
|
249 |
+
- 12 questions were revised for various confusions that have been
|
250 |
+
identified
|
251 |
+
- In 8 questions the question type has been changed to better suit to
|
252 |
+
the question body. The change of type lead to corresponding changes
|
253 |
+
in exact answers existence and format : 54fc4e2e6ea36a810c000003,
|
254 |
+
530b01a6970c65fa6b000008, 530cf54dab4de4de0c000009,
|
255 |
+
531b2fc3b166e2b80600003c, 532819afd6d3ac6a3400000f,
|
256 |
+
532aad53d6d3ac6a34000010, 5710ade4cf1c32585100002c,
|
257 |
+
52f65f372059c6d71c000027
|
258 |
+
- In 6 questions the ideal answer has been revised :
|
259 |
+
532aad53d6d3ac6a34000010, 5710ade4cf1c32585100002c,
|
260 |
+
53147b52e3eabad021000015, 5147c8a6d24251bc05000027,
|
261 |
+
5509bd6a1180f13250000002, 58bbb71f22d3005309000016
|
262 |
+
- In 5 questions the exact answer has been revised :
|
263 |
+
5314bd7ddae131f847000006, 53130a77e3eabad02100000f,
|
264 |
+
53148a07dae131f847000002, 53147b52e3eabad021000015,
|
265 |
+
5147c8a6d24251bc05000027
|
266 |
+
- In 2 questions the question body has been revised :
|
267 |
+
52f65f372059c6d71c000027, 5503145ee9bde69634000022
|
268 |
+
- In lists of ideal answers, documents, snippets, concepts and RDF triples
|
269 |
+
any duplicate identical elements have been removed.
|
270 |
+
- Ideal answers in format of one string have been converted to a list with
|
271 |
+
one element for consistency with cases where more than one golden ideal
|
272 |
+
answers are available. (i.e. "ideal_ans1" converted to ["ideal_ans1"])
|
273 |
+
- For yesno questions: All exact answers have been normalized to "yes" or
|
274 |
+
"no" (replacing "Yes", "YES" and "No")
|
275 |
+
- For factoid questions: The format of the exact answer was normalized to a
|
276 |
+
list of strings for each question, representing a set of synonyms
|
277 |
+
answering the question (i.e. [`ans1`, `syn11`, ... ]).
|
278 |
+
- For list questions: The format of the exact answer was normalized to a
|
279 |
+
list of lists. Each internal list represents one element of the answer
|
280 |
+
as a set of synonyms
|
281 |
+
(i.e. [[`ans1`, `syn11`, `syn12`], [`ans2`], [`ans3`, `syn31`] ...]).
|
282 |
+
- Empty elements, e.g. empty lists of documents have been removed.
|
283 |
+
|
284 |
+
[1] 2251 questions : 619 factoid, 616 yesno, 531 summary, 485 list
|
285 |
+
[2] The 48 deprecated question ids are : 52f8b2902059c6d71c000053,
|
286 |
+
52f11bf22059c6d71c000005, 52f77edb2059c6d71c000028, 52ed795098d0239505000032,
|
287 |
+
56d1a9baab2fed4a47000002, 52f7d3472059c6d71c00002f, 52fbe2bf2059c6d71c00006c,
|
288 |
+
52ec961098d023950500002a, 52e8e98298d0239505000020, 56cae5125795f9a73e000024,
|
289 |
+
530cefaaad0bf1360c000007, 530cefaaad0bf1360c000005, 52d63b2803868f1b0600003a,
|
290 |
+
530cefaaad0bf1360c00000a, 516425ff298dcd4e51000051, 55191149622b194345000010,
|
291 |
+
52fa70142059c6d71c000056, 52f77f4d2059c6d71c00002a, 52efc016c8da89891000001a,
|
292 |
+
52efc001c8da898910000019, 52f896ae2059c6d71c000045, 52eceada98d023950500002d,
|
293 |
+
52efc05cc8da89891000001c, 515e078e298dcd4e51000031, 52fe54252059c6d71c000079,
|
294 |
+
514217a6d24251bc05000005, 52d1389303868f1b06000032, 530cf4d5e2bfff940c000003,
|
295 |
+
52fc946d2059c6d71c000071, 52e8e99e98d0239505000021, 52ef7786c8da898910000015,
|
296 |
+
52d8494698d0239505000007, 530cf51d5610acba0c000001, 52f637972059c6d71c000025,
|
297 |
+
52e9f99798d0239505000025, 515de572298dcd4e51000021, 52fe4ad52059c6d71c000077,
|
298 |
+
52f65bf02059c6d71c000026, 52e8e9d298d0239505000022, 52fa74052059c6d71c00005a,
|
299 |
+
52ffbddf2059c6d71c00007d, 56bc932aac7ad1001900001c, 56c02883ef6e394741000017,
|
300 |
+
52d2b75403868f1b06000035, 52f118aa2059c6d71c000003, 52e929eb98d0239505000023,
|
301 |
+
532c12f2d6d3ac6a3400001d, 52d8466298d0239505000006'
|
302 |
+
[3] The 48 questions resulting from merging with their pair have the
|
303 |
+
following ids: 5149aafcd24251bc05000045, 515db020298dcd4e51000011,
|
304 |
+
515db54c298dcd4e51000016, 51680a49298dcd4e51000062, 52b06a68f828ad283c000005,
|
305 |
+
52bf1aa503868f1b06000006, 52bf1af803868f1b06000008, 52bf1d6003868f1b0600000e,
|
306 |
+
52cb9b9b03868f1b0600002d, 52d2818403868f1b06000033, 52df887498d023950500000c,
|
307 |
+
52e0c9a298d0239505000010, 52e203bc98d0239505000011, 52e62bae98d0239505000015,
|
308 |
+
52e6c92598d0239505000019, 52e7bbf698d023950500001d, 52ea605098d0239505000028,
|
309 |
+
52ece29f98d023950500002c, 52ecf2dd98d023950500002e, 52ef7754c8da898910000014,
|
310 |
+
52f112bb2059c6d71c000002, 52f65f372059c6d71c000027, 52f77f752059c6d71c00002b,
|
311 |
+
52f77f892059c6d71c00002c, 52f89ee42059c6d71c00004d, 52f89f4f2059c6d71c00004e,
|
312 |
+
52f89fba2059c6d71c00004f, 52f89fc62059c6d71c000050, 52f89fd32059c6d71c000051,
|
313 |
+
52fa6ac72059c6d71c000055, 52fa73c62059c6d71c000058, 52fa73e82059c6d71c000059,
|
314 |
+
52fa74252059c6d71c00005b, 52fc8b772059c6d71c00006e, 52fc94572059c6d71c000070,
|
315 |
+
52fc94ae2059c6d71c000073, 52fc94db2059c6d71c000074, 52fe52702059c6d71c000078,
|
316 |
+
52fe58f82059c6d71c00007a, 530cefaaad0bf1360c000008, 530cefaaad0bf1360c000010,
|
317 |
+
533ba218fd9a95ea0d000007, 534bb147aeec6fbd07000014, 55167dec46478f2f2c00000a,
|
318 |
+
56c04412ef6e39474100001b, 56c1f01eef6e394741000046, 56c81fd15795f9a73e00000c,
|
319 |
+
587d016ed673c3eb14000002
|
320 |
+
"""
|
321 |
+
|
322 |
+
_BIOASQ_5B_DESCRIPTION = """\
|
323 |
+
The data are intended to be used as training and development data for BioASQ 5,
|
324 |
+
which will take place during 2017. There is one file containing the data:
|
325 |
+
- BioASQ-trainingDataset5b.json
|
326 |
+
|
327 |
+
The file contains the data of the first four editions of the challenge: 1799
|
328 |
+
questions with their relevant documents, snippets, concepts and rdf triples,
|
329 |
+
exact and ideal answers.
|
330 |
+
"""
|
331 |
+
|
332 |
+
_BIOASQ_4B_DESCRIPTION = """\
|
333 |
+
The data are intended to be used as training and development data for BioASQ 4,
|
334 |
+
which will take place during 2016. There is one file containing the data:
|
335 |
+
- BioASQ-trainingDataset4b.json
|
336 |
+
|
337 |
+
The file contains the data of the first three editions of the challenge: 1307
|
338 |
+
questions with their relevant documents, snippets, concepts and rdf triples,
|
339 |
+
exact and ideal answers from the first two editions and 497 questions with
|
340 |
+
similar annotations from the third editions of the challenge.
|
341 |
+
"""
|
342 |
+
|
343 |
+
_BIOASQ_3B_DESCRIPTION = """No README provided."""
|
344 |
+
|
345 |
+
_BIOASQ_2B_DESCRIPTION = """No README provided."""
|
346 |
+
|
347 |
+
_DESCRIPTION = {
|
348 |
+
"bioasq_10b": _BIOASQ_10B_DESCRIPTION,
|
349 |
+
"bioasq_9b": _BIOASQ_9B_DESCRIPTION,
|
350 |
+
"bioasq_8b": _BIOASQ_8B_DESCRIPTION,
|
351 |
+
"bioasq_7b": _BIOASQ_7B_DESCRIPTION,
|
352 |
+
"bioasq_6b": _BIOASQ_6B_DESCRIPTION,
|
353 |
+
"bioasq_5b": _BIOASQ_5B_DESCRIPTION,
|
354 |
+
"bioasq_4b": _BIOASQ_4B_DESCRIPTION,
|
355 |
+
"bioasq_3b": _BIOASQ_3B_DESCRIPTION,
|
356 |
+
"bioasq_2b": _BIOASQ_2B_DESCRIPTION,
|
357 |
+
}
|
358 |
+
|
359 |
+
_HOMEPAGE = "http://participants-area.bioasq.org/datasets/"
|
360 |
+
|
361 |
+
# Data access reqires registering with BioASQ.
|
362 |
+
# See http://participants-area.bioasq.org/accounts/register/
|
363 |
+
_LICENSE = "https://www.nlm.nih.gov/databases/download/terms_and_conditions.html"
|
364 |
+
|
365 |
+
_URLs = {
|
366 |
+
"bioasq_10b": ["BioASQ-training10b.zip", None],
|
367 |
+
"bioasq_9b": ["BioASQ-training9b.zip", "Task9BGoldenEnriched.zip"],
|
368 |
+
"bioasq_8b": ["BioASQ-training8b.zip", "Task8BGoldenEnriched.zip"],
|
369 |
+
"bioasq_7b": ["BioASQ-training7b.zip", "Task7BGoldenEnriched.zip"],
|
370 |
+
"bioasq_6b": ["BioASQ-training6b.zip", "Task6BGoldenEnriched.zip"],
|
371 |
+
"bioasq_5b": ["BioASQ-training5b.zip", "Task5BGoldenEnriched.zip"],
|
372 |
+
"bioasq_4b": ["BioASQ-training4b.zip", "Task4BGoldenEnriched.zip"],
|
373 |
+
"bioasq_3b": ["BioASQ-trainingDataset3b.zip", "Task3BGoldenEnriched.zip"],
|
374 |
+
"bioasq_2b": ["BioASQ-trainingDataset2b.zip", "Task2BGoldenEnriched.zip"],
|
375 |
+
}
|
376 |
+
|
377 |
+
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
378 |
+
_SOURCE_VERSION = "1.0.0"
|
379 |
+
_BIGBIO_VERSION = "1.0.0"
|
380 |
+
|
381 |
+
|
382 |
+
class BioasqTaskBDataset(datasets.GeneratorBasedBuilder):
|
383 |
+
"""
|
384 |
+
BioASQ Task B On Biomedical Semantic QA.
|
385 |
+
Creates configs for BioASQ2 through BioASQ10.
|
386 |
+
"""
|
387 |
+
|
388 |
+
DEFAULT_CONFIG_NAME = "bioasq_9b_source"
|
389 |
+
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
390 |
+
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
391 |
+
|
392 |
+
# BioASQ2 through BioASQ10
|
393 |
+
BUILDER_CONFIGS = []
|
394 |
+
for version in range(2, 11):
|
395 |
+
BUILDER_CONFIGS.append(
|
396 |
+
BigBioConfig(
|
397 |
+
name=f"bioasq_{version}b_source",
|
398 |
+
version=SOURCE_VERSION,
|
399 |
+
description=f"bioasq{version} Task B source schema",
|
400 |
+
schema="source",
|
401 |
+
subset_id=f"bioasq_{version}b",
|
402 |
+
)
|
403 |
+
)
|
404 |
+
|
405 |
+
BUILDER_CONFIGS.append(
|
406 |
+
BigBioConfig(
|
407 |
+
name=f"bioasq_{version}b_bigbio_qa",
|
408 |
+
version=BIGBIO_VERSION,
|
409 |
+
description=f"bioasq{version} Task B in simplified BigBio schema",
|
410 |
+
schema="bigbio_qa",
|
411 |
+
subset_id=f"bioasq_{version}b",
|
412 |
+
)
|
413 |
+
)
|
414 |
+
|
415 |
+
def _info(self):
|
416 |
+
|
417 |
+
# BioASQ Task B source schema
|
418 |
+
if self.config.schema == "source":
|
419 |
+
features = datasets.Features(
|
420 |
+
{
|
421 |
+
"id": datasets.Value("string"),
|
422 |
+
"type": datasets.Value("string"),
|
423 |
+
"body": datasets.Value("string"),
|
424 |
+
"documents": datasets.Sequence(datasets.Value("string")),
|
425 |
+
"concepts": datasets.Sequence(datasets.Value("string")),
|
426 |
+
"ideal_answer": datasets.Sequence(datasets.Value("string")),
|
427 |
+
"exact_answer": datasets.Sequence(datasets.Value("string")),
|
428 |
+
"triples": [
|
429 |
+
{
|
430 |
+
"p": datasets.Value("string"),
|
431 |
+
"s": datasets.Value("string"),
|
432 |
+
"o": datasets.Value("string"),
|
433 |
+
}
|
434 |
+
],
|
435 |
+
"snippets": [
|
436 |
+
{
|
437 |
+
"offsetInBeginSection": datasets.Value("int32"),
|
438 |
+
"offsetInEndSection": datasets.Value("int32"),
|
439 |
+
"text": datasets.Value("string"),
|
440 |
+
"beginSection": datasets.Value("string"),
|
441 |
+
"endSection": datasets.Value("string"),
|
442 |
+
"document": datasets.Value("string"),
|
443 |
+
}
|
444 |
+
],
|
445 |
+
}
|
446 |
+
)
|
447 |
+
# simplified schema for QA tasks
|
448 |
+
elif self.config.schema == "bigbio_qa":
|
449 |
+
features = schemas.qa_features
|
450 |
+
|
451 |
+
return datasets.DatasetInfo(
|
452 |
+
description=_DESCRIPTION[self.config.subset_id],
|
453 |
+
features=features,
|
454 |
+
supervised_keys=None,
|
455 |
+
homepage=_HOMEPAGE,
|
456 |
+
license=_LICENSE,
|
457 |
+
citation=_CITATION,
|
458 |
+
)
|
459 |
+
|
460 |
+
def _dump_gold_json(self, data_dir):
|
461 |
+
"""
|
462 |
+
BioASQ test data is split into multiple records {9B1_golden.json,...,9B5_golden.json}
|
463 |
+
We combine these files into a single test set file 9Bx_golden.json
|
464 |
+
"""
|
465 |
+
version = re.search(r"bioasq_([0-9]+)b", self.config.subset_id).group(1)
|
466 |
+
gold_fpath = os.path.join(
|
467 |
+
data_dir, f"Task{version}BGoldenEnriched/bx_golden.json"
|
468 |
+
)
|
469 |
+
|
470 |
+
if not os.path.exists(gold_fpath):
|
471 |
+
# combine all gold json files
|
472 |
+
filelist = glob.glob(os.path.join(data_dir, "*/*.json"))
|
473 |
+
data = {"questions": []}
|
474 |
+
for fname in sorted(filelist):
|
475 |
+
with open(fname, "rt", encoding="utf-8") as file:
|
476 |
+
data["questions"].extend(json.load(file)["questions"])
|
477 |
+
# dump gold to json
|
478 |
+
with open(gold_fpath, "wt", encoding="utf-8") as file:
|
479 |
+
json.dump(data, file, indent=2)
|
480 |
+
|
481 |
+
return f"Task{version}BGoldenEnriched/bx_golden.json"
|
482 |
+
|
483 |
+
def _split_generators(self, dl_manager):
|
484 |
+
"""Returns SplitGenerators."""
|
485 |
+
|
486 |
+
if self.config.data_dir is None:
|
487 |
+
raise ValueError(
|
488 |
+
"This is a local dataset. Please pass the data_dir kwarg to load_dataset."
|
489 |
+
)
|
490 |
+
|
491 |
+
train_dir, test_dir = dl_manager.download_and_extract(
|
492 |
+
[
|
493 |
+
os.path.join(self.config.data_dir, _url)
|
494 |
+
for _url in _URLs[self.config.subset_id]
|
495 |
+
]
|
496 |
+
)
|
497 |
+
gold_fpath = self._dump_gold_json(test_dir)
|
498 |
+
|
499 |
+
# older versions of bioasq have different folder formats
|
500 |
+
train_fpaths = {
|
501 |
+
"bioasq_2b": "BioASQ_2013_TaskB/BioASQ-trainingDataset2b.json",
|
502 |
+
"bioasq_3b": "BioASQ-trainingDataset3b.json",
|
503 |
+
"bioasq_4b": "BioASQ-training4b/BioASQ-trainingDataset4b.json",
|
504 |
+
"bioasq_5b": "BioASQ-training5b/BioASQ-trainingDataset5b.json",
|
505 |
+
"bioasq_6b": "BioASQ-training6b/BioASQ-trainingDataset6b.json",
|
506 |
+
"bioasq_7b": "BioASQ-training7b/trainining7b.json",
|
507 |
+
"bioasq_8b": "training8b.json", # HACK - this zipfile strips the dirname
|
508 |
+
"bioasq_9b": "BioASQ-training9b/training9b.json",
|
509 |
+
"bioasq_10b": "BioASQ-training10b/training10b.json",
|
510 |
+
}
|
511 |
+
|
512 |
+
return [
|
513 |
+
datasets.SplitGenerator(
|
514 |
+
name=datasets.Split.TRAIN,
|
515 |
+
gen_kwargs={
|
516 |
+
"filepath": os.path.join(
|
517 |
+
train_dir, train_fpaths[self.config.subset_id]
|
518 |
+
),
|
519 |
+
"split": "train",
|
520 |
+
},
|
521 |
+
),
|
522 |
+
datasets.SplitGenerator(
|
523 |
+
name=datasets.Split.TEST,
|
524 |
+
gen_kwargs={
|
525 |
+
"filepath": os.path.join(test_dir, gold_fpath),
|
526 |
+
"split": "test",
|
527 |
+
},
|
528 |
+
),
|
529 |
+
]
|
530 |
+
|
531 |
+
def _get_exact_answer(self, record):
|
532 |
+
"""The value exact_answer can be in different formats based on question type."""
|
533 |
+
if record["type"] == "yesno":
|
534 |
+
exact_answer = [record["exact_answer"]]
|
535 |
+
elif record["type"] == "summary":
|
536 |
+
exact_answer = []
|
537 |
+
# summary question types only have an ideal answer, so use that for bigbio
|
538 |
+
if self.config.schema == "bigbio_qa":
|
539 |
+
exact_answer = (
|
540 |
+
record["ideal_answer"]
|
541 |
+
if isinstance(record["ideal_answer"], list)
|
542 |
+
else [record["ideal_answer"]]
|
543 |
+
)
|
544 |
+
|
545 |
+
elif record["type"] == "list":
|
546 |
+
exact_answer = record["exact_answer"]
|
547 |
+
elif record["type"] == "factoid":
|
548 |
+
# older version of bioasq sometimes represent this as as string
|
549 |
+
exact_answer = (
|
550 |
+
record["exact_answer"]
|
551 |
+
if isinstance(record["exact_answer"], list)
|
552 |
+
else [record["exact_answer"]]
|
553 |
+
)
|
554 |
+
return exact_answer
|
555 |
+
|
556 |
+
def _generate_examples(self, filepath, split):
|
557 |
+
"""Yields examples as (key, example) tuples."""
|
558 |
+
|
559 |
+
if self.config.schema == "source":
|
560 |
+
with open(filepath, encoding="utf-8") as file:
|
561 |
+
data = json.load(file)
|
562 |
+
for i, record in enumerate(data["questions"]):
|
563 |
+
yield i, {
|
564 |
+
"id": record["id"],
|
565 |
+
"type": record["type"],
|
566 |
+
"body": record["body"],
|
567 |
+
"documents": record["documents"],
|
568 |
+
"concepts": record["concepts"] if "concepts" in record else [],
|
569 |
+
"triples": record["triples"] if "triples" in record else [],
|
570 |
+
"ideal_answer": record["ideal_answer"]
|
571 |
+
if isinstance(record["ideal_answer"], list)
|
572 |
+
else [record["ideal_answer"]],
|
573 |
+
"exact_answer": self._get_exact_answer(record),
|
574 |
+
"snippets": record["snippets"] if "snippets" in record else [],
|
575 |
+
}
|
576 |
+
|
577 |
+
elif self.config.schema == "bigbio_qa":
|
578 |
+
with open(filepath, encoding="utf-8") as file:
|
579 |
+
uid = 0
|
580 |
+
data = json.load(file)
|
581 |
+
for record in data["questions"]:
|
582 |
+
# for questions that do not have snippets, skip
|
583 |
+
if "snippets" not in record:
|
584 |
+
continue
|
585 |
+
for i, snippet in enumerate(record["snippets"]):
|
586 |
+
yield uid, {
|
587 |
+
"id": f'{record["id"]}_{i}',
|
588 |
+
"document_id": snippet["document"],
|
589 |
+
"question_id": record["id"],
|
590 |
+
"question": record["body"],
|
591 |
+
"type": record["type"],
|
592 |
+
"choices": [],
|
593 |
+
"context": snippet["text"],
|
594 |
+
"answer": self._get_exact_answer(record),
|
595 |
+
}
|
596 |
+
uid += 1
|