Datasets:
Tasks:
Token Classification
Modalities:
Text
Formats:
parquet
Sub-tasks:
named-entity-recognition
Languages:
Spanish
Size:
1K - 10K
Tags:
relation-prediction
License:
File size: 7,310 Bytes
da652a3 a05a6d6 da652a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The eHealth-KD 2020 Corpus."""
import datasets
_CITATION = """\
@inproceedings{overview_ehealthkd2020,
author = {Piad{-}Morffis, Alejandro and
Guti{\'{e}}rrez, Yoan and
Cañizares-Diaz, Hian and
Estevez{-}Velarde, Suilan and
Almeida{-}Cruz, Yudivi{\'{a}}n and
Muñoz, Rafael and
Montoyo, Andr{\'{e}}s},
title = {Overview of the eHealth Knowledge Discovery Challenge at IberLEF 2020},
booktitle = ,
year = {2020},
}
"""
_DESCRIPTION = """\
Dataset of the eHealth Knowledge Discovery Challenge at IberLEF 2020. It is designed for
the identification of semantic entities and relations in Spanish health documents.
"""
_HOMEPAGE = "https://knowledge-learning.github.io/ehealthkd-2020/"
_LICENSE = "https://creativecommons.org/licenses/by-nc-sa/4.0/"
_URL = "https://raw.githubusercontent.com/knowledge-learning/ehealthkd-2020/master/data/"
_TRAIN_DIR = "training/"
_DEV_DIR = "development/main/"
_TEST_DIR = "testing/scenario3-taskB/"
_TEXT_FILE = "scenario.txt"
_ANNOTATIONS_FILE = "scenario.ann"
class EhealthKD(datasets.GeneratorBasedBuilder):
"""The eHealth-KD 2020 Corpus."""
VERSION = datasets.Version("1.1.0")
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="ehealth_kd", version=VERSION, description="eHealth-KD Corpus"),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"sentence": datasets.Value("string"),
"entities": [
{
"ent_id": datasets.Value("string"),
"ent_text": datasets.Value("string"),
"ent_label": datasets.ClassLabel(names=["Concept", "Action", "Predicate", "Reference"]),
"start_character": datasets.Value("int32"),
"end_character": datasets.Value("int32"),
}
],
"relations": [
{
"rel_id": datasets.Value("string"),
"rel_label": datasets.ClassLabel(
names=[
"is-a",
"same-as",
"has-property",
"part-of",
"causes",
"entails",
"in-time",
"in-place",
"in-context",
"subject",
"target",
"domain",
"arg",
]
),
"arg1": datasets.Value("string"),
"arg2": datasets.Value("string"),
}
],
}
),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
urls_to_download = {
k: [f"{_URL}{v}{_TEXT_FILE}", f"{_URL}{v}{_ANNOTATIONS_FILE}"]
for k, v in zip(["train", "dev", "test"], [_TRAIN_DIR, _DEV_DIR, _TEST_DIR])
}
downloaded_files = dl_manager.download_and_extract(urls_to_download)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={"txt_path": downloaded_files["train"][0], "ann_path": downloaded_files["train"][1]},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={"txt_path": downloaded_files["dev"][0], "ann_path": downloaded_files["dev"][1]},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={"txt_path": downloaded_files["test"][0], "ann_path": downloaded_files["test"][1]},
),
]
def _generate_examples(self, txt_path, ann_path):
"""Yields examples."""
with open(txt_path, encoding="utf-8") as txt_file, open(ann_path, encoding="utf-8") as ann_file:
_id = 0
entities = []
relations = []
annotations = ann_file.readlines()
last = annotations[-1]
# Create a variable to keep track of the last annotation (entity or relation) to know when a sentence is fully annotated
# In the annotations file, the entities are before the relations
last_annotation = ""
for annotation in annotations:
if annotation == last:
sentence = txt_file.readline().strip()
yield _id, {"sentence": sentence, "entities": entities, "relations": relations}
if annotation.startswith("T"):
if last_annotation == "relation":
sentence = txt_file.readline().strip()
yield _id, {"sentence": sentence, "entities": entities, "relations": relations}
_id += 1
entities = []
relations = []
ent_id, mid, ent_text = annotation.strip().split("\t")
ent_label, spans = mid.split(" ", 1)
start_character = spans.split(" ")[0]
end_character = spans.split(" ")[-1]
entities.append(
{
"ent_id": ent_id,
"ent_text": ent_text,
"ent_label": ent_label,
"start_character": start_character,
"end_character": end_character,
}
)
last_annotation = "entity"
else:
rel_id, rel_label, arg1, arg2 = annotation.strip().split()
if annotation.startswith("R"):
arg1 = arg1.split(":")[1]
arg2 = arg2.split(":")[1]
relations.append({"rel_id": rel_id, "rel_label": rel_label, "arg1": arg1, "arg2": arg2})
last_annotation = "relation"
|