Datasets:
Tasks:
Question Answering
Sub-tasks:
extractive-qa
Languages:
English
Size:
100K<n<1M
ArXiv:
License:
Commit
•
87af480
1
Parent(s):
b0eb0fa
Update and optimize loading script
Browse files- search_qa.py +22 -47
search_qa.py
CHANGED
@@ -14,11 +14,10 @@
|
|
14 |
# limitations under the License.
|
15 |
|
16 |
# Lint as: python3
|
17 |
-
"""
|
18 |
-
|
19 |
|
|
|
20 |
import json
|
21 |
-
import os
|
22 |
|
23 |
import datasets
|
24 |
|
@@ -57,8 +56,21 @@ Following this approach, we built SearchQA, which consists of more than 140k que
|
|
57 |
"""
|
58 |
|
59 |
_DL_URLS = {
|
60 |
-
"raw_jeopardy":
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
}
|
63 |
# pylint: enable=line-too-long
|
64 |
|
@@ -110,59 +122,22 @@ class SearchQa(datasets.GeneratorBasedBuilder):
|
|
110 |
|
111 |
def _split_generators(self, dl_manager):
|
112 |
"""Returns SplitGenerators."""
|
113 |
-
|
114 |
-
# dl_manager is a datasets.download.DownloadManager that can be used to
|
115 |
-
# download and extract URLs
|
116 |
-
|
117 |
if self.config.name == "raw_jeopardy":
|
118 |
-
|
119 |
-
sub_folders = sorted(os.listdir(os.path.join(filepath, "jeopardy")))
|
120 |
-
all_files = []
|
121 |
-
for zip_folder in sub_folders:
|
122 |
-
if "lock" in zip_folder:
|
123 |
-
continue
|
124 |
-
zip_folder_path = os.path.join(filepath, "jeopardy", zip_folder)
|
125 |
-
file_path = dl_manager.extract(zip_folder_path)
|
126 |
-
zip_folder = zip_folder.split(".")[0]
|
127 |
-
if os.path.isdir(os.path.join(file_path, zip_folder)):
|
128 |
-
file_path = os.path.join(file_path, zip_folder)
|
129 |
-
|
130 |
-
else:
|
131 |
-
# in some cases the subfolder name contains sapces as 050000 - 059999 and 050000-059999
|
132 |
-
parts = zip_folder.split("-")
|
133 |
-
zip_folder = parts[0] + " - " + parts[1]
|
134 |
-
if os.path.isdir(os.path.join(file_path, zip_folder)):
|
135 |
-
file_path = os.path.join(file_path, zip_folder)
|
136 |
-
|
137 |
-
files = sorted(os.listdir(file_path))
|
138 |
-
|
139 |
-
files_paths = [os.path.join(file_path, file) for file in files if "__MACOSX" not in file]
|
140 |
-
all_files.extend(files_paths)
|
141 |
-
|
142 |
return [
|
143 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths":
|
144 |
]
|
145 |
elif self.config.name == "train_test_val":
|
146 |
-
filepath = dl_manager.download_and_extract(_DL_URLS["train_test_val"])
|
147 |
-
train_path = dl_manager.extract(os.path.join(filepath, "data_json", "train.zip"))
|
148 |
-
test_path = dl_manager.extract(os.path.join(filepath, "data_json", "test.zip"))
|
149 |
-
val_path = dl_manager.extract(os.path.join(filepath, "data_json", "val.zip"))
|
150 |
-
|
151 |
-
train_files = [os.path.join(train_path, file) for file in sorted(os.listdir(train_path))]
|
152 |
-
test_files = [os.path.join(test_path, file) for file in sorted(os.listdir(test_path))]
|
153 |
-
val_files = [os.path.join(val_path, file) for file in sorted(os.listdir(val_path))]
|
154 |
return [
|
155 |
-
datasets.SplitGenerator(name=
|
156 |
-
datasets.
|
157 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepaths": val_files}),
|
158 |
]
|
159 |
|
160 |
def _generate_examples(self, filepaths):
|
161 |
"""Yields examples."""
|
162 |
-
# TODO(searchQa): Yields (key, example) tuples from the dataset
|
163 |
for i, filepath in enumerate(filepaths):
|
164 |
with open(filepath, encoding="utf-8") as f:
|
165 |
-
|
166 |
data = json.load(f)
|
167 |
category = data["category"]
|
168 |
air_date = data["air_date"]
|
|
|
14 |
# limitations under the License.
|
15 |
|
16 |
# Lint as: python3
|
17 |
+
"""SearchQA dataset."""
|
|
|
18 |
|
19 |
+
import itertools
|
20 |
import json
|
|
|
21 |
|
22 |
import datasets
|
23 |
|
|
|
56 |
"""
|
57 |
|
58 |
_DL_URLS = {
|
59 |
+
"raw_jeopardy": [
|
60 |
+
"data/raw_jeopardy/000000-029999.zip",
|
61 |
+
"data/raw_jeopardy/030000-49999.zip",
|
62 |
+
"data/raw_jeopardy/050000-059999.zip",
|
63 |
+
"data/raw_jeopardy/060000-089999.zip",
|
64 |
+
"data/raw_jeopardy/090000-119999.zip",
|
65 |
+
"data/raw_jeopardy/120000-149999.zip",
|
66 |
+
"data/raw_jeopardy/150000-179999.zip",
|
67 |
+
"data/raw_jeopardy/180000-216929.zip",
|
68 |
+
],
|
69 |
+
"train_test_val": {
|
70 |
+
"train": "data/train_test_val/train.zip",
|
71 |
+
"test": "data/train_test_val/test.zip",
|
72 |
+
"validation": "data/train_test_val/val.zip",
|
73 |
+
},
|
74 |
}
|
75 |
# pylint: enable=line-too-long
|
76 |
|
|
|
122 |
|
123 |
def _split_generators(self, dl_manager):
|
124 |
"""Returns SplitGenerators."""
|
125 |
+
data_dirs = dl_manager.download_and_extract(_DL_URLS[self.config.name])
|
|
|
|
|
|
|
126 |
if self.config.name == "raw_jeopardy":
|
127 |
+
filepaths = itertools.chain.from_iterable(dl_manager.iter_files(data_dir) for data_dir in data_dirs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
return [
|
129 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepaths": filepaths}),
|
130 |
]
|
131 |
elif self.config.name == "train_test_val":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
return [
|
133 |
+
datasets.SplitGenerator(name=split, gen_kwargs={"filepaths": dl_manager.iter_files(data_dirs[split])})
|
134 |
+
for split in (datasets.Split.TRAIN, datasets.Split.TEST, datasets.Split.VALIDATION)
|
|
|
135 |
]
|
136 |
|
137 |
def _generate_examples(self, filepaths):
|
138 |
"""Yields examples."""
|
|
|
139 |
for i, filepath in enumerate(filepaths):
|
140 |
with open(filepath, encoding="utf-8") as f:
|
|
|
141 |
data = json.load(f)
|
142 |
category = data["category"]
|
143 |
air_date = data["air_date"]
|