Commit
·
a3563cb
1
Parent(s):
f4bcff3
Update parquet files
Browse files- .gitattributes +0 -54
- bigbiohub.py +0 -556
- biomrc.py +0 -247
- biomrc_large_A_bigbio_qa/biomrc-test.parquet +3 -0
- biomrc_large_A_bigbio_qa/biomrc-train-00000-of-00003.parquet +3 -0
- biomrc_large_A_bigbio_qa/biomrc-train-00001-of-00003.parquet +3 -0
- biomrc_large_A_bigbio_qa/biomrc-train-00002-of-00003.parquet +3 -0
- biomrc_large_A_bigbio_qa/biomrc-validation.parquet +3 -0
- biomrc_large_A_source/biomrc-test.parquet +3 -0
- biomrc_large_A_source/biomrc-train-00000-of-00004.parquet +3 -0
- biomrc_large_A_source/biomrc-train-00001-of-00004.parquet +3 -0
- biomrc_large_A_source/biomrc-train-00002-of-00004.parquet +3 -0
- biomrc_large_A_source/biomrc-train-00003-of-00004.parquet +3 -0
- biomrc_large_A_source/biomrc-validation.parquet +3 -0
- biomrc_large_B_bigbio_qa/biomrc-test.parquet +3 -0
- biomrc_large_B_bigbio_qa/biomrc-train-00000-of-00003.parquet +3 -0
- biomrc_large_B_bigbio_qa/biomrc-train-00001-of-00003.parquet +3 -0
- biomrc_large_B_bigbio_qa/biomrc-train-00002-of-00003.parquet +3 -0
- biomrc_large_B_bigbio_qa/biomrc-validation.parquet +3 -0
- biomrc_large_B_source/biomrc-test.parquet +3 -0
- biomrc_large_B_source/biomrc-train-00000-of-00003.parquet +3 -0
- biomrc_large_B_source/biomrc-train-00001-of-00003.parquet +3 -0
- biomrc_large_B_source/biomrc-train-00002-of-00003.parquet +3 -0
- biomrc_large_B_source/biomrc-validation.parquet +3 -0
- biomrc_small_A_bigbio_qa/biomrc-test.parquet +3 -0
- biomrc_small_A_bigbio_qa/biomrc-train.parquet +3 -0
- biomrc_small_A_bigbio_qa/biomrc-validation.parquet +3 -0
- biomrc_small_A_source/biomrc-test.parquet +3 -0
- biomrc_small_A_source/biomrc-train.parquet +3 -0
- biomrc_small_A_source/biomrc-validation.parquet +3 -0
- biomrc_small_B_bigbio_qa/biomrc-test.parquet +3 -0
- biomrc_small_B_bigbio_qa/biomrc-train.parquet +3 -0
- biomrc_small_B_bigbio_qa/biomrc-validation.parquet +3 -0
- biomrc_small_B_source/biomrc-test.parquet +3 -0
- biomrc_small_B_source/biomrc-train.parquet +3 -0
- biomrc_small_B_source/biomrc-validation.parquet +3 -0
- biomrc_tiny_A_bigbio_qa/biomrc-train.parquet +3 -0
- biomrc_tiny_A_source/biomrc-train.parquet +3 -0
- biomrc_tiny_B_bigbio_qa/biomrc-train.parquet +3 -0
- biomrc_tiny_B_source/biomrc-train.parquet +3 -0
.gitattributes
DELETED
@@ -1,54 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.lz4 filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
24 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
26 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
27 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
-
# Audio files - uncompressed
|
37 |
-
*.pcm filter=lfs diff=lfs merge=lfs -text
|
38 |
-
*.sam filter=lfs diff=lfs merge=lfs -text
|
39 |
-
*.raw filter=lfs diff=lfs merge=lfs -text
|
40 |
-
# Audio files - compressed
|
41 |
-
*.aac filter=lfs diff=lfs merge=lfs -text
|
42 |
-
*.flac filter=lfs diff=lfs merge=lfs -text
|
43 |
-
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
44 |
-
*.ogg filter=lfs diff=lfs merge=lfs -text
|
45 |
-
*.wav filter=lfs diff=lfs merge=lfs -text
|
46 |
-
# Image files - uncompressed
|
47 |
-
*.bmp filter=lfs diff=lfs merge=lfs -text
|
48 |
-
*.gif filter=lfs diff=lfs merge=lfs -text
|
49 |
-
*.png filter=lfs diff=lfs merge=lfs -text
|
50 |
-
*.tiff filter=lfs diff=lfs merge=lfs -text
|
51 |
-
# Image files - compressed
|
52 |
-
*.jpg filter=lfs diff=lfs merge=lfs -text
|
53 |
-
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
54 |
-
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bigbiohub.py
DELETED
@@ -1,556 +0,0 @@
|
|
1 |
-
from collections import defaultdict
|
2 |
-
from dataclasses import dataclass
|
3 |
-
from enum import Enum
|
4 |
-
import logging
|
5 |
-
from pathlib import Path
|
6 |
-
from types import SimpleNamespace
|
7 |
-
from typing import TYPE_CHECKING, Dict, Iterable, List, Tuple
|
8 |
-
|
9 |
-
import datasets
|
10 |
-
|
11 |
-
if TYPE_CHECKING:
|
12 |
-
import bioc
|
13 |
-
|
14 |
-
logger = logging.getLogger(__name__)
|
15 |
-
|
16 |
-
|
17 |
-
BigBioValues = SimpleNamespace(NULL="<BB_NULL_STR>")
|
18 |
-
|
19 |
-
|
20 |
-
@dataclass
|
21 |
-
class BigBioConfig(datasets.BuilderConfig):
|
22 |
-
"""BuilderConfig for BigBio."""
|
23 |
-
|
24 |
-
name: str = None
|
25 |
-
version: datasets.Version = None
|
26 |
-
description: str = None
|
27 |
-
schema: str = None
|
28 |
-
subset_id: str = None
|
29 |
-
|
30 |
-
|
31 |
-
class Tasks(Enum):
|
32 |
-
NAMED_ENTITY_RECOGNITION = "NER"
|
33 |
-
NAMED_ENTITY_DISAMBIGUATION = "NED"
|
34 |
-
EVENT_EXTRACTION = "EE"
|
35 |
-
RELATION_EXTRACTION = "RE"
|
36 |
-
COREFERENCE_RESOLUTION = "COREF"
|
37 |
-
QUESTION_ANSWERING = "QA"
|
38 |
-
TEXTUAL_ENTAILMENT = "TE"
|
39 |
-
SEMANTIC_SIMILARITY = "STS"
|
40 |
-
TEXT_PAIRS_CLASSIFICATION = "TXT2CLASS"
|
41 |
-
PARAPHRASING = "PARA"
|
42 |
-
TRANSLATION = "TRANSL"
|
43 |
-
SUMMARIZATION = "SUM"
|
44 |
-
TEXT_CLASSIFICATION = "TXTCLASS"
|
45 |
-
|
46 |
-
|
47 |
-
entailment_features = datasets.Features(
|
48 |
-
{
|
49 |
-
"id": datasets.Value("string"),
|
50 |
-
"premise": datasets.Value("string"),
|
51 |
-
"hypothesis": datasets.Value("string"),
|
52 |
-
"label": datasets.Value("string"),
|
53 |
-
}
|
54 |
-
)
|
55 |
-
|
56 |
-
pairs_features = datasets.Features(
|
57 |
-
{
|
58 |
-
"id": datasets.Value("string"),
|
59 |
-
"document_id": datasets.Value("string"),
|
60 |
-
"text_1": datasets.Value("string"),
|
61 |
-
"text_2": datasets.Value("string"),
|
62 |
-
"label": datasets.Value("string"),
|
63 |
-
}
|
64 |
-
)
|
65 |
-
|
66 |
-
qa_features = datasets.Features(
|
67 |
-
{
|
68 |
-
"id": datasets.Value("string"),
|
69 |
-
"question_id": datasets.Value("string"),
|
70 |
-
"document_id": datasets.Value("string"),
|
71 |
-
"question": datasets.Value("string"),
|
72 |
-
"type": datasets.Value("string"),
|
73 |
-
"choices": [datasets.Value("string")],
|
74 |
-
"context": datasets.Value("string"),
|
75 |
-
"answer": datasets.Sequence(datasets.Value("string")),
|
76 |
-
}
|
77 |
-
)
|
78 |
-
|
79 |
-
text_features = datasets.Features(
|
80 |
-
{
|
81 |
-
"id": datasets.Value("string"),
|
82 |
-
"document_id": datasets.Value("string"),
|
83 |
-
"text": datasets.Value("string"),
|
84 |
-
"labels": [datasets.Value("string")],
|
85 |
-
}
|
86 |
-
)
|
87 |
-
|
88 |
-
text2text_features = datasets.Features(
|
89 |
-
{
|
90 |
-
"id": datasets.Value("string"),
|
91 |
-
"document_id": datasets.Value("string"),
|
92 |
-
"text_1": datasets.Value("string"),
|
93 |
-
"text_2": datasets.Value("string"),
|
94 |
-
"text_1_name": datasets.Value("string"),
|
95 |
-
"text_2_name": datasets.Value("string"),
|
96 |
-
}
|
97 |
-
)
|
98 |
-
|
99 |
-
kb_features = datasets.Features(
|
100 |
-
{
|
101 |
-
"id": datasets.Value("string"),
|
102 |
-
"document_id": datasets.Value("string"),
|
103 |
-
"passages": [
|
104 |
-
{
|
105 |
-
"id": datasets.Value("string"),
|
106 |
-
"type": datasets.Value("string"),
|
107 |
-
"text": datasets.Sequence(datasets.Value("string")),
|
108 |
-
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
109 |
-
}
|
110 |
-
],
|
111 |
-
"entities": [
|
112 |
-
{
|
113 |
-
"id": datasets.Value("string"),
|
114 |
-
"type": datasets.Value("string"),
|
115 |
-
"text": datasets.Sequence(datasets.Value("string")),
|
116 |
-
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
117 |
-
"normalized": [
|
118 |
-
{
|
119 |
-
"db_name": datasets.Value("string"),
|
120 |
-
"db_id": datasets.Value("string"),
|
121 |
-
}
|
122 |
-
],
|
123 |
-
}
|
124 |
-
],
|
125 |
-
"events": [
|
126 |
-
{
|
127 |
-
"id": datasets.Value("string"),
|
128 |
-
"type": datasets.Value("string"),
|
129 |
-
# refers to the text_bound_annotation of the trigger
|
130 |
-
"trigger": {
|
131 |
-
"text": datasets.Sequence(datasets.Value("string")),
|
132 |
-
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
133 |
-
},
|
134 |
-
"arguments": [
|
135 |
-
{
|
136 |
-
"role": datasets.Value("string"),
|
137 |
-
"ref_id": datasets.Value("string"),
|
138 |
-
}
|
139 |
-
],
|
140 |
-
}
|
141 |
-
],
|
142 |
-
"coreferences": [
|
143 |
-
{
|
144 |
-
"id": datasets.Value("string"),
|
145 |
-
"entity_ids": datasets.Sequence(datasets.Value("string")),
|
146 |
-
}
|
147 |
-
],
|
148 |
-
"relations": [
|
149 |
-
{
|
150 |
-
"id": datasets.Value("string"),
|
151 |
-
"type": datasets.Value("string"),
|
152 |
-
"arg1_id": datasets.Value("string"),
|
153 |
-
"arg2_id": datasets.Value("string"),
|
154 |
-
"normalized": [
|
155 |
-
{
|
156 |
-
"db_name": datasets.Value("string"),
|
157 |
-
"db_id": datasets.Value("string"),
|
158 |
-
}
|
159 |
-
],
|
160 |
-
}
|
161 |
-
],
|
162 |
-
}
|
163 |
-
)
|
164 |
-
|
165 |
-
|
166 |
-
def get_texts_and_offsets_from_bioc_ann(ann: "bioc.BioCAnnotation") -> Tuple:
|
167 |
-
|
168 |
-
offsets = [(loc.offset, loc.offset + loc.length) for loc in ann.locations]
|
169 |
-
|
170 |
-
text = ann.text
|
171 |
-
|
172 |
-
if len(offsets) > 1:
|
173 |
-
i = 0
|
174 |
-
texts = []
|
175 |
-
for start, end in offsets:
|
176 |
-
chunk_len = end - start
|
177 |
-
texts.append(text[i : chunk_len + i])
|
178 |
-
i += chunk_len
|
179 |
-
while i < len(text) and text[i] == " ":
|
180 |
-
i += 1
|
181 |
-
else:
|
182 |
-
texts = [text]
|
183 |
-
|
184 |
-
return offsets, texts
|
185 |
-
|
186 |
-
|
187 |
-
def remove_prefix(a: str, prefix: str) -> str:
|
188 |
-
if a.startswith(prefix):
|
189 |
-
a = a[len(prefix) :]
|
190 |
-
return a
|
191 |
-
|
192 |
-
|
193 |
-
def parse_brat_file(
|
194 |
-
txt_file: Path,
|
195 |
-
annotation_file_suffixes: List[str] = None,
|
196 |
-
parse_notes: bool = False,
|
197 |
-
) -> Dict:
|
198 |
-
"""
|
199 |
-
Parse a brat file into the schema defined below.
|
200 |
-
`txt_file` should be the path to the brat '.txt' file you want to parse, e.g. 'data/1234.txt'
|
201 |
-
Assumes that the annotations are contained in one or more of the corresponding '.a1', '.a2' or '.ann' files,
|
202 |
-
e.g. 'data/1234.ann' or 'data/1234.a1' and 'data/1234.a2'.
|
203 |
-
Will include annotator notes, when `parse_notes == True`.
|
204 |
-
brat_features = datasets.Features(
|
205 |
-
{
|
206 |
-
"id": datasets.Value("string"),
|
207 |
-
"document_id": datasets.Value("string"),
|
208 |
-
"text": datasets.Value("string"),
|
209 |
-
"text_bound_annotations": [ # T line in brat, e.g. type or event trigger
|
210 |
-
{
|
211 |
-
"offsets": datasets.Sequence([datasets.Value("int32")]),
|
212 |
-
"text": datasets.Sequence(datasets.Value("string")),
|
213 |
-
"type": datasets.Value("string"),
|
214 |
-
"id": datasets.Value("string"),
|
215 |
-
}
|
216 |
-
],
|
217 |
-
"events": [ # E line in brat
|
218 |
-
{
|
219 |
-
"trigger": datasets.Value(
|
220 |
-
"string"
|
221 |
-
), # refers to the text_bound_annotation of the trigger,
|
222 |
-
"id": datasets.Value("string"),
|
223 |
-
"type": datasets.Value("string"),
|
224 |
-
"arguments": datasets.Sequence(
|
225 |
-
{
|
226 |
-
"role": datasets.Value("string"),
|
227 |
-
"ref_id": datasets.Value("string"),
|
228 |
-
}
|
229 |
-
),
|
230 |
-
}
|
231 |
-
],
|
232 |
-
"relations": [ # R line in brat
|
233 |
-
{
|
234 |
-
"id": datasets.Value("string"),
|
235 |
-
"head": {
|
236 |
-
"ref_id": datasets.Value("string"),
|
237 |
-
"role": datasets.Value("string"),
|
238 |
-
},
|
239 |
-
"tail": {
|
240 |
-
"ref_id": datasets.Value("string"),
|
241 |
-
"role": datasets.Value("string"),
|
242 |
-
},
|
243 |
-
"type": datasets.Value("string"),
|
244 |
-
}
|
245 |
-
],
|
246 |
-
"equivalences": [ # Equiv line in brat
|
247 |
-
{
|
248 |
-
"id": datasets.Value("string"),
|
249 |
-
"ref_ids": datasets.Sequence(datasets.Value("string")),
|
250 |
-
}
|
251 |
-
],
|
252 |
-
"attributes": [ # M or A lines in brat
|
253 |
-
{
|
254 |
-
"id": datasets.Value("string"),
|
255 |
-
"type": datasets.Value("string"),
|
256 |
-
"ref_id": datasets.Value("string"),
|
257 |
-
"value": datasets.Value("string"),
|
258 |
-
}
|
259 |
-
],
|
260 |
-
"normalizations": [ # N lines in brat
|
261 |
-
{
|
262 |
-
"id": datasets.Value("string"),
|
263 |
-
"type": datasets.Value("string"),
|
264 |
-
"ref_id": datasets.Value("string"),
|
265 |
-
"resource_name": datasets.Value(
|
266 |
-
"string"
|
267 |
-
), # Name of the resource, e.g. "Wikipedia"
|
268 |
-
"cuid": datasets.Value(
|
269 |
-
"string"
|
270 |
-
), # ID in the resource, e.g. 534366
|
271 |
-
"text": datasets.Value(
|
272 |
-
"string"
|
273 |
-
), # Human readable description/name of the entity, e.g. "Barack Obama"
|
274 |
-
}
|
275 |
-
],
|
276 |
-
### OPTIONAL: Only included when `parse_notes == True`
|
277 |
-
"notes": [ # # lines in brat
|
278 |
-
{
|
279 |
-
"id": datasets.Value("string"),
|
280 |
-
"type": datasets.Value("string"),
|
281 |
-
"ref_id": datasets.Value("string"),
|
282 |
-
"text": datasets.Value("string"),
|
283 |
-
}
|
284 |
-
],
|
285 |
-
},
|
286 |
-
)
|
287 |
-
"""
|
288 |
-
|
289 |
-
example = {}
|
290 |
-
example["document_id"] = txt_file.with_suffix("").name
|
291 |
-
with txt_file.open() as f:
|
292 |
-
example["text"] = f.read()
|
293 |
-
|
294 |
-
# If no specific suffixes of the to-be-read annotation files are given - take standard suffixes
|
295 |
-
# for event extraction
|
296 |
-
if annotation_file_suffixes is None:
|
297 |
-
annotation_file_suffixes = [".a1", ".a2", ".ann"]
|
298 |
-
|
299 |
-
if len(annotation_file_suffixes) == 0:
|
300 |
-
raise AssertionError(
|
301 |
-
"At least one suffix for the to-be-read annotation files should be given!"
|
302 |
-
)
|
303 |
-
|
304 |
-
ann_lines = []
|
305 |
-
for suffix in annotation_file_suffixes:
|
306 |
-
annotation_file = txt_file.with_suffix(suffix)
|
307 |
-
if annotation_file.exists():
|
308 |
-
with annotation_file.open() as f:
|
309 |
-
ann_lines.extend(f.readlines())
|
310 |
-
|
311 |
-
example["text_bound_annotations"] = []
|
312 |
-
example["events"] = []
|
313 |
-
example["relations"] = []
|
314 |
-
example["equivalences"] = []
|
315 |
-
example["attributes"] = []
|
316 |
-
example["normalizations"] = []
|
317 |
-
|
318 |
-
if parse_notes:
|
319 |
-
example["notes"] = []
|
320 |
-
|
321 |
-
for line in ann_lines:
|
322 |
-
line = line.strip()
|
323 |
-
if not line:
|
324 |
-
continue
|
325 |
-
|
326 |
-
if line.startswith("T"): # Text bound
|
327 |
-
ann = {}
|
328 |
-
fields = line.split("\t")
|
329 |
-
|
330 |
-
ann["id"] = fields[0]
|
331 |
-
ann["type"] = fields[1].split()[0]
|
332 |
-
ann["offsets"] = []
|
333 |
-
span_str = remove_prefix(fields[1], (ann["type"] + " "))
|
334 |
-
text = fields[2]
|
335 |
-
for span in span_str.split(";"):
|
336 |
-
start, end = span.split()
|
337 |
-
ann["offsets"].append([int(start), int(end)])
|
338 |
-
|
339 |
-
# Heuristically split text of discontiguous entities into chunks
|
340 |
-
ann["text"] = []
|
341 |
-
if len(ann["offsets"]) > 1:
|
342 |
-
i = 0
|
343 |
-
for start, end in ann["offsets"]:
|
344 |
-
chunk_len = end - start
|
345 |
-
ann["text"].append(text[i : chunk_len + i])
|
346 |
-
i += chunk_len
|
347 |
-
while i < len(text) and text[i] == " ":
|
348 |
-
i += 1
|
349 |
-
else:
|
350 |
-
ann["text"] = [text]
|
351 |
-
|
352 |
-
example["text_bound_annotations"].append(ann)
|
353 |
-
|
354 |
-
elif line.startswith("E"):
|
355 |
-
ann = {}
|
356 |
-
fields = line.split("\t")
|
357 |
-
|
358 |
-
ann["id"] = fields[0]
|
359 |
-
|
360 |
-
ann["type"], ann["trigger"] = fields[1].split()[0].split(":")
|
361 |
-
|
362 |
-
ann["arguments"] = []
|
363 |
-
for role_ref_id in fields[1].split()[1:]:
|
364 |
-
argument = {
|
365 |
-
"role": (role_ref_id.split(":"))[0],
|
366 |
-
"ref_id": (role_ref_id.split(":"))[1],
|
367 |
-
}
|
368 |
-
ann["arguments"].append(argument)
|
369 |
-
|
370 |
-
example["events"].append(ann)
|
371 |
-
|
372 |
-
elif line.startswith("R"):
|
373 |
-
ann = {}
|
374 |
-
fields = line.split("\t")
|
375 |
-
|
376 |
-
ann["id"] = fields[0]
|
377 |
-
ann["type"] = fields[1].split()[0]
|
378 |
-
|
379 |
-
ann["head"] = {
|
380 |
-
"role": fields[1].split()[1].split(":")[0],
|
381 |
-
"ref_id": fields[1].split()[1].split(":")[1],
|
382 |
-
}
|
383 |
-
ann["tail"] = {
|
384 |
-
"role": fields[1].split()[2].split(":")[0],
|
385 |
-
"ref_id": fields[1].split()[2].split(":")[1],
|
386 |
-
}
|
387 |
-
|
388 |
-
example["relations"].append(ann)
|
389 |
-
|
390 |
-
# '*' seems to be the legacy way to mark equivalences,
|
391 |
-
# but I couldn't find any info on the current way
|
392 |
-
# this might have to be adapted dependent on the brat version
|
393 |
-
# of the annotation
|
394 |
-
elif line.startswith("*"):
|
395 |
-
ann = {}
|
396 |
-
fields = line.split("\t")
|
397 |
-
|
398 |
-
ann["id"] = fields[0]
|
399 |
-
ann["ref_ids"] = fields[1].split()[1:]
|
400 |
-
|
401 |
-
example["equivalences"].append(ann)
|
402 |
-
|
403 |
-
elif line.startswith("A") or line.startswith("M"):
|
404 |
-
ann = {}
|
405 |
-
fields = line.split("\t")
|
406 |
-
|
407 |
-
ann["id"] = fields[0]
|
408 |
-
|
409 |
-
info = fields[1].split()
|
410 |
-
ann["type"] = info[0]
|
411 |
-
ann["ref_id"] = info[1]
|
412 |
-
|
413 |
-
if len(info) > 2:
|
414 |
-
ann["value"] = info[2]
|
415 |
-
else:
|
416 |
-
ann["value"] = ""
|
417 |
-
|
418 |
-
example["attributes"].append(ann)
|
419 |
-
|
420 |
-
elif line.startswith("N"):
|
421 |
-
ann = {}
|
422 |
-
fields = line.split("\t")
|
423 |
-
|
424 |
-
ann["id"] = fields[0]
|
425 |
-
ann["text"] = fields[2]
|
426 |
-
|
427 |
-
info = fields[1].split()
|
428 |
-
|
429 |
-
ann["type"] = info[0]
|
430 |
-
ann["ref_id"] = info[1]
|
431 |
-
ann["resource_name"] = info[2].split(":")[0]
|
432 |
-
ann["cuid"] = info[2].split(":")[1]
|
433 |
-
example["normalizations"].append(ann)
|
434 |
-
|
435 |
-
elif parse_notes and line.startswith("#"):
|
436 |
-
ann = {}
|
437 |
-
fields = line.split("\t")
|
438 |
-
|
439 |
-
ann["id"] = fields[0]
|
440 |
-
ann["text"] = fields[2] if len(fields) == 3 else BigBioValues.NULL
|
441 |
-
|
442 |
-
info = fields[1].split()
|
443 |
-
|
444 |
-
ann["type"] = info[0]
|
445 |
-
ann["ref_id"] = info[1]
|
446 |
-
example["notes"].append(ann)
|
447 |
-
|
448 |
-
return example
|
449 |
-
|
450 |
-
|
451 |
-
def brat_parse_to_bigbio_kb(brat_parse: Dict) -> Dict:
|
452 |
-
"""
|
453 |
-
Transform a brat parse (conforming to the standard brat schema) obtained with
|
454 |
-
`parse_brat_file` into a dictionary conforming to the `bigbio-kb` schema (as defined in ../schemas/kb.py)
|
455 |
-
:param brat_parse:
|
456 |
-
"""
|
457 |
-
|
458 |
-
unified_example = {}
|
459 |
-
|
460 |
-
# Prefix all ids with document id to ensure global uniqueness,
|
461 |
-
# because brat ids are only unique within their document
|
462 |
-
id_prefix = brat_parse["document_id"] + "_"
|
463 |
-
|
464 |
-
# identical
|
465 |
-
unified_example["document_id"] = brat_parse["document_id"]
|
466 |
-
unified_example["passages"] = [
|
467 |
-
{
|
468 |
-
"id": id_prefix + "_text",
|
469 |
-
"type": "abstract",
|
470 |
-
"text": [brat_parse["text"]],
|
471 |
-
"offsets": [[0, len(brat_parse["text"])]],
|
472 |
-
}
|
473 |
-
]
|
474 |
-
|
475 |
-
# get normalizations
|
476 |
-
ref_id_to_normalizations = defaultdict(list)
|
477 |
-
for normalization in brat_parse["normalizations"]:
|
478 |
-
ref_id_to_normalizations[normalization["ref_id"]].append(
|
479 |
-
{
|
480 |
-
"db_name": normalization["resource_name"],
|
481 |
-
"db_id": normalization["cuid"],
|
482 |
-
}
|
483 |
-
)
|
484 |
-
|
485 |
-
# separate entities and event triggers
|
486 |
-
unified_example["events"] = []
|
487 |
-
non_event_ann = brat_parse["text_bound_annotations"].copy()
|
488 |
-
for event in brat_parse["events"]:
|
489 |
-
event = event.copy()
|
490 |
-
event["id"] = id_prefix + event["id"]
|
491 |
-
trigger = next(
|
492 |
-
tr
|
493 |
-
for tr in brat_parse["text_bound_annotations"]
|
494 |
-
if tr["id"] == event["trigger"]
|
495 |
-
)
|
496 |
-
if trigger in non_event_ann:
|
497 |
-
non_event_ann.remove(trigger)
|
498 |
-
event["trigger"] = {
|
499 |
-
"text": trigger["text"].copy(),
|
500 |
-
"offsets": trigger["offsets"].copy(),
|
501 |
-
}
|
502 |
-
for argument in event["arguments"]:
|
503 |
-
argument["ref_id"] = id_prefix + argument["ref_id"]
|
504 |
-
|
505 |
-
unified_example["events"].append(event)
|
506 |
-
|
507 |
-
unified_example["entities"] = []
|
508 |
-
anno_ids = [ref_id["id"] for ref_id in non_event_ann]
|
509 |
-
for ann in non_event_ann:
|
510 |
-
entity_ann = ann.copy()
|
511 |
-
entity_ann["id"] = id_prefix + entity_ann["id"]
|
512 |
-
entity_ann["normalized"] = ref_id_to_normalizations[ann["id"]]
|
513 |
-
unified_example["entities"].append(entity_ann)
|
514 |
-
|
515 |
-
# massage relations
|
516 |
-
unified_example["relations"] = []
|
517 |
-
skipped_relations = set()
|
518 |
-
for ann in brat_parse["relations"]:
|
519 |
-
if (
|
520 |
-
ann["head"]["ref_id"] not in anno_ids
|
521 |
-
or ann["tail"]["ref_id"] not in anno_ids
|
522 |
-
):
|
523 |
-
skipped_relations.add(ann["id"])
|
524 |
-
continue
|
525 |
-
unified_example["relations"].append(
|
526 |
-
{
|
527 |
-
"arg1_id": id_prefix + ann["head"]["ref_id"],
|
528 |
-
"arg2_id": id_prefix + ann["tail"]["ref_id"],
|
529 |
-
"id": id_prefix + ann["id"],
|
530 |
-
"type": ann["type"],
|
531 |
-
"normalized": [],
|
532 |
-
}
|
533 |
-
)
|
534 |
-
if len(skipped_relations) > 0:
|
535 |
-
example_id = brat_parse["document_id"]
|
536 |
-
logger.info(
|
537 |
-
f"Example:{example_id}: The `bigbio_kb` schema allows `relations` only between entities."
|
538 |
-
f" Skip (for now): "
|
539 |
-
f"{list(skipped_relations)}"
|
540 |
-
)
|
541 |
-
|
542 |
-
# get coreferences
|
543 |
-
unified_example["coreferences"] = []
|
544 |
-
for i, ann in enumerate(brat_parse["equivalences"], start=1):
|
545 |
-
is_entity_cluster = True
|
546 |
-
for ref_id in ann["ref_ids"]:
|
547 |
-
if not ref_id.startswith("T"): # not textbound -> no entity
|
548 |
-
is_entity_cluster = False
|
549 |
-
elif ref_id not in anno_ids: # event trigger -> no entity
|
550 |
-
is_entity_cluster = False
|
551 |
-
if is_entity_cluster:
|
552 |
-
entity_ids = [id_prefix + i for i in ann["ref_ids"]]
|
553 |
-
unified_example["coreferences"].append(
|
554 |
-
{"id": id_prefix + str(i), "entity_ids": entity_ids}
|
555 |
-
)
|
556 |
-
return unified_example
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
biomrc.py
DELETED
@@ -1,247 +0,0 @@
|
|
1 |
-
# coding=utf-8
|
2 |
-
# Copyright 2020 The TensorFlow Datasets Authors and the 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 |
-
"""
|
17 |
-
We introduce BIOMRC, a large-scale cloze-style biomedical MRC dataset. Care was taken to reduce noise, compared to the
|
18 |
-
previous BIOREAD dataset of Pappas et al. (2018). Experiments show that simple heuristics do not perform well on the
|
19 |
-
new dataset and that two neural MRC models that had been tested on BIOREAD perform much better on BIOMRC, indicating
|
20 |
-
that the new dataset is indeed less noisy or at least that its task is more feasible. Non-expert human performance is
|
21 |
-
also higher on the new dataset compared to BIOREAD, and biomedical experts perform even better. We also introduce a new
|
22 |
-
BERT-based MRC model, the best version of which substantially outperforms all other methods tested, reaching or
|
23 |
-
surpassing the accuracy of biomedical experts in some experiments. We make the new dataset available in three different
|
24 |
-
sizes, also releasing our code, and providing a leaderboard.
|
25 |
-
"""
|
26 |
-
|
27 |
-
import itertools as it
|
28 |
-
import json
|
29 |
-
|
30 |
-
import datasets
|
31 |
-
|
32 |
-
from .bigbiohub import qa_features
|
33 |
-
from .bigbiohub import BigBioConfig
|
34 |
-
from .bigbiohub import Tasks
|
35 |
-
|
36 |
-
_LANGUAGES = ["English"]
|
37 |
-
_PUBMED = True
|
38 |
-
_LOCAL = False
|
39 |
-
_CITATION = """\
|
40 |
-
@inproceedings{pappas-etal-2020-biomrc,
|
41 |
-
title = "{B}io{MRC}: A Dataset for Biomedical Machine Reading Comprehension",
|
42 |
-
author = "Pappas, Dimitris and
|
43 |
-
Stavropoulos, Petros and
|
44 |
-
Androutsopoulos, Ion and
|
45 |
-
McDonald, Ryan",
|
46 |
-
booktitle = "Proceedings of the 19th SIGBioMed Workshop on Biomedical Language Processing",
|
47 |
-
month = jul,
|
48 |
-
year = "2020",
|
49 |
-
address = "Online",
|
50 |
-
publisher = "Association for Computational Linguistics",
|
51 |
-
url = "https://www.aclweb.org/anthology/2020.bionlp-1.15",
|
52 |
-
pages = "140--149",
|
53 |
-
}
|
54 |
-
"""
|
55 |
-
|
56 |
-
_DATASETNAME = "biomrc"
|
57 |
-
_DISPLAYNAME = "BIOMRC"
|
58 |
-
|
59 |
-
_DESCRIPTION = """\
|
60 |
-
We introduce BIOMRC, a large-scale cloze-style biomedical MRC dataset. Care was taken to reduce noise, compared to the
|
61 |
-
previous BIOREAD dataset of Pappas et al. (2018). Experiments show that simple heuristics do not perform well on the
|
62 |
-
new dataset and that two neural MRC models that had been tested on BIOREAD perform much better on BIOMRC, indicating
|
63 |
-
that the new dataset is indeed less noisy or at least that its task is more feasible. Non-expert human performance is
|
64 |
-
also higher on the new dataset compared to BIOREAD, and biomedical experts perform even better. We also introduce a new
|
65 |
-
BERT-based MRC model, the best version of which substantially outperforms all other methods tested, reaching or
|
66 |
-
surpassing the accuracy of biomedical experts in some experiments. We make the new dataset available in three different
|
67 |
-
sizes, also releasing our code, and providing a leaderboard.
|
68 |
-
"""
|
69 |
-
|
70 |
-
_HOMEPAGE = "https://github.com/PetrosStav/BioMRC_code"
|
71 |
-
|
72 |
-
_LICENSE = "License information unavailable"
|
73 |
-
|
74 |
-
_BASE_URL = "https://huggingface.co/datasets/biomrc/resolve/main/data/"
|
75 |
-
_URLS = {
|
76 |
-
"large": {
|
77 |
-
"A": {
|
78 |
-
"train": _BASE_URL + "biomrc_large/dataset_train.jsonl.gz",
|
79 |
-
"val": _BASE_URL + "biomrc_large/dataset_val.jsonl.gz",
|
80 |
-
"test": _BASE_URL + "biomrc_large/dataset_test.jsonl.gz",
|
81 |
-
},
|
82 |
-
"B": {
|
83 |
-
"train": _BASE_URL + "biomrc_large/dataset_train_B.jsonl.gz",
|
84 |
-
"val": _BASE_URL + "biomrc_large/dataset_val_B.jsonl.gz",
|
85 |
-
"test": _BASE_URL + "biomrc_large/dataset_test_B.jsonl.gz",
|
86 |
-
},
|
87 |
-
},
|
88 |
-
"small": {
|
89 |
-
"A": {
|
90 |
-
"train": _BASE_URL + "biomrc_small/dataset_train_small.jsonl.gz",
|
91 |
-
"val": _BASE_URL + "biomrc_small/dataset_val_small.jsonl.gz",
|
92 |
-
"test": _BASE_URL + "biomrc_small/dataset_test_small.jsonl.gz",
|
93 |
-
},
|
94 |
-
"B": {
|
95 |
-
"train": _BASE_URL + "biomrc_small/dataset_train_small_B.jsonl.gz",
|
96 |
-
"val": _BASE_URL + "biomrc_small/dataset_val_small_B.jsonl.gz",
|
97 |
-
"test": _BASE_URL + "biomrc_small/dataset_test_small_B.jsonl.gz",
|
98 |
-
},
|
99 |
-
},
|
100 |
-
"tiny": {
|
101 |
-
"A": {"test": _BASE_URL + "biomrc_tiny/dataset_tiny.jsonl.gz"},
|
102 |
-
"B": {"test": _BASE_URL + "biomrc_tiny/dataset_tiny_B.jsonl.gz"},
|
103 |
-
},
|
104 |
-
}
|
105 |
-
|
106 |
-
_SUPPORTED_TASKS = [Tasks.QUESTION_ANSWERING]
|
107 |
-
|
108 |
-
_SOURCE_VERSION = "1.0.0"
|
109 |
-
|
110 |
-
_BIGBIO_VERSION = "1.0.0"
|
111 |
-
|
112 |
-
|
113 |
-
class BiomrcDataset(datasets.GeneratorBasedBuilder):
|
114 |
-
"""BioMRC: A Dataset for Biomedical Machine Reading Comprehension"""
|
115 |
-
|
116 |
-
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
117 |
-
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
118 |
-
|
119 |
-
BUILDER_CONFIGS = []
|
120 |
-
|
121 |
-
for biomrc_setting in ["A", "B"]:
|
122 |
-
for biomrc_version in ["large", "small", "tiny"]:
|
123 |
-
subset_id = f"biomrc_{biomrc_version}_{biomrc_setting}"
|
124 |
-
BUILDER_CONFIGS.append(
|
125 |
-
BigBioConfig(
|
126 |
-
name=f"{subset_id}_source",
|
127 |
-
version=SOURCE_VERSION,
|
128 |
-
description=f"BioMRC Version {biomrc_version} Setting {biomrc_setting} source schema",
|
129 |
-
schema="source",
|
130 |
-
subset_id=subset_id,
|
131 |
-
)
|
132 |
-
)
|
133 |
-
BUILDER_CONFIGS.append(
|
134 |
-
BigBioConfig(
|
135 |
-
name=f"{subset_id}_bigbio_qa",
|
136 |
-
version=BIGBIO_VERSION,
|
137 |
-
description=f"BioMRC Version {biomrc_version} Setting {biomrc_setting} BigBio schema",
|
138 |
-
schema="bigbio_qa",
|
139 |
-
subset_id=subset_id,
|
140 |
-
)
|
141 |
-
)
|
142 |
-
|
143 |
-
DEFAULT_CONFIG_NAME = "biomrc_large_B_source"
|
144 |
-
|
145 |
-
def _info(self):
|
146 |
-
if self.config.schema == "source":
|
147 |
-
features = datasets.Features(
|
148 |
-
{
|
149 |
-
"abstract": datasets.Value("string"),
|
150 |
-
"title": datasets.Value("string"),
|
151 |
-
"entities_list": datasets.features.Sequence(
|
152 |
-
{
|
153 |
-
"pseudoidentifier": datasets.Value("string"),
|
154 |
-
"identifier": datasets.Value("string"),
|
155 |
-
"synonyms": datasets.Value("string"),
|
156 |
-
}
|
157 |
-
),
|
158 |
-
"answer": {
|
159 |
-
"pseudoidentifier": datasets.Value("string"),
|
160 |
-
"identifier": datasets.Value("string"),
|
161 |
-
"synonyms": datasets.Value("string"),
|
162 |
-
},
|
163 |
-
}
|
164 |
-
)
|
165 |
-
elif self.config.schema == "bigbio_qa":
|
166 |
-
features = qa_features
|
167 |
-
else:
|
168 |
-
raise NotImplementedError()
|
169 |
-
|
170 |
-
return datasets.DatasetInfo(
|
171 |
-
description=_DESCRIPTION,
|
172 |
-
features=features,
|
173 |
-
homepage=_HOMEPAGE,
|
174 |
-
license=str(_LICENSE),
|
175 |
-
citation=_CITATION,
|
176 |
-
)
|
177 |
-
|
178 |
-
def _split_generators(self, dl_manager):
|
179 |
-
"""Returns SplitGenerators."""
|
180 |
-
|
181 |
-
_, version, setting = self.config.subset_id.split("_")
|
182 |
-
downloaded_files = dl_manager.download_and_extract(_URLS[version][setting])
|
183 |
-
|
184 |
-
if version == "tiny":
|
185 |
-
return [
|
186 |
-
datasets.SplitGenerator(
|
187 |
-
name=datasets.Split.TRAIN,
|
188 |
-
gen_kwargs={"filepath": downloaded_files["test"]},
|
189 |
-
),
|
190 |
-
]
|
191 |
-
else:
|
192 |
-
return [
|
193 |
-
datasets.SplitGenerator(
|
194 |
-
name=datasets.Split.TRAIN,
|
195 |
-
gen_kwargs={"filepath": downloaded_files["train"]},
|
196 |
-
),
|
197 |
-
datasets.SplitGenerator(
|
198 |
-
name=datasets.Split.VALIDATION,
|
199 |
-
gen_kwargs={"filepath": downloaded_files["val"]},
|
200 |
-
),
|
201 |
-
datasets.SplitGenerator(
|
202 |
-
name=datasets.Split.TEST,
|
203 |
-
gen_kwargs={"filepath": downloaded_files["test"]},
|
204 |
-
),
|
205 |
-
]
|
206 |
-
|
207 |
-
def _generate_examples(self, filepath):
|
208 |
-
"""Yields examples as (key, example) tuples."""
|
209 |
-
|
210 |
-
if self.config.schema == "source":
|
211 |
-
with open(filepath, encoding="utf-8") as fp:
|
212 |
-
for _id, line in enumerate(fp):
|
213 |
-
example = json.loads(line)
|
214 |
-
example["entities_list"] = [
|
215 |
-
self._parse_dict_from_entity(entity) for entity in example["entities_list"]
|
216 |
-
]
|
217 |
-
example["answer"] = self._parse_dict_from_entity(example["answer"])
|
218 |
-
yield _id, example
|
219 |
-
elif self.config.schema == "bigbio_qa":
|
220 |
-
with open(filepath, encoding="utf-8") as fp:
|
221 |
-
uid = it.count(0)
|
222 |
-
for _id, line in enumerate(fp):
|
223 |
-
example = json.loads(line)
|
224 |
-
# remove info such as code, label, synonyms from answer and choices
|
225 |
-
# f.e. @entity1 :: ('9606', 'Species') :: ['patients', 'patient']"
|
226 |
-
example = {
|
227 |
-
"id": next(uid),
|
228 |
-
"question_id": next(uid),
|
229 |
-
"document_id": next(uid),
|
230 |
-
"question": example["title"],
|
231 |
-
"type": "multiple_choice",
|
232 |
-
"choices": [x.split(" :: ")[0] for x in example["entities_list"]],
|
233 |
-
"context": example["abstract"],
|
234 |
-
"answer": [example["answer"].split(" :: ")[0]],
|
235 |
-
}
|
236 |
-
yield _id, example
|
237 |
-
|
238 |
-
def _parse_dict_from_entity(self, entity):
|
239 |
-
if "::" in entity:
|
240 |
-
pseudoidentifier, identifier, synonyms = entity.split(" :: ")
|
241 |
-
return {
|
242 |
-
"pseudoidentifier": pseudoidentifier,
|
243 |
-
"identifier": identifier,
|
244 |
-
"synonyms": synonyms,
|
245 |
-
}
|
246 |
-
else:
|
247 |
-
return {"pseudoidentifier": entity, "identifier": "", "synonyms": ""}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
biomrc_large_A_bigbio_qa/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7925fb0f19d5427c47fca5a3ba0399f5bee83a92a901ffead0476a802d063a47
|
3 |
+
size 46671647
|
biomrc_large_A_bigbio_qa/biomrc-train-00000-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:01359c06a1e82c788157239423957a92454632b387e3b88e71aee228c036d5f4
|
3 |
+
size 186592653
|
biomrc_large_A_bigbio_qa/biomrc-train-00001-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:399e41973e93025e6bb97a81eb09094c0bcb8ff2ef4edb21318c2fd8f26453c6
|
3 |
+
size 185137367
|
biomrc_large_A_bigbio_qa/biomrc-train-00002-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:34b3027fd4ade9954da43d1f5afe0584106c9ee65d14c92c391baf5d862836e3
|
3 |
+
size 147305997
|
biomrc_large_A_bigbio_qa/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:623b1ec251de9262b0777c1013d3cc984101cdc0ef1c11822e85b532f842cc83
|
3 |
+
size 37776173
|
biomrc_large_A_source/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b1caea21668666766836b4fe121ebaab2c5bcb0114f01feb926bd60613f6fb41
|
3 |
+
size 52044663
|
biomrc_large_A_source/biomrc-train-00000-of-00004.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d2f565f454e54fc38472dc8257a7bb8cb7bb9156e5b8888a96074b8d74e78547
|
3 |
+
size 175806309
|
biomrc_large_A_source/biomrc-train-00001-of-00004.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1b81324eda2eaded2824eb24b808c785103b5986e3453ac78bd993f6c2adf751
|
3 |
+
size 175184155
|
biomrc_large_A_source/biomrc-train-00002-of-00004.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dec1199776246b1b89e16454f3e42a6b43fc5cbb3c84731ab4d880c0da8cc36c
|
3 |
+
size 174311975
|
biomrc_large_A_source/biomrc-train-00003-of-00004.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ed686f80b58637ba924eb01908e7ad9019218c8d4982780d237a88a1ee64a15
|
3 |
+
size 53811094
|
biomrc_large_A_source/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c2f0050435aa683030b97b9a54d3e1d3481c4f9fe9ffbe083e0a797fd31c581e
|
3 |
+
size 42074649
|
biomrc_large_B_bigbio_qa/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31e0346ec052eeeffc76f7835eecbef19583b8d1e21fde763766ffaad83b9f3b
|
3 |
+
size 44621595
|
biomrc_large_B_bigbio_qa/biomrc-train-00000-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f9274904a18594fc6ba696f4edc4d218d2c16827cea31e07f079b1542c207465
|
3 |
+
size 183453315
|
biomrc_large_B_bigbio_qa/biomrc-train-00001-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e80a743a88d748ecee8fd2188f3e73bbe04f28359351cc317024e25aae3c61f
|
3 |
+
size 181824238
|
biomrc_large_B_bigbio_qa/biomrc-train-00002-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8437ee121b09157343fea9259ce743849b880a9378608265a0417ddd8e78301
|
3 |
+
size 130981389
|
biomrc_large_B_bigbio_qa/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:789591589eeecbc00510f51b1ca13fa923a5a59632893a2d0d5176c5866fe342
|
3 |
+
size 36140134
|
biomrc_large_B_source/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f06b5198ab1e5a5d6bc5983ec7138aa5d2f418e73d2a57895533f9cadc839114
|
3 |
+
size 43711636
|
biomrc_large_B_source/biomrc-train-00000-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b50522189d846eb85f3439c914afaaff24652f48472fc7a33249a6ec1eec0da7
|
3 |
+
size 177596282
|
biomrc_large_B_source/biomrc-train-00001-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a0bfa5b7153b689cc515eaa3e84b68f7d1e22b1845a7648aac993429b22dd495
|
3 |
+
size 176662312
|
biomrc_large_B_source/biomrc-train-00002-of-00003.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ac5755c24d9c8a6593334e4cfa77a72de83145290a5025d0361e85797f89b044
|
3 |
+
size 131836504
|
biomrc_large_B_source/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1c8137b8c316007e6b103712f84e07855f1d561562ba5f335d0941dc2da839bd
|
3 |
+
size 35415235
|
biomrc_small_A_bigbio_qa/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:407284b902c491480c678555b8f6a070ca9f82c7b70d0fa2bde4bb75f58c89d9
|
3 |
+
size 6624165
|
biomrc_small_A_bigbio_qa/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aa95cde7bfeca0d3df192cf30472780b7ac07896f27e44f7a660c95710f86224
|
3 |
+
size 91947743
|
biomrc_small_A_bigbio_qa/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f5624711c2721fbcfcf6ffb31fc5cf355c871fa685bb211ec1c353a1d40aaaec
|
3 |
+
size 6666279
|
biomrc_small_A_source/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0dae9a4761d3cf1cba6e928087e22aa9775b4158dd17b662ad304d921971b633
|
3 |
+
size 7352986
|
biomrc_small_A_source/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3895a7f015ad0b1705d7d7cf2ab3163fbd09d430379d715565c91c1a720c5efd
|
3 |
+
size 102143974
|
biomrc_small_A_source/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0139108f05b47450cbcdb97ee70878b0269cb97e457a84a32b93ae5345c35963
|
3 |
+
size 7395441
|
biomrc_small_B_bigbio_qa/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ff7bf33891500784e59a6707cafe10a61d6d83730f538ab6935ab7f7df0941b0
|
3 |
+
size 6338959
|
biomrc_small_B_bigbio_qa/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9a8b97cbbf283e6db9051b564e1d811e04ccd1ee4d6a08e4219c02453091a46d
|
3 |
+
size 88008416
|
biomrc_small_B_bigbio_qa/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3e6f0190075a552192ae389ebc5f3e90730672e038d00f5cec38407ea12c78e5
|
3 |
+
size 6387874
|
biomrc_small_B_source/biomrc-test.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c5adf4abc8158037e3f8623b59ec8743270821c4753b46a35af191ec234bf459
|
3 |
+
size 6249393
|
biomrc_small_B_source/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4cd47c5741289fda9d95bc137fb7191a23959377282e4a0d7f6b092b82198ba7
|
3 |
+
size 86745709
|
biomrc_small_B_source/biomrc-validation.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ea02d7582d4d89c8acb92615ad304e56b61570e8ba48808885122dd28d88eced
|
3 |
+
size 6298396
|
biomrc_tiny_A_bigbio_qa/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:23fa0b78e9e0756a293e174e45b92c8484316a52c758790965ec717c8b421e8f
|
3 |
+
size 46681
|
biomrc_tiny_A_source/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a475308bfb5e225e0af86b78b5ca29a2b226bcb9efd50f9682f1b4ac9a1939a1
|
3 |
+
size 53587
|
biomrc_tiny_B_bigbio_qa/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ff0caf43d2257e6c31b8e919cd401bad1c9fe61b9dcde84188a65362f3eeb04f
|
3 |
+
size 47569
|
biomrc_tiny_B_source/biomrc-train.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a23895fed47ee25e98cf6e0dcead1431533bf4b5e7d08d9059e13a73168ff9aa
|
3 |
+
size 47716
|