Initial data loader version
Browse files- .gitattributes +7 -0
- squality.py +194 -0
.gitattributes
CHANGED
@@ -35,3 +35,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
35 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
36 |
*.ogg filter=lfs diff=lfs merge=lfs -text
|
37 |
*.wav filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
36 |
*.ogg filter=lfs diff=lfs merge=lfs -text
|
37 |
*.wav filter=lfs diff=lfs merge=lfs -text
|
38 |
+
data/v1/test.jsonl filter=lfs diff=lfs merge=lfs -text
|
39 |
+
data/v1/train.jsonl filter=lfs diff=lfs merge=lfs -text
|
40 |
+
data/v1/validation.jsonl filter=lfs diff=lfs merge=lfs -text
|
41 |
+
data/v1-1/*.jsonl filter=lfs diff=lfs merge=lfs -text
|
42 |
+
data/v1-1/train.jsonl filter=lfs diff=lfs merge=lfs -text
|
43 |
+
data/v1-1/validation.jsonl filter=lfs diff=lfs merge=lfs -text
|
44 |
+
data/v1-1/test.jsonl filter=lfs diff=lfs merge=lfs -text
|
squality.py
ADDED
@@ -0,0 +1,194 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
2 |
+
#
|
3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4 |
+
# you may not use this file except in compliance with the License.
|
5 |
+
# You may obtain a copy of the License at
|
6 |
+
#
|
7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8 |
+
#
|
9 |
+
# Unless required by applicable law or agreed to in writing, software
|
10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12 |
+
# See the License for the specific language governing permissions and
|
13 |
+
# limitations under the License.
|
14 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
15 |
+
"""TODO: Add a description here."""
|
16 |
+
""" Dataset loading script for SQuALITY, an abstractive summarization dataset that is
|
17 |
+
* long document: 3k-6k words
|
18 |
+
* question-focused: 5/doc
|
19 |
+
* multi-reference 4/question
|
20 |
+
"""
|
21 |
+
|
22 |
+
import os
|
23 |
+
import csv
|
24 |
+
import json
|
25 |
+
|
26 |
+
import datasets
|
27 |
+
|
28 |
+
|
29 |
+
_CITATION = """\
|
30 |
+
@article{wang2022squality,
|
31 |
+
title={SQuALITY: Building a Long-Document Summarization Dataset the Hard Way},
|
32 |
+
author={Wang, Alex and Pang, Richard Yuanzhe and Chen, Angelica and Phang, Jason and Bowman, Samuel R.},
|
33 |
+
journal={arXiv preprint 2205.11465},
|
34 |
+
year={2022}
|
35 |
+
}
|
36 |
+
"""
|
37 |
+
|
38 |
+
# TODO: Add description of the dataset here
|
39 |
+
# You can copy an official description
|
40 |
+
_DESCRIPTION = """\
|
41 |
+
This new dataset is designed to solve this great NLP task and is crafted with a lot of care.
|
42 |
+
"""
|
43 |
+
|
44 |
+
_HOMEPAGE = "ihttps://github.com/nyu-mll/SQuALITY"
|
45 |
+
|
46 |
+
_LICENSE = "CC BY"
|
47 |
+
|
48 |
+
# TODO: Add link to the official dataset URLs here
|
49 |
+
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
50 |
+
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
51 |
+
#_URLS = {
|
52 |
+
# "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
|
53 |
+
# "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
|
54 |
+
#}
|
55 |
+
|
56 |
+
|
57 |
+
class SQuALITYDataset(datasets.GeneratorBasedBuilder):
|
58 |
+
"""TODO: Short description of my dataset."""
|
59 |
+
|
60 |
+
VERSION = datasets.Version("1.1")
|
61 |
+
|
62 |
+
# This is an example of a dataset with multiple configurations.
|
63 |
+
# If you don't want/need to define several sub-sets in your dataset,
|
64 |
+
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
|
65 |
+
|
66 |
+
# If you need to make complex sub-parts in the datasets with configurable options
|
67 |
+
# You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
|
68 |
+
# BUILDER_CONFIG_CLASS = MyBuilderConfig
|
69 |
+
|
70 |
+
# You will be able to load one or the other configurations in the following list with
|
71 |
+
# data = datasets.load_dataset('my_dataset', 'first_domain')
|
72 |
+
BUILDER_CONFIGS = [
|
73 |
+
datasets.BuilderConfig(name="squality-v1", version=datasets.Version("1.0"), description="SQUALITY v1.0, containing 100 stories (2000 summaries)"),
|
74 |
+
datasets.BuilderConfig(name="squality-v1.1", version=VERSION, description="SQuALITY version v1.1, expands on v1.0 by adding 27 stories (540 summaries)"),
|
75 |
+
]
|
76 |
+
|
77 |
+
DEFAULT_CONFIG_NAME = "squality-v1.1" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
78 |
+
|
79 |
+
def _info(self):
|
80 |
+
# This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
81 |
+
|
82 |
+
#if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
83 |
+
# features = datasets.Features(
|
84 |
+
# {
|
85 |
+
# "sentence": datasets.Value("string"),
|
86 |
+
# "option1": datasets.Value("string"),
|
87 |
+
# "answer": datasets.Value("string")
|
88 |
+
# # These are the features of your dataset like images, labels ...
|
89 |
+
# }
|
90 |
+
# )
|
91 |
+
|
92 |
+
features = datasets.Features(
|
93 |
+
{
|
94 |
+
"document": datasets.Value("string"),
|
95 |
+
"question": datasets.Value("string"),
|
96 |
+
"summary": datasets.Value("string")
|
97 |
+
# These are the features of your dataset like images, labels ...
|
98 |
+
}
|
99 |
+
)
|
100 |
+
|
101 |
+
return datasets.DatasetInfo(
|
102 |
+
# This is the description that will appear on the datasets page.
|
103 |
+
description=_DESCRIPTION,
|
104 |
+
# This defines the different columns of the dataset and their types
|
105 |
+
features=features,
|
106 |
+
# If there's a common (input, target) tuple from the features,
|
107 |
+
# uncomment supervised_keys line below and
|
108 |
+
# specify them. They'll be used if as_supervised=True in builder.as_dataset.
|
109 |
+
# supervised_keys=("sentence", "label"),
|
110 |
+
# Homepage of the dataset for documentation
|
111 |
+
homepage=_HOMEPAGE,
|
112 |
+
# License for the dataset if available
|
113 |
+
license=_LICENSE,
|
114 |
+
# Citation for the dataset
|
115 |
+
citation=_CITATION,
|
116 |
+
)
|
117 |
+
|
118 |
+
def _split_generators(self, dl_manager):
|
119 |
+
# This method is tasked with downloading/extracting the data and
|
120 |
+
# defining the splits depending on the configuration
|
121 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS),
|
122 |
+
# the configuration selected by the user is in self.config.name
|
123 |
+
|
124 |
+
if self.config.name == "squality-v1":
|
125 |
+
data_dir = "data/v1"
|
126 |
+
elif self.config.name == "squality-v1.1":
|
127 |
+
data_dir = "data/v1-1"
|
128 |
+
|
129 |
+
return [
|
130 |
+
datasets.SplitGenerator(
|
131 |
+
name=datasets.Split.TRAIN,
|
132 |
+
# These kwargs will be passed to _generate_examples
|
133 |
+
gen_kwargs={
|
134 |
+
"filepath": os.path.join(data_dir, "train.jsonl"),
|
135 |
+
"split": "train",
|
136 |
+
},
|
137 |
+
),
|
138 |
+
datasets.SplitGenerator(
|
139 |
+
name=datasets.Split.TEST,
|
140 |
+
# These kwargs will be passed to _generate_examples
|
141 |
+
gen_kwargs={
|
142 |
+
"filepath": os.path.join(data_dir, "test.jsonl"),
|
143 |
+
"split": "test"
|
144 |
+
},
|
145 |
+
),
|
146 |
+
datasets.SplitGenerator(
|
147 |
+
name=datasets.Split.VALIDATION,
|
148 |
+
# These kwargs will be passed to _generate_examples
|
149 |
+
gen_kwargs={
|
150 |
+
"filepath": os.path.join(data_dir, "validation.jsonl"),
|
151 |
+
"split": "dev",
|
152 |
+
},
|
153 |
+
),
|
154 |
+
]
|
155 |
+
|
156 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
157 |
+
def _generate_examples(self, filepath, split):
|
158 |
+
# This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
159 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
160 |
+
with open(filepath, encoding="utf-8") as f:
|
161 |
+
for row in enumerate(f):
|
162 |
+
# fields
|
163 |
+
# * metadata
|
164 |
+
# * document
|
165 |
+
# * questions
|
166 |
+
story = json.loads(row)
|
167 |
+
for question in story['questions']:
|
168 |
+
# fields
|
169 |
+
# * question_text
|
170 |
+
# * question_number
|
171 |
+
# * responses
|
172 |
+
key = question['gem_id']
|
173 |
+
|
174 |
+
# for the test split, yield all references at once
|
175 |
+
# to easily compute multi-reference metrics
|
176 |
+
if split == "test":
|
177 |
+
yield key, {
|
178 |
+
'document': story['document'],
|
179 |
+
'question': question['question_text'],
|
180 |
+
'summary': [r['response_text'] for r in question['responses']]
|
181 |
+
}
|
182 |
+
|
183 |
+
else:
|
184 |
+
for response in question['responses']:
|
185 |
+
# fields
|
186 |
+
# * uid
|
187 |
+
# * worker_uid
|
188 |
+
# * response_text
|
189 |
+
yield key, {
|
190 |
+
'document': story['document'],
|
191 |
+
'question': question['question_text'],
|
192 |
+
'summary': response['response_text']
|
193 |
+
}
|
194 |
+
|