Uri commited on
Commit
327ffe0
1 Parent(s): 646a69c

Upload scrolls.py

Browse files
Files changed (1) hide show
  1. scrolls.py +308 -0
scrolls.py ADDED
@@ -0,0 +1,308 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # TODO License
3
+
4
+ # Lint as: python3
5
+ """The Scrolls benchmark."""
6
+
7
+
8
+ import json
9
+ import os
10
+ import datasets
11
+
12
+ _SCROLLS_CITATION = """
13
+ @article{ TODO citation here
14
+ }
15
+ Note that each Scrolls dataset has its own citation. Please see the source to
16
+ get the correct citation for each contained dataset.
17
+ """
18
+
19
+ _SCROLLS_DESCRIPTION = """
20
+ Scrolls (https://TODO.com/) is a benchmark of generative tasks that require processing long texts.
21
+ """
22
+
23
+ _SUMM_SCREEN_DESCRIPTION = """
24
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
25
+ show episode, given the full script."""
26
+
27
+
28
+ _QASPER_DESCRIPTION = """
29
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
30
+ show episode, given the full script."""
31
+
32
+
33
+ _QMSUM_DESCRIPTION = """
34
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
35
+ show episode, given the full script."""
36
+
37
+
38
+ _NARRATIVE_QA_DESCRIPTION = """
39
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
40
+ show episode, given the full script."""
41
+
42
+
43
+ _GOV_REPORT_DESCRIPTION = """
44
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
45
+ show episode, given the full script."""
46
+
47
+
48
+ _CONTRACT_NLI_DESCRIPTION = """
49
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
50
+ show episode, given the full script."""
51
+
52
+
53
+ _QUALITY_DESCRIPTION = """
54
+ SummScreen (Boolean Questions, Clark et al., 2019a) is a summarization task where one should output the recap of a TV
55
+ show episode, given the full script."""
56
+
57
+
58
+ _SUMM_SCREEN_CITATION = r"""
59
+ @misc{chen2021summscreen,
60
+ title={SummScreen: A Dataset for Abstractive Screenplay Summarization},
61
+ author={Mingda Chen and Zewei Chu and Sam Wiseman and Kevin Gimpel},
62
+ year={2021},
63
+ eprint={2104.07091},
64
+ archivePrefix={arXiv},
65
+ primaryClass={cs.CL}
66
+ }"""
67
+
68
+ _QASPER_CITATION = r"""
69
+ @inproceedings{dasigi-etal-2021-dataset,
70
+ title = "A Dataset of Information-Seeking Questions and Answers Anchored in Research Papers",
71
+ author = "Dasigi, Pradeep and
72
+ Lo, Kyle and
73
+ Beltagy, Iz and
74
+ Cohan, Arman and
75
+ Smith, Noah A. and
76
+ Gardner, Matt",
77
+ booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
78
+ month = jun,
79
+ year = "2021",
80
+ address = "Online",
81
+ publisher = "Association for Computational Linguistics",
82
+ url = "https://aclanthology.org/2021.naacl-main.365",
83
+ doi = "10.18653/v1/2021.naacl-main.365",
84
+ pages = "4599--4610",
85
+ 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.",
86
+ }"""
87
+
88
+ _QMSUM_CITATION = r"""@inproceedings{zhong-etal-2021-qmsum,
89
+ title = "{QMS}um: A New Benchmark for Query-based Multi-domain Meeting Summarization",
90
+ author = "Zhong, Ming and
91
+ Yin, Da and
92
+ Yu, Tao and
93
+ Zaidi, Ahmad and
94
+ Mutuma, Mutethia and
95
+ Jha, Rahul and
96
+ Awadallah, Ahmed Hassan and
97
+ Celikyilmaz, Asli and
98
+ Liu, Yang and
99
+ Qiu, Xipeng and
100
+ Radev, Dragomir",
101
+ booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
102
+ month = jun,
103
+ year = "2021",
104
+ address = "Online",
105
+ publisher = "Association for Computational Linguistics",
106
+ url = "https://aclanthology.org/2021.naacl-main.472",
107
+ doi = "10.18653/v1/2021.naacl-main.472",
108
+ pages = "5905--5921",
109
+ 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}.",
110
+ }"""
111
+
112
+ _NARRATIVE_QA_CITATION = r"""
113
+ @article{kovcisky2018narrativeqa,
114
+ title={The narrativeqa reading comprehension challenge},
115
+ 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},
116
+ journal={Transactions of the Association for Computational Linguistics},
117
+ volume={6},
118
+ pages={317--328},
119
+ year={2018},
120
+ publisher={MIT Press}
121
+ }"""
122
+
123
+ _GOV_REPORT_CITATION = r"""
124
+ @inproceedings{huang-etal-2021-efficient,
125
+ title = "Efficient Attentions for Long Document Summarization",
126
+ author = "Huang, Luyang and
127
+ Cao, Shuyang and
128
+ Parulian, Nikolaus and
129
+ Ji, Heng and
130
+ Wang, Lu",
131
+ booktitle = "Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies",
132
+ month = jun,
133
+ year = "2021",
134
+ address = "Online",
135
+ publisher = "Association for Computational Linguistics",
136
+ url = "https://aclanthology.org/2021.naacl-main.112",
137
+ doi = "10.18653/v1/2021.naacl-main.112",
138
+ pages = "1419--1436",
139
+ 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.",
140
+ }"""
141
+
142
+ _CONTRACT_NLI_CITATION = """\
143
+ @inproceedings{koreeda-manning-2021-contractnli,
144
+ title = "ContractNLI: A Dataset for Document-level Natural Language Inference for Contracts",
145
+ author = "Koreeda, Yuta and
146
+ Manning, Christopher D.",
147
+ booktitle = "Findings of the Association for Computational Linguistics: EMNLP 2021",
148
+ year = "2021",
149
+ publisher = "Association for Computational Linguistics"
150
+ }
151
+ """
152
+ _QUALITY_CITATION = """\
153
+ @article{pang2021quality,
154
+ title={{QuALITY}: Question Answering with Long Input Texts, Yes!},
155
+ 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.},
156
+ journal={arXiv preprint arXiv:2112.08608},
157
+ year={2021}
158
+ }
159
+ """
160
+
161
+ class ScrollsConfig(datasets.BuilderConfig):
162
+ """BuilderConfig for Scrolls."""
163
+
164
+ def __init__(self, features, data_url, citation, url, **kwargs):
165
+ """BuilderConfig for Scrolls.
166
+ Args:
167
+ features: `list[string]`, list of the features that will appear in the
168
+ feature dict. Should not include "label".
169
+ data_url: `string`, url to download the zip file from.
170
+ citation: `string`, citation for the data set.
171
+ url: `string`, url for information about the data set.
172
+ label_classes: `list[string]`, the list of classes for the label if the
173
+ label is present as a string. Non-string labels will be cast to either
174
+ 'False' or 'True'.
175
+ **kwargs: keyword arguments forwarded to super.
176
+ """
177
+ # Version history:
178
+ # 1.0.2: Fixed non-nondeterminism in ReCoRD.
179
+ # 1.0.1: Change from the pre-release trial version of SuperGLUE (v1.9) to
180
+ # the full release (v2.0).
181
+ # 1.0.0: S3 (new shuffling, sharding and slicing mechanism).
182
+ # 0.0.2: Initial version.
183
+ super(ScrollsConfig, self).__init__(version=datasets.Version("1.0.2"), **kwargs)
184
+ self.features = features
185
+ self.data_url = data_url
186
+ self.citation = citation
187
+ self.url = url
188
+
189
+ class QualityConfig(ScrollsConfig):
190
+ def __init__(self, **kwargs):
191
+ super().__init__(**kwargs)
192
+ self.hard_only = False
193
+
194
+ class Scrolls(datasets.GeneratorBasedBuilder):
195
+ """The SuperGLUE benchmark."""
196
+ features = ["id", "pid", "input", "output"]
197
+ DEFAULT_WRITER_BATCH_SIZE = 1000 # because Narrative QA is a rather large dataset
198
+ BUILDER_CONFIGS = [
199
+ ScrollsConfig(
200
+ name="summ_screen_fd",
201
+ description=_SUMM_SCREEN_DESCRIPTION,
202
+ features=features,
203
+ data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/summ_screen_fd.zip",
204
+ citation=_SUMM_SCREEN_CITATION,
205
+ url="https://github.com/mingdachen/SummScreen",
206
+ ),
207
+ ScrollsConfig(
208
+ name="qasper",
209
+ description=_QASPER_DESCRIPTION,
210
+ features=features,
211
+ data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/qasper.zip",
212
+ citation=_QASPER_CITATION,
213
+ url="https://allenai.org/project/qasper",
214
+ ),
215
+ ScrollsConfig(
216
+ name="qmsum",
217
+ description=_QMSUM_DESCRIPTION,
218
+ features=features,
219
+ data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/qmsum.zip",
220
+ citation=_QMSUM_CITATION,
221
+ url="https://github.com/Yale-LILY/QMSum",
222
+ ),
223
+ ScrollsConfig(
224
+ name="narrative_qa",
225
+ description=_NARRATIVE_QA_DESCRIPTION,
226
+ features=features,
227
+ data_url="https://scrolls-tau.s3.us-east-2.amazonaws.com/narrative_qa.zip",
228
+ citation=_NARRATIVE_QA_CITATION,
229
+ url="https://deepmind.com/research/publications/narrativeqa-reading-comprehension-challenge",
230
+ ),
231
+ ScrollsConfig(
232
+ name="gov_report",
233
+ description=_GOV_REPORT_CITATION,
234
+ features=features,
235
+ data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/gov_report.zip",
236
+ citation=_GOV_REPORT_DESCRIPTION,
237
+ url="https://gov-report-data.github.io/",
238
+ ),
239
+ ScrollsConfig(
240
+ name="contract_nli",
241
+ description=_CONTRACT_NLI_DESCRIPTION,
242
+ features=features,
243
+ data_url="https://huggingface.co/datasets/tau/scrolls/resolve/main/contract_nli.zip",
244
+ citation=_CONTRACT_NLI_CITATION,
245
+ url="https://stanfordnlp.github.io/contract-nli/",
246
+ ),
247
+ QualityConfig(
248
+ name="quality",
249
+ description=_QUALITY_CITATION,
250
+ features=features,
251
+ data_url="https://scrolls-tau.s3.us-east-2.amazonaws.com/quality.zip",
252
+ citation=_QUALITY_DESCRIPTION,
253
+ url="https://github.com/nyu-mll/quality",
254
+ )
255
+ ]
256
+
257
+ def _info(self):
258
+ features = {feature: datasets.Value("string") for feature in self.config.features}
259
+
260
+ return datasets.DatasetInfo(
261
+ description=_SCROLLS_DESCRIPTION + self.config.description,
262
+ features=datasets.Features(features),
263
+ homepage=self.config.url,
264
+ citation=self.config.citation + "\n" + _SCROLLS_CITATION,
265
+ )
266
+
267
+ def _split_generators(self, dl_manager):
268
+ dl_dir = dl_manager.download_and_extract(self.config.data_url)
269
+ task_name = _get_task_name_from_data_url(self.config.data_url)
270
+ dl_dir = os.path.join(dl_dir, task_name)
271
+ return [
272
+ datasets.SplitGenerator(
273
+ name=datasets.Split.TRAIN,
274
+ gen_kwargs={
275
+ "data_file": os.path.join(dl_dir, "train.jsonl"),
276
+ "split": datasets.Split.TRAIN,
277
+ },
278
+ ),
279
+ datasets.SplitGenerator(
280
+ name=datasets.Split.VALIDATION,
281
+ gen_kwargs={
282
+ "data_file": os.path.join(dl_dir, "validation.jsonl"),
283
+ "split": datasets.Split.VALIDATION,
284
+ },
285
+ ),
286
+ datasets.SplitGenerator(
287
+ name=datasets.Split.TEST,
288
+ gen_kwargs={
289
+ "data_file": os.path.join(dl_dir, "test.jsonl") if self.config.data_files is None else self.config.data_files["test"],
290
+ "split": datasets.Split.TEST,
291
+ },
292
+ ),
293
+ ]
294
+
295
+ def _generate_examples(self, data_file, split):
296
+ with open(data_file, encoding="utf-8") as f:
297
+ for line in f:
298
+ row = json.loads(line)
299
+
300
+ if self.config.name == "quality":
301
+ if self.config.hard_only and not row["is_hard"]:
302
+ continue
303
+
304
+ yield row["pid"], row
305
+
306
+
307
+ def _get_task_name_from_data_url(data_url):
308
+ return data_url.split("/")[-1].split(".")[0]