File size: 9,426 Bytes
e3815e4 a379767 e3815e4 |
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# coding=utf-8
# Copyright 2022 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.
import json
from pathlib import Path
from typing import Dict, List, Tuple
import pandas as pd
import datasets
from .bigbiohub import kb_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks
_LOCAL = True
_CITATION = """\
@inproceedings{borchert-etal-2022-ggponc,
title = "{GGPONC} 2.0 - The {G}erman Clinical Guideline Corpus for Oncology: Curation Workflow, Annotation Policy, Baseline {NER} Taggers",
author = "Borchert, Florian and
Lohr, Christina and
Modersohn, Luise and
Witt, Jonas and
Langer, Thomas and
Follmann, Markus and
Gietzelt, Matthias and
Arnrich, Bert and
Hahn, Udo and
Schapranow, Matthieu-P.",
booktitle = "Proceedings of the Thirteenth Language Resources and Evaluation Conference",
month = jun,
year = "2022",
address = "Marseille, France",
publisher = "European Language Resources Association",
url = "https://aclanthology.org/2022.lrec-1.389",
pages = "3650--3660",
}
"""
_DATASETNAME = "ggponc2"
_DESCRIPTION = """\
The GGPONC project aims to provide a freely distributable corpus of German medical text for NLP researchers.
Clinical guidelines are particularly suitable to create such corpora, as they contain no protected health information
(PHI), which distinguishes them from other kinds of medical text.
The second version of the corpus (GGPONC 2.0) consists of 30 German oncology guidelines with 1.87 million tokens.
It has been completely manually annotated on the entity level by 7 medical students using the INCEpTION platform over a
time frame of 6 months in more than 1200 hours of work. This makes GGPONC 2.0 the largest annotated, freely
distributable corpus of German medical text at the moment.
Annotated entities are Findings (Diagnosis / Pathology, Other Finding), Substances (Clinical Drug, Nutrients / Body
Substances, External Substances) and Procedures (Therapeutic, Diagnostic), as well as Specifications for these entities.
In total, annotators have created more than 200000 entity annotations. In addition, fragment relationships have been
annotated to explicitly indicate elliptical coordinated noun phrases, a common phenomenon in German text."""
_HOMEPAGE = "https://www.leitlinienprogramm-onkologie.de/projekte/ggponc-english/"
_LANGUAGES = ['German']
_URLS = {}
_PUBMED = False
_SUPPORTED_TASKS = [Tasks.NAMED_ENTITY_RECOGNITION]
_SOURCE_VERSION = "2.0.0"
_BIGBIO_VERSION = "1.0.0"
_DISPLAYNAME = "GGPONC 2.0"
_DATASETNAME = "ggponc2"
_LICENSE = "DUA"
class Ggponc(datasets.GeneratorBasedBuilder):
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
DEFAULT_CONFIG_NAME = "ggponc2_fine_long_bigbio_kb"
BUILDER_CONFIGS = [
# source
BigBioConfig(
name="ggponc2_fine_long_source",
version=SOURCE_VERSION,
description="GGPONC 2.0 (fine grained categories and long spans) schema",
schema="source",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_fine_short_source",
version=SOURCE_VERSION,
description="GGPONC 2.0 (fine grained categories and short spans) schema",
schema="source",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_coarse_long_source",
version=SOURCE_VERSION,
description="GGPONC 2.0 (coarse categories and long spans) schema",
schema="source",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_coarse_short_source",
version=SOURCE_VERSION,
description="GGPONC 2.0 (coarse categories and short spans) schema",
schema="source",
subset_id="ggponc2",
),
# bigbio
BigBioConfig(
name="ggponc2_fine_long_bigbio_kb",
version=BIGBIO_VERSION,
description="GGPONC 2.0 (fine grained categories and long spans) schema",
schema="bigbio_kb",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_fine_short_bigbio_kb",
version=BIGBIO_VERSION,
description="GGPONC 2.0 (fine grained categories and short spans) schema",
schema="bigbio_kb",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_coarse_long_bigbio_kb",
version=BIGBIO_VERSION,
description="GGPONC 2.0 (coarse categories and long spans) schema",
schema="bigbio_kb",
subset_id="ggponc2",
),
BigBioConfig(
name="ggponc2_coarse_short_bigbio_kb",
version=BIGBIO_VERSION,
description="GGPONC 2.0 (coarse categories and short spans) schema",
schema="bigbio_kb",
subset_id="ggponc2",
),
]
def _info(self) -> datasets.DatasetInfo:
# return the same info for source and bigbio versions because `source == bigbio_kb`
features = kb_features
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
citation=_CITATION,
)
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
"""Returns SplitGenerators."""
if self.config.data_dir is None:
raise ValueError(
"This is a local dataset. Please pass the data_dir kwarg to load_dataset."
)
else:
data_dir = Path(self.config.data_dir)
split_dir = data_dir / "annotations/splits.csv"
dir_lookup = {
"ggponc2_fine_long_bigbio_kb": data_dir
/ "annotations/json/fine/long/all.json",
"ggponc2_fine_short_bigbio_kb": data_dir
/ "annotations/json/fine/short/all.json",
"ggponc2_coarse_long_bigbio_kb": data_dir
/ "annotations/json/coarse/long/all.json",
"ggponc2_coarse_short_bigbio_kb": data_dir
/ "annotations/json/coarse/short/all.json",
}
# return the same info for source and bigbio versions because `source == bigbio_kb`
data_dir = dir_lookup[self.config.name.replace('source', 'bigbio_kb')]
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"split": "train",
"filepath": data_dir,
"split_dir": split_dir,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"split": "test",
"filepath": data_dir,
"split_dir": split_dir,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"split": "dev",
"filepath": data_dir,
"split_dir": split_dir,
},
),
]
def _generate_examples(
self, filepath: str, split: str, split_dir: str
) -> Tuple[int, Dict]:
"""Yields examples as (key, example) tuples."""
splits = pd.read_csv(split_dir)
with open(filepath, encoding="utf8") as file:
data = json.load(file)
for uid, row in enumerate(data):
file_name = row["document_id"].replace("tsv", "txt")
file_split = splits.loc[splits["file"] == file_name]["split"].item()
if file_split == split:
out = {
"id": uid,
"document_id": row["document_id"],
"passages": [],
"entities": row["entities"],
}
for j, passage in enumerate(row["passages"]):
passage_id = passage["id"]
out["passages"].append(
{
"id": f"{uid}-{j}",
"type": passage["type"],
"text": [passage["text"]],
"offsets": passage["offsets"],
}
)
for i, _ in enumerate(out["entities"]):
out["entities"][i]["id"] = f"{uid}-{i}"
out["entities"][i]["normalized"] = []
out["events"] = []
out["coreferences"] = []
out["relations"] = []
yield uid, out
|