File size: 8,933 Bytes
09e1b57 |
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 |
# 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.
"""
Paragraph-level Simplification of Medical Texts ("MedParaSimp") is a
dataset that contains pairs of technical medical abstracts from
biomedical systematic reviews (taken from the Cochrane Library)
and their corresponding plain-language summarizations (PLS).
The PLS's were created by the authors of the original abstracts.
The dataset was obtained by scraping the Cochrane Library website.
"""
from typing import Dict, List, Tuple
import datasets
from .bigbiohub import BigBioConfig, Tasks, text2text_features
_LOCAL = False
_CITATION = """\
@inproceedings{devaraj-etal-2021-paragraph,
title = "Paragraph-level Simplification of Medical Texts",
author = "Devaraj, Ashwin and Marshall, Iain and Wallace, Byron and Li, Junyi Jessy",
booktitle = {Proceedings of the 2021 Conference of the North
American Chapter of the Association for Computational Linguistics},
month = jun,
year = "2021",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/2021.naacl-main.395",
pages = "4972--4984",
}
"""
_DATASETNAME = "medparasimp"
_DESCRIPTION = """\
This dataset is designed for the summarization NLP task. It is a
collection of technical abstracts of biomedical systematic reviews
and corresponding plain-language summaries (PLS) from the Cochrane
Database of Systematic Reviews, which comprises thousands of evidence
synopses (where authors provide an overview of all published evidence
relevant to a particular clinical question or topic). The PLS are
written by review authors; Cochrane’s PLS standards recommend that
“the PLS should be written in plain English which can be understood by
most readers without a university education”. PLS are not parallel with
every sentence in the abstract; on the contrary, they are structured heterogeneously.
"""
_HOMEPAGE = "https://github.com/AshOlogn/Paragraph-level-Simplification-of-Medical-Texts"
_LICENSE = "CC_BY_4p0"
_URLS = {
_DATASETNAME: {
"train_doi": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/train.doi"
),
"train_source": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/train.source"
),
"train_target": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/train.target"
),
"val_doi": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/val.doi"
),
"val_source": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/val.source"
),
"val_target": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/val.target"
),
"test_doi": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/test.doi"
),
"test_source": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/test.source"
),
"test_target": (
"https://raw.githubusercontent.com/AshOlogn/"
"Paragraph-level-Simplification-of-Medical-Texts/main/data/data-1024/test.target"
),
}
}
_SUPPORTED_TASKS = [Tasks.SUMMARIZATION]
_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"
_LANGUAGES = ["English (United States)"]
_PUBMED = False
_DISPLAYNAME = "Paragraph-Level Simplification of Medical Texts"
class MedParaSimpDataset(datasets.GeneratorBasedBuilder):
"""Paired abstracts and plain-language summaries from the Cochrane Database of Systematic Reviews."""
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
BUILDER_CONFIGS = [
BigBioConfig(
name="medparasimp_source",
version=SOURCE_VERSION,
description=(
"Paragraph-level Simplification of Medical Texts (MedParaSimp) is a"
"paired dataset of technical medical abstracts and their plain-language summarizations."
),
schema="source",
subset_id="medparasimp",
),
BigBioConfig(
name="medparasimp_bigbio_t2t",
version=BIGBIO_VERSION,
description=(
"Paragraph-level Simplification of Medical Texts (MedParaSimp) is a"
"paired dataset of technical medical abstracts and their plain-language summarizations."
),
schema="bigbio_t2t",
subset_id="medparasimp",
),
]
DEFAULT_CONFIG_NAME = "medparasimp_source"
def _info(self) -> datasets.DatasetInfo:
if self.config.schema == "source":
features = datasets.Features(
{
"id": datasets.Value("string"),
"document_id": datasets.Value("string"),
"text_1": datasets.Value("string"),
"text_2": datasets.Value("string"),
"text_1_name": datasets.Value("string"),
"text_2_name": datasets.Value("string"),
}
)
elif self.config.schema == "bigbio_t2t":
features = text2text_features
else:
raise ValueError(
f"Invalid config.schema specified ({self.config.schema}) - must be one of (source|bigbio_t2t)"
)
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=str(_LICENSE),
citation=_CITATION,
)
def _split_generators(self, dl_manager) -> List[datasets.SplitGenerator]:
"""Returns SplitGenerators."""
urls = _URLS[_DATASETNAME]
data_dir = dl_manager.download_and_extract(urls)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"doi_filepath": data_dir["train_doi"],
"source_filepath": data_dir["train_source"],
"target_filepath": data_dir["train_target"],
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"doi_filepath": data_dir["val_doi"],
"source_filepath": data_dir["val_source"],
"target_filepath": data_dir["val_target"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"doi_filepath": data_dir["test_doi"],
"source_filepath": data_dir["test_source"],
"target_filepath": data_dir["test_target"],
},
),
]
def _generate_examples(self, doi_filepath: str, source_filepath: str, target_filepath: str) -> Tuple[int, Dict]:
"""Yields examples as (key, example) tuples."""
# Read data from files
with open(doi_filepath, "r") as f:
dois: List[str] = f.read().splitlines()
with open(source_filepath, "r") as f:
sources: List[str] = f.read().splitlines()
with open(target_filepath, "r") as f:
targets: List[str] = f.read().splitlines()
for idx, (source, target) in enumerate(zip(sources, targets)):
key: int = idx
example: Dict = {
"id": str(idx),
"document_id": dois[idx],
"text_1": source,
"text_2": target,
"text_1_name": "abstract",
"text_2_name": "pls",
}
yield (key, example)
if __name__ == "__main__":
datasets.load_dataset(__file__)
|