HoC / HoC.py
qanastek's picture
Upload 5 files
bdc8e75
# coding=utf-8
"""HoC : Hallmarks of Cancer Corpus"""
import datasets
from pathlib import Path
logger = datasets.logging.get_logger(__name__)
_CITATION = """
@article{baker2015automatic,
title={Automatic semantic classification of scientific literature according to the hallmarks of cancer},
author={Baker, Simon and Silins, Ilona and Guo, Yufan and Ali, Imran and H{\"o}gberg, Johan and Stenius, Ulla and Korhonen, Anna},
journal={Bioinformatics},
volume={32},
number={3},
pages={432--440},
year={2015},
publisher={Oxford University Press}
}
@article{baker2017cancer,
title={Cancer Hallmarks Analytics Tool (CHAT): a text mining approach to organize and evaluate scientific literature on cancer},
author={Baker, Simon and Ali, Imran and Silins, Ilona and Pyysalo, Sampo and Guo, Yufan and H{\"o}gberg, Johan and Stenius, Ulla and Korhonen, Anna},
journal={Bioinformatics},
volume={33},
number={24},
pages={3973--3981},
year={2017},
publisher={Oxford University Press}
}
@article{baker2017cancer,
title={Cancer hallmark text classification using convolutional neural networks},
author={Baker, Simon and Korhonen, Anna-Leena and Pyysalo, Sampo},
year={2016}
}
@article{baker2017initializing,
title={Initializing neural networks for hierarchical multi-label text classification},
author={Baker, Simon and Korhonen, Anna},
journal={BioNLP 2017},
pages={307--315},
year={2017}
}
"""
_LICENSE = """
GNU General Public License v3.0
"""
_DESCRIPTION = """
The Hallmarks of Cancer Corpus for text classification
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).
In addition to the HOC corpus, we also have the
[Cancer Hallmarks Analytics Tool](http://chat.lionproject.net/)
which classifes all of PubMed according to the HoC taxonomy.
"""
_HOMEPAGE = "https://github.com/sb895/Hallmarks-of-Cancer"
_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",
}
_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 HoC(datasets.GeneratorBasedBuilder):
"""HoC : Hallmarks of Cancer Corpus"""
BUILDER_CONFIGS = [
datasets.BuilderConfig(
name = "HoC",
version = datasets.Version("1.0.0"),
description = f"The HoC corpora",
)
]
DEFAULT_CONFIG_NAME = "HoC"
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features(
{
"document_id": datasets.Value("string"),
"text": datasets.Value("string"),
"label": [datasets.ClassLabel(names=_CLASS_NAMES)],
},
),
supervised_keys=None,
homepage=_HOMEPAGE,
citation=_CITATION,
license=_LICENSE,
)
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={
"corpus_path": Path(data_dir["corpus"]),
"indices_path": Path(data_dir["split_indices"]) / "data_generation/indexing/HoC/train_pmid.tsv",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"corpus_path": Path(data_dir["corpus"]),
"indices_path": Path(data_dir["split_indices"]) / "data_generation/indexing/HoC/dev_pmid.tsv",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"corpus_path": Path(data_dir["corpus"]),
"indices_path": Path(data_dir["split_indices"]) / "data_generation/indexing/HoC/test_pmid.tsv",
},
),
]
def _generate_examples(self, corpus_path: Path, indices_path: Path):
indices = indices_path.read_text(encoding="utf8").strip("\n").split(",")
dataset_dir = corpus_path / "Hallmarks-of-Cancer-master"
texts_dir = dataset_dir / "text"
labels_dir = dataset_dir / "labels"
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"}
unique_key = 100 * document_index + example_index
yield unique_key, {
"document_id": f"{text_file.name.split('.')[0]}_{example_index}",
"text": sentence,
"label": list(unique_multi_labels),
}