File size: 7,723 Bytes
601420d |
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 |
# 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.
from pathlib import Path
import datasets
from .bigbiohub import text_features
from .bigbiohub import BigBioConfig
from .bigbiohub import Tasks
_LANGUAGES = ['English']
_PUBMED = True
_LOCAL = False
_CITATION = """\
@article{DBLP:journals/bioinformatics/BakerSGAHSK16,
author = {Simon Baker and
Ilona Silins and
Yufan Guo and
Imran Ali and
Johan H{\"{o}}gberg and
Ulla Stenius and
Anna Korhonen},
title = {Automatic semantic classification of scientific literature
according to the hallmarks of cancer},
journal = {Bioinform.},
volume = {32},
number = {3},
pages = {432--440},
year = {2016},
url = {https://doi.org/10.1093/bioinformatics/btv585},
doi = {10.1093/bioinformatics/btv585},
timestamp = {Thu, 14 Oct 2021 08:57:44 +0200},
biburl = {https://dblp.org/rec/journals/bioinformatics/BakerSGAHSK16.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}
"""
_DATASETNAME = "hallmarks_of_cancer"
_DISPLAYNAME = "Hallmarks of Cancer"
_DESCRIPTION = """\
The Hallmarks of Cancer (HOC) Corpus consists of 1852 PubMed publication
abstracts manually annotated by experts according to a taxonomy. The taxonomy
consists of 37 classes in a hierarchy. Zero or more class labels are assigned
to each sentence in the corpus. The labels are found under the "labels"
directory, while the tokenized text can be found under "text" directory.
The filenames are the corresponding PubMed IDs (PMID).
"""
_HOMEPAGE = "https://github.com/sb895/Hallmarks-of-Cancer"
_LICENSE = 'GNU General Public License v3.0 only'
_URLs = {
"corpus": "https://github.com/sb895/Hallmarks-of-Cancer/archive/refs/heads/master.zip",
"split_indices": "https://microsoft.github.io/BLURB/sample_code/data_generation.tar.gz",
}
_SUPPORTED_TASKS = [Tasks.TEXT_CLASSIFICATION]
_SOURCE_VERSION = "1.0.0"
_BIGBIO_VERSION = "1.0.0"
_CLASS_NAMES = [
"evading growth suppressors",
"tumor promoting inflammation",
"enabling replicative immortality",
"cellular energetics",
"resisting cell death",
"activating invasion and metastasis",
"genomic instability and mutation",
"none",
"inducing angiogenesis",
"sustaining proliferative signaling",
"avoiding immune destruction",
]
class HallmarksOfCancerDataset(datasets.GeneratorBasedBuilder):
"""Hallmarks Of Cancer Dataset"""
SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
BIGBIO_VERSION = datasets.Version(_BIGBIO_VERSION)
BUILDER_CONFIGS = [
BigBioConfig(
name="hallmarks_of_cancer_source",
version=SOURCE_VERSION,
description="Hallmarks of Cancer source schema",
schema="source",
subset_id="hallmarks_of_cancer",
),
BigBioConfig(
name="hallmarks_of_cancer_bigbio_text",
version=BIGBIO_VERSION,
description="Hallmarks of Cancer Biomedical schema",
schema="bigbio_text",
subset_id="hallmarks_of_cancer",
),
]
DEFAULT_CONFIG_NAME = "hallmarks_of_cancer_source"
def _info(self):
if self.config.schema == "source":
features = datasets.Features(
{
"document_id": datasets.Value("string"),
"text": datasets.Value("string"),
"label": [datasets.ClassLabel(names=_CLASS_NAMES)],
}
)
elif self.config.schema == "bigbio_text":
features = text_features
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
supervised_keys=None,
homepage=_HOMEPAGE,
license=str(_LICENSE),
citation=_CITATION,
)
def _split_generators(self, dl_manager):
"""Returns SplitGenerators."""
data_dir = dl_manager.download_and_extract(_URLs)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"corpuspath": Path(data_dir["corpus"]),
"indicespath": Path(data_dir["split_indices"])
/ "data_generation/indexing/HoC/train_pmid.tsv",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"corpuspath": Path(data_dir["corpus"]),
"indicespath": Path(data_dir["split_indices"])
/ "data_generation/indexing/HoC/test_pmid.tsv",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"corpuspath": Path(data_dir["corpus"]),
"indicespath": Path(data_dir["split_indices"])
/ "data_generation/indexing/HoC/dev_pmid.tsv",
},
),
]
def _generate_examples(self, corpuspath: Path, indicespath: Path):
indices = indicespath.read_text(encoding="utf8").strip("\n").split(",")
dataset_dir = corpuspath / "Hallmarks-of-Cancer-master"
texts_dir = dataset_dir / "text"
labels_dir = dataset_dir / "labels"
uid = 1
for document_index, document in enumerate(indices):
text_file = texts_dir / document
label_file = labels_dir / document
text = text_file.read_text(encoding="utf8").strip("\n")
labels = label_file.read_text(encoding="utf8").strip("\n")
sentences = text.split("\n")
labels = labels.split("<")[1:]
for example_index, example_pair in enumerate(zip(sentences, labels)):
sentence, label = example_pair
label = label.strip()
if label == "":
label = "none"
multi_labels = [m_label.strip() for m_label in label.split("AND")]
unique_multi_labels = {
m_label.split("--")[0].lower().lstrip()
for m_label in multi_labels
if m_label != "NULL"
}
arrow_file_unique_key = 100 * document_index + example_index
if self.config.schema == "source":
yield arrow_file_unique_key, {
"document_id": f"{text_file.name.split('.')[0]}_{example_index}",
"text": sentence,
"label": list(unique_multi_labels),
}
elif self.config.schema == "bigbio_text":
yield arrow_file_unique_key, {
"id": uid,
"document_id": f"{text_file.name.split('.')[0]}_{example_index}",
"text": sentence,
"labels": list(unique_multi_labels),
}
uid += 1
|