|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Dataset for TLDR: Extreme Summarization of Scientific Documents""" |
|
|
|
|
|
import json |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
_SOURCE = "source" |
|
_TARGET = "target" |
|
|
|
_CITATION = """\ |
|
@article{cachola2020tldr, |
|
title={{TLDR}: Extreme Summarization of Scientific Documents}, |
|
author={Isabel Cachola and Kyle Lo and Arman Cohan and Daniel S. Weld}, |
|
journal={arXiv:2004.15011}, |
|
year={2020}, |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """\ |
|
A new multi-target dataset of 5.4K TLDRs over 3.2K papers. |
|
SCITLDR contains both author-written and expert-derived TLDRs, |
|
where the latter are collected using a novel annotation protocol |
|
that produces high-quality summaries while minimizing annotation burden. |
|
""" |
|
|
|
|
|
_LICENSE = "Apache License 2.0" |
|
|
|
|
|
|
|
|
|
_URLs = { |
|
"Abstract": "https://raw.githubusercontent.com/allenai/scitldr/master/SciTLDR-Data/SciTLDR-A/", |
|
"AIC": "https://raw.githubusercontent.com/allenai/scitldr/master/SciTLDR-Data/SciTLDR-AIC/", |
|
"FullText": "https://raw.githubusercontent.com/allenai/scitldr/master/SciTLDR-Data/SciTLDR-FullText/", |
|
} |
|
|
|
_TRAIN_DATA = "train.jsonl" |
|
_TEST_DATA = "test.jsonl" |
|
_VALID_DATA = "dev.jsonl" |
|
|
|
|
|
|
|
class Scitldr(datasets.GeneratorBasedBuilder): |
|
"""Dataset for TLDR: Extreme Summarization of Scientific Documents.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="Abstract", description="This part contains only abstracts of the paper"), |
|
datasets.BuilderConfig( |
|
name="AIC", |
|
description="This part contains Abstracts, Introduction and Conclusion (AIC) sections of the paper", |
|
), |
|
datasets.BuilderConfig(name="FullText", description="This part contains the full text of the paper"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = ( |
|
"Abstract" |
|
) |
|
|
|
def _info(self): |
|
if self.config.name == "AIC": |
|
features = datasets.Features( |
|
{ |
|
"source": datasets.Sequence(datasets.Value("string")), |
|
"source_labels": datasets.Sequence(datasets.ClassLabel(num_classes=2, names=[0, 1])), |
|
"rouge_scores": datasets.Sequence(datasets.Value("float32")), |
|
"paper_id": datasets.Value("string"), |
|
"ic": datasets.Value("bool_"), |
|
"target": datasets.features.Sequence(datasets.Value("string")) |
|
|
|
} |
|
) |
|
else: |
|
features = datasets.Features( |
|
{ |
|
"source": datasets.Sequence(datasets.Value("string")), |
|
"source_labels": datasets.Sequence( |
|
datasets.ClassLabel(num_classes=2, names=["non-oracle", "oracle"]) |
|
), |
|
"rouge_scores": datasets.Sequence(datasets.Value("float32")), |
|
"paper_id": datasets.Value("string"), |
|
"target": datasets.Sequence(datasets.Value("string")) |
|
|
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
supervised_keys=(_SOURCE, _TARGET), |
|
|
|
homepage="https://github.com/allenai/scitldr", |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
urls = { |
|
"train": _URLs[self.config.name] + _TRAIN_DATA, |
|
"valid": _URLs[self.config.name] + _VALID_DATA, |
|
"test": _URLs[self.config.name] + _TEST_DATA, |
|
} |
|
data_dir = dl_manager.download(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": os.path.join(data_dir["train"])}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": os.path.join(data_dir["test"])}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
gen_kwargs={"filepath": os.path.join(data_dir["valid"])}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath): |
|
"""Yields examples.""" |
|
with open(filepath, encoding="utf-8") as f: |
|
for id_, row in enumerate(f): |
|
data = json.loads(row) |
|
if self.config.name == "AIC": |
|
yield id_, { |
|
"source": data["source"], |
|
"source_labels": data["source_labels"], |
|
"rouge_scores": data["rouge_scores"], |
|
"paper_id": data["paper_id"], |
|
"ic": True if data["ic"] else False, |
|
"target": data["target"], |
|
} |
|
else: |
|
yield id_, { |
|
"source": data["source"], |
|
"source_labels": data["source_labels"], |
|
"rouge_scores": data["rouge_scores"], |
|
"paper_id": data["paper_id"], |
|
"target": data["target"], |
|
} |
|
|