Datasets:
Tags:
speech-modeling
License:
Fix data to allow .shuffle()
Browse files
NPSC.py
CHANGED
@@ -21,7 +21,6 @@ import json
|
|
21 |
import tarfile
|
22 |
import datasets
|
23 |
from datasets.tasks import AutomaticSpeechRecognition
|
24 |
-
from datasets.utils.streaming_download_manager import xopen
|
25 |
|
26 |
|
27 |
_CITATION = """\
|
@@ -115,60 +114,50 @@ class Npsc(datasets.GeneratorBasedBuilder):
|
|
115 |
def _split_generators(self, dl_manager):
|
116 |
"""Returns SplitGenerators."""
|
117 |
data_urls = {}
|
118 |
-
metadata_urls = {}
|
119 |
config_name = self.config.name
|
120 |
for split in ["train", "eval", "test"]:
|
121 |
-
metadata_urls[split] = []
|
122 |
data_urls[split] = []
|
123 |
for shard in _SHARDS[split]:
|
124 |
-
|
125 |
-
_METADATA_URL.format(split=split, shard=shard)
|
126 |
-
]
|
127 |
-
data_urls[split] += [
|
128 |
_DATA_URL.format(split=split, shard=shard, config=config_name)
|
129 |
-
]
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
train_downloaded_archives = dl_manager.download(data_urls["train"])
|
134 |
-
validation_downloaded_archives = dl_manager.download(data_urls["eval"])
|
135 |
-
test_downloaded_archives = dl_manager.download(data_urls["test"])
|
136 |
|
137 |
return [
|
138 |
datasets.SplitGenerator(
|
139 |
name=datasets.Split.TRAIN, gen_kwargs={
|
140 |
-
"
|
141 |
-
"metadata_paths": train_downloaded_metadata,
|
142 |
}
|
143 |
),
|
144 |
datasets.SplitGenerator(
|
145 |
name=datasets.Split.VALIDATION, gen_kwargs={
|
146 |
-
"
|
147 |
-
"metadata_paths": validation_downloaded_metadata,
|
148 |
}
|
149 |
),
|
150 |
datasets.SplitGenerator(
|
151 |
name=datasets.Split.TEST, gen_kwargs={
|
152 |
-
"
|
153 |
-
"metadata_paths": test_downloaded_metadata,
|
154 |
}
|
155 |
),
|
156 |
]
|
157 |
|
158 |
-
def _generate_examples(self,
|
159 |
"""Yields examples."""
|
160 |
data_fields = list(self._info().features.keys())
|
161 |
data_fields.remove("audio")
|
162 |
-
for
|
163 |
metadata = {}
|
164 |
-
with
|
165 |
for line in metadata_file.read().split("\n"):
|
166 |
if line:
|
167 |
metadata_object = json.loads(line)
|
168 |
if "path" in metadata_object:
|
169 |
metadata_key = metadata_object["path"].split("/", 1)[-1]
|
170 |
metadata[metadata_key] = metadata_object
|
171 |
-
with
|
172 |
archive_bytes = io.BytesIO(archive_fs.read())
|
173 |
with tarfile.open(fileobj=archive_bytes, mode="r") as tar:
|
174 |
for audio_file in tar.getmembers():
|
|
|
21 |
import tarfile
|
22 |
import datasets
|
23 |
from datasets.tasks import AutomaticSpeechRecognition
|
|
|
24 |
|
25 |
|
26 |
_CITATION = """\
|
|
|
114 |
def _split_generators(self, dl_manager):
|
115 |
"""Returns SplitGenerators."""
|
116 |
data_urls = {}
|
|
|
117 |
config_name = self.config.name
|
118 |
for split in ["train", "eval", "test"]:
|
|
|
119 |
data_urls[split] = []
|
120 |
for shard in _SHARDS[split]:
|
121 |
+
data_urls[split] += [(
|
122 |
+
_METADATA_URL.format(split=split, shard=shard),
|
|
|
|
|
123 |
_DATA_URL.format(split=split, shard=shard, config=config_name)
|
124 |
+
)]
|
125 |
+
train_downloaded_data = dl_manager.download(data_urls["train"])
|
126 |
+
validation_downloaded_data = dl_manager.download(data_urls["eval"])
|
127 |
+
test_downloaded_data = dl_manager.download(data_urls["test"])
|
|
|
|
|
|
|
128 |
|
129 |
return [
|
130 |
datasets.SplitGenerator(
|
131 |
name=datasets.Split.TRAIN, gen_kwargs={
|
132 |
+
"filepaths": train_downloaded_data,
|
|
|
133 |
}
|
134 |
),
|
135 |
datasets.SplitGenerator(
|
136 |
name=datasets.Split.VALIDATION, gen_kwargs={
|
137 |
+
"filepaths": validation_downloaded_data,
|
|
|
138 |
}
|
139 |
),
|
140 |
datasets.SplitGenerator(
|
141 |
name=datasets.Split.TEST, gen_kwargs={
|
142 |
+
"filepaths": test_downloaded_data,
|
|
|
143 |
}
|
144 |
),
|
145 |
]
|
146 |
|
147 |
+
def _generate_examples(self, filepaths):
|
148 |
"""Yields examples."""
|
149 |
data_fields = list(self._info().features.keys())
|
150 |
data_fields.remove("audio")
|
151 |
+
for metadata_path, archive_path in filepaths:
|
152 |
metadata = {}
|
153 |
+
with open(metadata_path) as metadata_file:
|
154 |
for line in metadata_file.read().split("\n"):
|
155 |
if line:
|
156 |
metadata_object = json.loads(line)
|
157 |
if "path" in metadata_object:
|
158 |
metadata_key = metadata_object["path"].split("/", 1)[-1]
|
159 |
metadata[metadata_key] = metadata_object
|
160 |
+
with open(archive_path, "rb") as archive_fs:
|
161 |
archive_bytes = io.BytesIO(archive_fs.read())
|
162 |
with tarfile.open(fileobj=archive_bytes, mode="r") as tar:
|
163 |
for audio_file in tar.getmembers():
|