Commit ·
3c7e054
1
Parent(s): f00603c
Update parquet files
Browse files- .gitattributes +0 -54
- bigbiohub.py +0 -556
- lll.py +0 -329
- lll_bigbio_kb/lll-test.parquet +3 -0
- lll_bigbio_kb/lll-train.parquet +3 -0
- lll_source/lll-test.parquet +3 -0
- lll_source/lll-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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ott, github: nomisto
|
| 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 |
-
The LLL05 challenge task is to learn rules to extract protein/gene interactions from biology abstracts from the Medline
|
| 18 |
-
bibliography database. The goal of the challenge is to test the ability of the participating IE systems to identify the
|
| 19 |
-
interactions and the gene/proteins that interact. The participants will test their IE patterns on a test set with the
|
| 20 |
-
aim of extracting the correct agent and target.The challenge focuses on information extraction of gene interactions in
|
| 21 |
-
Bacillus subtilis. Extracting gene interaction is the most popular event IE task in biology. Bacillus subtilis (Bs) is
|
| 22 |
-
a model bacterium and many papers have been published on direct gene interactions involved in sporulation. The gene
|
| 23 |
-
interactions are generally mentioned in the abstract and the full text of the paper is not needed. Extracting gene
|
| 24 |
-
interaction means, extracting the agent (proteins) and the target (genes) of all couples of genic interactions from
|
| 25 |
-
sentences.
|
| 26 |
-
"""
|
| 27 |
-
|
| 28 |
-
# NOTE:
|
| 29 |
-
# word stop offsets are increased by one to be consistent with python slicing.
|
| 30 |
-
# test set does not include entity relation information
|
| 31 |
-
|
| 32 |
-
import itertools as it
|
| 33 |
-
from typing import List
|
| 34 |
-
|
| 35 |
-
import datasets
|
| 36 |
-
|
| 37 |
-
from .bigbiohub import kb_features
|
| 38 |
-
from .bigbiohub import BigBioConfig
|
| 39 |
-
from .bigbiohub import Tasks
|
| 40 |
-
from .bigbiohub import BigBioValues
|
| 41 |
-
|
| 42 |
-
_LANGUAGES = ['English']
|
| 43 |
-
_PUBMED = True
|
| 44 |
-
_LOCAL = False
|
| 45 |
-
_CITATION = """\
|
| 46 |
-
@article{article,
|
| 47 |
-
author = {Nédellec, C.},
|
| 48 |
-
year = {2005},
|
| 49 |
-
month = {01},
|
| 50 |
-
pages = {},
|
| 51 |
-
title = {Learning Language in Logic - Genic Interaction Extraction Challenge},
|
| 52 |
-
journal = {Proceedings of the Learning Language in Logic 2005 Workshop at the \
|
| 53 |
-
International Conference on Machine Learning}
|
| 54 |
-
}
|
| 55 |
-
"""
|
| 56 |
-
|
| 57 |
-
_DATASETNAME = "lll"
|
| 58 |
-
_DISPLAYNAME = "LLL05"
|
| 59 |
-
|
| 60 |
-
_DESCRIPTION = """\
|
| 61 |
-
The LLL05 challenge task is to learn rules to extract protein/gene interactions from biology abstracts from the Medline
|
| 62 |
-
bibliography database. The goal of the challenge is to test the ability of the participating IE systems to identify the
|
| 63 |
-
interactions and the gene/proteins that interact. The participants will test their IE patterns on a test set with the
|
| 64 |
-
aim of extracting the correct agent and target.The challenge focuses on information extraction of gene interactions in
|
| 65 |
-
Bacillus subtilis. Extracting gene interaction is the most popular event IE task in biology. Bacillus subtilis (Bs) is
|
| 66 |
-
a model bacterium and many papers have been published on direct gene interactions involved in sporulation. The gene
|
| 67 |
-
interactions are generally mentioned in the abstract and the full text of the paper is not needed. Extracting gene
|
| 68 |
-
interaction means, extracting the agent (proteins) and the target (genes) of all couples of genic interactions from
|
| 69 |
-
sentences.
|
| 70 |
-
"""
|
| 71 |
-
|
| 72 |
-
_HOMEPAGE = "http://genome.jouy.inra.fr/texte/LLLchallenge"
|
| 73 |
-
|
| 74 |
-
_LICENSE = 'License information unavailable'
|
| 75 |
-
|
| 76 |
-
_URLS = {
|
| 77 |
-
_DATASETNAME: [
|
| 78 |
-
"http://genome.jouy.inra.fr/texte/LLLchallenge/data/LLLChalenge05/data/train/task2/genic_interaction_linguistic_data.txt", # noqa
|
| 79 |
-
"http://genome.jouy.inra.fr/texte/LLLchallenge/data/LLLChalenge05/data/train/task2/genic_interaction_linguistic_data_coref.txt", # noqa
|
| 80 |
-
"http://genome.jouy.inra.fr/texte/LLLchallenge/data/LLLChalenge05/data/test/task2/enriched_test_data.txt", # noqa
|
| 81 |
-
]
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
_SUPPORTED_TASKS = [Tasks.RELATION_EXTRACTION]
|
| 85 |
-
|
| 86 |
-
_SOURCE_VERSION = "1.0.0"
|
| 87 |
-
|
| 88 |
-
_BIGBIO_VERSION = "1.0.0"
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
class LLLDataset(datasets.GeneratorBasedBuilder):
|
| 92 |
-
"""LLL dataset for gene interaction extraction (RE)"""
|
| 93 |
-
|
| 94 |
-
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
|
| 95 |
-
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
|
| 96 |
-
|
| 97 |
-
BUILDER_CONFIGS = [
|
| 98 |
-
BigBioConfig(
|
| 99 |
-
name="lll_source",
|
| 100 |
-
version=SOURCE_VERSION,
|
| 101 |
-
description="LLL source schema",
|
| 102 |
-
schema="source",
|
| 103 |
-
subset_id="lll",
|
| 104 |
-
),
|
| 105 |
-
BigBioConfig(
|
| 106 |
-
name="lll_bigbio_kb",
|
| 107 |
-
version=BIGBIO_VERSION,
|
| 108 |
-
description="LLL BigBio schema",
|
| 109 |
-
schema="bigbio_kb",
|
| 110 |
-
subset_id="lll",
|
| 111 |
-
),
|
| 112 |
-
]
|
| 113 |
-
|
| 114 |
-
DEFAULT_CONFIG_NAME = "lll_source"
|
| 115 |
-
|
| 116 |
-
def _info(self) -> datasets.DatasetInfo:
|
| 117 |
-
|
| 118 |
-
if self.config.schema == "source":
|
| 119 |
-
features = datasets.Features(
|
| 120 |
-
{
|
| 121 |
-
"id": datasets.Value("string"),
|
| 122 |
-
"sentence": datasets.Value("string"),
|
| 123 |
-
"words": [
|
| 124 |
-
{
|
| 125 |
-
"id": datasets.Value("string"),
|
| 126 |
-
"text": datasets.Value("string"),
|
| 127 |
-
"offsets": datasets.Sequence(datasets.Value("int32")),
|
| 128 |
-
}
|
| 129 |
-
],
|
| 130 |
-
"genic_interactions": [
|
| 131 |
-
{
|
| 132 |
-
"ref_id1": datasets.Value("string"),
|
| 133 |
-
"ref_id2": datasets.Value("string"),
|
| 134 |
-
}
|
| 135 |
-
],
|
| 136 |
-
"agents": [
|
| 137 |
-
{
|
| 138 |
-
"ref_id": datasets.Value("string"),
|
| 139 |
-
}
|
| 140 |
-
],
|
| 141 |
-
"targets": [
|
| 142 |
-
{
|
| 143 |
-
"ref_id": datasets.Value("string"),
|
| 144 |
-
}
|
| 145 |
-
],
|
| 146 |
-
"lemmas": [
|
| 147 |
-
{
|
| 148 |
-
"ref_id": datasets.Value("string"),
|
| 149 |
-
"lemma": datasets.Value("string"),
|
| 150 |
-
}
|
| 151 |
-
],
|
| 152 |
-
"syntactic_relations": [
|
| 153 |
-
{
|
| 154 |
-
"type": datasets.Value("string"),
|
| 155 |
-
"ref_id1": datasets.Value("string"),
|
| 156 |
-
"ref_id2": datasets.Value("string"),
|
| 157 |
-
}
|
| 158 |
-
],
|
| 159 |
-
}
|
| 160 |
-
)
|
| 161 |
-
|
| 162 |
-
elif self.config.schema == "bigbio_kb":
|
| 163 |
-
features = kb_features
|
| 164 |
-
|
| 165 |
-
return datasets.DatasetInfo(
|
| 166 |
-
description=_DESCRIPTION,
|
| 167 |
-
features=features,
|
| 168 |
-
homepage=_HOMEPAGE,
|
| 169 |
-
license=str(_LICENSE),
|
| 170 |
-
citation=_CITATION,
|
| 171 |
-
)
|
| 172 |
-
|
| 173 |
-
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
|
| 174 |
-
|
| 175 |
-
urls = _URLS[_DATASETNAME]
|
| 176 |
-
train_path, train_coref_path, test_path = dl_manager.download_and_extract(urls)
|
| 177 |
-
|
| 178 |
-
return [
|
| 179 |
-
datasets.SplitGenerator(
|
| 180 |
-
name=datasets.Split.TRAIN,
|
| 181 |
-
gen_kwargs={
|
| 182 |
-
"data_paths": [train_path, train_coref_path],
|
| 183 |
-
"split": "train",
|
| 184 |
-
},
|
| 185 |
-
),
|
| 186 |
-
datasets.SplitGenerator(
|
| 187 |
-
name=datasets.Split.TEST,
|
| 188 |
-
gen_kwargs={"data_paths": [test_path], "split": "test"},
|
| 189 |
-
),
|
| 190 |
-
]
|
| 191 |
-
|
| 192 |
-
def _generate_examples(self, data_paths, split):
|
| 193 |
-
|
| 194 |
-
if self.config.schema == "source":
|
| 195 |
-
for path in data_paths:
|
| 196 |
-
with open(path, encoding="utf8") as documents:
|
| 197 |
-
for document in self._generate_parsed_documents(documents, split):
|
| 198 |
-
yield document["id"], document
|
| 199 |
-
|
| 200 |
-
elif self.config.schema == "bigbio_kb":
|
| 201 |
-
uid = it.count(0)
|
| 202 |
-
for path in data_paths:
|
| 203 |
-
with open(path, encoding="utf8") as documents:
|
| 204 |
-
for document in self._generate_parsed_documents(documents, split):
|
| 205 |
-
document_ = {}
|
| 206 |
-
document_["id"] = next(uid)
|
| 207 |
-
document_["document_id"] = document["id"]
|
| 208 |
-
|
| 209 |
-
document_["passages"] = [
|
| 210 |
-
{
|
| 211 |
-
"id": next(uid),
|
| 212 |
-
"type": BigBioValues.NULL,
|
| 213 |
-
"text": [document["sentence"]],
|
| 214 |
-
"offsets": [[0, len(document["sentence"])]],
|
| 215 |
-
}
|
| 216 |
-
]
|
| 217 |
-
|
| 218 |
-
id_to_word = {i["id"]: i for i in document["words"]}
|
| 219 |
-
document_["entities"] = []
|
| 220 |
-
for agent in document["agents"]:
|
| 221 |
-
word = id_to_word[agent["ref_id"]]
|
| 222 |
-
document_["entities"].append(
|
| 223 |
-
{
|
| 224 |
-
"id": f"{document_['id']}-agent-{word['id']}",
|
| 225 |
-
"type": "agent",
|
| 226 |
-
"text": [word["text"]],
|
| 227 |
-
"offsets": [
|
| 228 |
-
[word["offsets"][0], word["offsets"][1]]
|
| 229 |
-
],
|
| 230 |
-
"normalized": [],
|
| 231 |
-
}
|
| 232 |
-
)
|
| 233 |
-
for agent in document["targets"]:
|
| 234 |
-
word = id_to_word[agent["ref_id"]]
|
| 235 |
-
document_["entities"].append(
|
| 236 |
-
{
|
| 237 |
-
"id": f"{document_['id']}-target-{word['id']}",
|
| 238 |
-
"type": "target",
|
| 239 |
-
"text": [word["text"]],
|
| 240 |
-
"offsets": [
|
| 241 |
-
[word["offsets"][0], word["offsets"][1]]
|
| 242 |
-
],
|
| 243 |
-
"normalized": [],
|
| 244 |
-
}
|
| 245 |
-
)
|
| 246 |
-
|
| 247 |
-
document_["relations"] = [
|
| 248 |
-
{
|
| 249 |
-
"id": next(uid),
|
| 250 |
-
"type": "genic_interaction",
|
| 251 |
-
"arg1_id": f"{document_['id']}-agent-{relation['ref_id1']}",
|
| 252 |
-
"arg2_id": f"{document_['id']}-target-{relation['ref_id2']}",
|
| 253 |
-
"normalized": [],
|
| 254 |
-
}
|
| 255 |
-
for relation in document["genic_interactions"]
|
| 256 |
-
]
|
| 257 |
-
|
| 258 |
-
document_["events"] = []
|
| 259 |
-
document_["coreferences"] = []
|
| 260 |
-
yield document_["document_id"], document_
|
| 261 |
-
|
| 262 |
-
def _generate_parsed_documents(self, fstream, split):
|
| 263 |
-
for raw_document in self._generate_raw_documents(fstream):
|
| 264 |
-
yield self._parse_document(raw_document, split)
|
| 265 |
-
|
| 266 |
-
def _generate_raw_documents(self, fstream):
|
| 267 |
-
raw_document = []
|
| 268 |
-
for line in fstream:
|
| 269 |
-
if "%" in line:
|
| 270 |
-
continue
|
| 271 |
-
elif line.strip():
|
| 272 |
-
raw_document.append(line.strip())
|
| 273 |
-
elif raw_document:
|
| 274 |
-
if raw_document:
|
| 275 |
-
yield raw_document
|
| 276 |
-
raw_document = []
|
| 277 |
-
# needed for last document
|
| 278 |
-
if raw_document:
|
| 279 |
-
yield raw_document
|
| 280 |
-
|
| 281 |
-
def _parse_document(self, raw_document, split):
|
| 282 |
-
document = {}
|
| 283 |
-
for line in raw_document:
|
| 284 |
-
key, value = line.split("\t", 1)
|
| 285 |
-
if key in ["ID", "sentence"]:
|
| 286 |
-
document[key.lower()] = value
|
| 287 |
-
elif key in [
|
| 288 |
-
"words",
|
| 289 |
-
"genic_interactions",
|
| 290 |
-
"agents",
|
| 291 |
-
"targets",
|
| 292 |
-
"lemmas",
|
| 293 |
-
"syntactic_relations",
|
| 294 |
-
]:
|
| 295 |
-
document[key.lower()] = self._parse_elements(value, key)
|
| 296 |
-
else:
|
| 297 |
-
raise NotImplementedError()
|
| 298 |
-
|
| 299 |
-
# Needed as testset does not contain agents, targets and genic_interactions (dataset was part of a challenge)
|
| 300 |
-
if split == "test":
|
| 301 |
-
document.setdefault("genic_interactions", [])
|
| 302 |
-
document.setdefault("agents", [])
|
| 303 |
-
document.setdefault("targets", [])
|
| 304 |
-
|
| 305 |
-
return document
|
| 306 |
-
|
| 307 |
-
def _parse_elements(self, values, type):
|
| 308 |
-
return [self._parse_element(atom, type) for atom in values.split("\t")]
|
| 309 |
-
|
| 310 |
-
def _parse_element(self, atom, type):
|
| 311 |
-
# Sorry for that abomination, parses the arguments from atoms like rel(arg1, ..., argn)
|
| 312 |
-
args = atom.split("(", 1)[1][:-1].split(",")
|
| 313 |
-
if type == "words":
|
| 314 |
-
# fix offsets for python slicing
|
| 315 |
-
return {
|
| 316 |
-
"id": args[0],
|
| 317 |
-
"text": args[1].strip("'"),
|
| 318 |
-
"offsets": [int(args[2]), int(args[3]) + 1],
|
| 319 |
-
}
|
| 320 |
-
elif type == "genic_interactions":
|
| 321 |
-
return {"ref_id1": args[0], "ref_id2": args[1]}
|
| 322 |
-
elif type == "agents":
|
| 323 |
-
return {"ref_id": args[0]}
|
| 324 |
-
elif type == "targets":
|
| 325 |
-
return {"ref_id": args[0]}
|
| 326 |
-
elif type == "lemmas":
|
| 327 |
-
return {"ref_id": args[0], "lemma": args[1].strip("'")}
|
| 328 |
-
elif type == "syntact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-test.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:83eaa96f4e351790844140b2e5cc4b06d14c4ff72c29114b9f19db55e75602db
|
| 3 |
+
size 25475
|
lll_bigbio_kb/lll-train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1f596dac87617c685cf1c8589e497edfb7847041188c71e660fe8c8ba433021
|
| 3 |
+
size 32879
|
lll_source/lll-test.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:394cff96a504bb6c0abaa94f6a8a3f35ee9b129fde5256aacd34c4a0ee6828f7
|
| 3 |
+
size 42479
|
lll_source/lll-train.parquet
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2b08d0f86edfe2017ec269b2b40865540aa1d2ecdf600bdb6c51fa2c4ca92574
|
| 3 |
+
size 45988
|