scrolls / scrolls.py
eladsegal's picture
Update scrolls.py
d54363f
raw history blame
No virus
15.2 kB
# coding=utf-8
# TODO License
# Lint as: python3
"""The Scrolls benchmark."""
import json
import os
import datasets
_SCROLLS_CITATION = """
@article{ TODO citation here
}
Note that each Scrolls dataset has its own citation. Please see the source to
get the correct citation for each contained dataset.
"""
_SCROLLS_DESCRIPTION = """
Scrolls (https://TODO.com/) is a benchmark of generative tasks that require processing long texts.
"""
_SUMM_SCREEN_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_QASPER_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_QMSUM_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_NARRATIVE_QA_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_GOV_REPORT_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_CONTRACT_NLI_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_QUALITY_DESCRIPTION = """
SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
show episode, given the full script."""
_SUMM_SCREEN_CITATION = r"""
@misc{chen2021summscreen,
title={SummScreen: A Dataset for Abstractive Screenplay Summarization},
author={Mingda Chen and Zewei Chu and Sam Wiseman and Kevin Gimpel},
year={2021},
eprint={2104.07091},
archivePrefix={arXiv},
primaryClass={cs.CL}
}"""
_QASPER_CITATION = r"""
@inproceedings{dasigi-etal-2021-dataset,
title = "A Dataset of Information-Seeking Questions and Answers Anchored in Research Papers",
author = "Dasigi, Pradeep and
Lo, Kyle and
Beltagy, Iz and
Cohan, Arman and
Smith, Noah A. and
Gardner, Matt",
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
month = jun,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.365",
doi = "10.18653/v1/2021.naacl-main.365",
pages = "4599--4610",
abstract = "Readers of academic research papers often read with the goal of answering specific questions. Question Answering systems that can answer those questions can make consumption of the content much more efficient. However, building such tools requires data that reflect the difficulty of the task arising from complex reasoning about claims made in multiple parts of a paper. In contrast, existing information-seeking question answering datasets usually contain questions about generic factoid-type information. We therefore present Qasper, a dataset of 5049 questions over 1585 Natural Language Processing papers. Each question is written by an NLP practitioner who read only the title and abstract of the corresponding paper, and the question seeks information present in the full text. The questions are then answered by a separate set of NLP practitioners who also provide supporting evidence to answers. We find that existing models that do well on other QA tasks do not perform well on answering these questions, underperforming humans by at least 27 F1 points when answering them from entire papers, motivating further research in document-grounded, information-seeking QA, which our dataset is designed to facilitate.",
}"""
_QMSUM_CITATION = r"""@inproceedings{zhong-etal-2021-qmsum,
title = "{QMS}um: A New Benchmark for Query-based Multi-domain Meeting Summarization",
author = "Zhong, Ming and
Yin, Da and
Yu, Tao and
Zaidi, Ahmad and
Mutuma, Mutethia and
Jha, Rahul and
Awadallah, Ahmed Hassan and
Celikyilmaz, Asli and
Liu, Yang and
Qiu, Xipeng and
Radev, Dragomir",
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
month = jun,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.472",
doi = "10.18653/v1/2021.naacl-main.472",
pages = "5905--5921",
abstract = "Meetings are a key component of human collaboration. As increasing numbers of meetings are recorded and transcribed, meeting summaries have become essential to remind those who may or may not have attended the meetings about the key decisions made and the tasks to be completed. However, it is hard to create a single short summary that covers all the content of a long meeting involving multiple people and topics. In order to satisfy the needs of different types of users, we define a new query-based multi-domain meeting summarization task, where models have to select and summarize relevant spans of meetings in response to a query, and we introduce QMSum, a new benchmark for this task. QMSum consists of 1,808 query-summary pairs over 232 meetings in multiple domains. Besides, we investigate a locate-then-summarize method and evaluate a set of strong summarization baselines on the task. Experimental results and manual analysis reveal that QMSum presents significant challenges in long meeting summarization for future research. Dataset is available at \url{https://github.com/Yale-LILY/QMSum}.",
}"""
_NARRATIVE_QA_CITATION = r"""
@article{kovcisky2018narrativeqa,
title={The narrativeqa reading comprehension challenge},
author={Ko{\v{c}}isk{\'y}, Tom{\'a}{\v{s}} and Schwarz, Jonathan and Blunsom, Phil and Dyer, Chris and Hermann, Karl Moritz and Melis, G{\'a}bor and Grefenstette, Edward},
journal={Transactions of the Association for Computational Linguistics},
volume={6},
pages={317--328},
year={2018},
publisher={MIT Press}
}"""
_GOV_REPORT_CITATION = r"""
@inproceedings{huang-etal-2021-efficient,
title = "Efficient Attentions for Long Document Summarization",
author = "Huang, Luyang and
Cao, Shuyang and
Parulian, Nikolaus and
Ji, Heng and
Wang, Lu",
booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
month = jun,
year = "2021",
address = "Online",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2021.naacl-main.112",
doi = "10.18653/v1/2021.naacl-main.112",
pages = "1419--1436",
abstract = "The quadratic computational and memory complexities of large Transformers have limited their scalability for long document summarization. In this paper, we propose Hepos, a novel efficient encoder-decoder attention with head-wise positional strides to effectively pinpoint salient information from the source. We further conduct a systematic study of existing efficient self-attentions. Combined with Hepos, we are able to process ten times more tokens than existing models that use full attentions. For evaluation, we present a new dataset, GovReport, with significantly longer documents and summaries. Results show that our models produce significantly higher ROUGE scores than competitive comparisons, including new state-of-the-art results on PubMed. Human evaluation also shows that our models generate more informative summaries with fewer unfaithful errors.",
}"""
_CONTRACT_NLI_CITATION = """\
@inproceedings{koreeda-manning-2021-contractnli,
title = "ContractNLI: A Dataset for Document-level Natural Language Inference for Contracts",
author = "Koreeda, Yuta and
Manning, Christopher D.",
booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2021",
year = "2021",
publisher = "Association for Computational Linguistics"
}
"""
_QUALITY_CITATION = """\
@article{pang2021quality,
title={{QuALITY}: Question Answering with Long Input Texts, Yes!},
author={Pang, Richard Yuanzhe and Parrish, Alicia and Joshi, Nitish and Nangia, Nikita and Phang, Jason and Chen, Angelica and Padmakumar, Vishakh and Ma, Johnny and Thompson, Jana and He, He and Bowman, Samuel R.},
journal={arXiv preprint arXiv:2112.08608},
year={2021}
}
"""
class ScrollsConfig(datasets.BuilderConfig):
"""BuilderConfig for Scrolls."""
def __init__(self, features, data_url, citation, url, **kwargs):
"""BuilderConfig for Scrolls.
Args:
features: `list[string]`, list of the features that will appear in the
feature dict. Should not include "label".
data_url: `string`, url to download the zip file from.
citation: `string`, citation for the data set.
url: `string`, url for information about the data set.
label_classes: `list[string]`, the list of classes for the label if the
label is present as a string. Non-string labels will be cast to either
'False' or 'True'.
**kwargs: keyword arguments forwarded to super.
"""
# Version history:
# 1.0.2: Fixed non-nondeterminism in ReCoRD.
# 1.0.1: Change from the pre-release trial version of SuperGLUE (v1.9) to
# the full release (v2.0).
# 1.0.0: S3 (new shuffling, sharding and slicing mechanism).
# 0.0.2: Initial version.
super(ScrollsConfig, self).__init__(version=datasets.Version("1.0.2"), **kwargs)
self.features = features
self.data_url = data_url
self.citation = citation
self.url = url
class QualityConfig(ScrollsConfig):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.hard_only = False
class Scrolls(datasets.GeneratorBasedBuilder):
"""The SuperGLUE benchmark."""
features = ["id", "pid", "input", "output"]
DEFAULT_WRITER_BATCH_SIZE = 1000 # because Narrative QA is a rather large dataset
BUILDER_CONFIGS = [
ScrollsConfig(
name="summ_screen_fd",
description=_SUMM_SCREEN_DESCRIPTION,
features=features,
data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/summ_screen_fd.zip",
citation=_SUMM_SCREEN_CITATION,
url="https://github.com/mingdachen/SummScreen",
),
ScrollsConfig(
name="qasper",
description=_QASPER_DESCRIPTION,
features=features,
data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/qasper.zip",
citation=_QASPER_CITATION,
url="https://allenai.org/project/qasper",
),
ScrollsConfig(
name="qmsum",
description=_QMSUM_DESCRIPTION,
features=features,
data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/qmsum.zip",
citation=_QMSUM_CITATION,
url="https://github.com/Yale-LILY/QMSum",
),
ScrollsConfig(
name="narrative_qa",
description=_NARRATIVE_QA_DESCRIPTION,
features=features,
data_url="https://scrolls-tau.s3.us-east-2.amazonaws.com/narrative_qa.zip",
citation=_NARRATIVE_QA_CITATION,
url="https://deepmind.com/research/publications/narrativeqa-reading-comprehension-challenge",
),
ScrollsConfig(
name="gov_report",
description=_GOV_REPORT_CITATION,
features=features,
data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/gov_report.zip",
citation=_GOV_REPORT_DESCRIPTION,
url="https://gov-report-data.github.io/",
),
ScrollsConfig(
name="contract_nli",
description=_CONTRACT_NLI_DESCRIPTION,
features=features,
data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/contract_nli.zip",
citation=_CONTRACT_NLI_CITATION,
url="https://stanfordnlp.github.io/contract-nli/",
),
QualityConfig(
name="quality",
description=_QUALITY_CITATION,
features=features,
data_url="https://scrolls-tau.s3.us-east-2.amazonaws.com/quality.zip",
citation=_QUALITY_DESCRIPTION,
url="https://github.com/nyu-mll/quality",
),
]
def _info(self):
features = {feature: datasets.Value("string") for feature in self.config.features}
return datasets.DatasetInfo(
description=_SCROLLS_DESCRIPTION + self.config.description,
features=datasets.Features(features),
homepage=self.config.url,
citation=self.config.citation + "\n" + _SCROLLS_CITATION,
)
def _split_generators(self, dl_manager):
dl_dir = dl_manager.download_and_extract(self.config.data_url)
task_name = _get_task_name_from_data_url(self.config.data_url)
dl_dir = os.path.join(dl_dir, task_name)
data_files = {} if self.config.data_files is not None else None
if data_files is not None:
for split, paths in self.config.data_files.items():
data_files[split] = paths[0]
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"data_file": os.path.join(dl_dir, "train.jsonl"),
"split": datasets.Split.TRAIN,
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"data_file": os.path.join(dl_dir, "validation.jsonl"),
"split": datasets.Split.VALIDATION,
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"data_file": os.path.join(dl_dir, "test.jsonl") if data_files is None else data_files["test"],
"split": datasets.Split.TEST,
},
),
]
def _generate_examples(self, data_file, split):
with open(data_file, encoding="utf-8") as f:
for line in f:
row = json.loads(line)
if self.config.name == "quality":
is_hard = row.pop("is_hard", False)
if self.config.hard_only and not is_hard:
continue
yield row["pid"], row
def _get_task_name_from_data_url(data_url):
return data_url.split("/")[-1].split(".")[0]