Commit
•
3333d98
1
Parent(s):
b1faecb
add some comments and todos
Browse files- peoples_speech.py +18 -29
peoples_speech.py
CHANGED
@@ -61,35 +61,8 @@ _LICENSE = [
|
|
61 |
"cc-by-sa-3.0", "cc-by-sa-4.0"
|
62 |
]
|
63 |
|
64 |
-
# TODO: Add link to the official dataset URLs here
|
65 |
-
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
|
66 |
-
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
|
67 |
-
_URLS = {
|
68 |
-
"clean-cc-by": {
|
69 |
-
"audio_tar": "",
|
70 |
-
"manifest": "",
|
71 |
-
},
|
72 |
-
"dirty-cc-by": {
|
73 |
-
"audio_tar": "",
|
74 |
-
"manifest": "",
|
75 |
-
},
|
76 |
-
"clean-cc-by-sa": {
|
77 |
-
"audio_tar": "",
|
78 |
-
"manifest": "",
|
79 |
-
},
|
80 |
-
"dirty-cc-by-sa": {
|
81 |
-
"audio_tar": "",
|
82 |
-
"manifest": "",
|
83 |
-
},
|
84 |
-
"microset": {
|
85 |
-
"audio_tar": "",
|
86 |
-
"manifest": "",
|
87 |
-
},
|
88 |
-
}
|
89 |
-
|
90 |
-
# _BASE_URL = "https://huggingface.co/datasets/MLCommons/peoples_speech/resolve/main/"
|
91 |
-
|
92 |
# relative path to data inside dataset's repo
|
|
|
93 |
_DATA_URL = "{config}/{config}_00000{archive_id}.tar"
|
94 |
|
95 |
# relative path to metadata inside dataset's repo
|
@@ -101,6 +74,7 @@ class PeoplesSpeech(datasets.GeneratorBasedBuilder):
|
|
101 |
|
102 |
VERSION = datasets.Version("1.1.0")
|
103 |
BUILDER_CONFIGS = [
|
|
|
104 |
datasets.BuilderConfig(name="clean", version=VERSION, description="Clean, CC-BY licensed subset."),
|
105 |
datasets.BuilderConfig(name="dirty", version=VERSION, description="Dirty, CC-BY licensed subset."),
|
106 |
datasets.BuilderConfig(name="clean_sa", version=VERSION, description="Clean, CC-BY-SA licensed subset."),
|
@@ -132,17 +106,30 @@ class PeoplesSpeech(datasets.GeneratorBasedBuilder):
|
|
132 |
# TODO: this should be changed to the actual number of archives further
|
133 |
urls = [_DATA_URL.format(config=self.config.name, archive_id=i) for i in range(5)]
|
134 |
archive_paths = [dl_manager.download(url) for url in urls]
|
|
|
|
|
135 |
local_extracted_archive_paths = [dl_manager.extract(path) for path in archive_paths] \
|
136 |
if not dl_manager.is_streaming else [None] * len(archive_paths)
|
137 |
|
138 |
manifest_url = _MANIFEST_URL.format(config=self.config.name)
|
139 |
manifest_path = dl_manager.download_and_extract(manifest_url)
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
return [
|
142 |
datasets.SplitGenerator(
|
143 |
name=datasets.Split.TRAIN,
|
144 |
gen_kwargs={
|
145 |
"local_extracted_archive_paths": local_extracted_archive_paths,
|
|
|
146 |
"archives": [dl_manager.iter_archive(path) for path in archive_paths],
|
147 |
"manifest_path": manifest_path
|
148 |
},
|
@@ -165,9 +152,11 @@ class PeoplesSpeech(datasets.GeneratorBasedBuilder):
|
|
165 |
"duration_ms": duration
|
166 |
}
|
167 |
|
168 |
-
print("generating examples")
|
169 |
for local_extracted_archive_path, archive in zip(local_extracted_archive_paths, archives):
|
|
|
170 |
for audio_filename, audio_file in archive:
|
|
|
|
|
171 |
path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path \
|
172 |
else audio_filename
|
173 |
yield audio_filename, {
|
|
|
61 |
"cc-by-sa-3.0", "cc-by-sa-4.0"
|
62 |
]
|
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
# relative path to data inside dataset's repo
|
65 |
+
# TODO: change according to the scheme of generating urls to the audio archives
|
66 |
_DATA_URL = "{config}/{config}_00000{archive_id}.tar"
|
67 |
|
68 |
# relative path to metadata inside dataset's repo
|
|
|
74 |
|
75 |
VERSION = datasets.Version("1.1.0")
|
76 |
BUILDER_CONFIGS = [
|
77 |
+
# TODO: add "subset" config
|
78 |
datasets.BuilderConfig(name="clean", version=VERSION, description="Clean, CC-BY licensed subset."),
|
79 |
datasets.BuilderConfig(name="dirty", version=VERSION, description="Dirty, CC-BY licensed subset."),
|
80 |
datasets.BuilderConfig(name="clean_sa", version=VERSION, description="Clean, CC-BY-SA licensed subset."),
|
|
|
106 |
# TODO: this should be changed to the actual number of archives further
|
107 |
urls = [_DATA_URL.format(config=self.config.name, archive_id=i) for i in range(5)]
|
108 |
archive_paths = [dl_manager.download(url) for url in urls]
|
109 |
+
|
110 |
+
# In non-streaming mode, we extract the archives to have the data locally:
|
111 |
local_extracted_archive_paths = [dl_manager.extract(path) for path in archive_paths] \
|
112 |
if not dl_manager.is_streaming else [None] * len(archive_paths)
|
113 |
|
114 |
manifest_url = _MANIFEST_URL.format(config=self.config.name)
|
115 |
manifest_path = dl_manager.download_and_extract(manifest_url)
|
116 |
|
117 |
+
# To access the audio data from the TAR archives using the download manager,
|
118 |
+
# we have to use the dl_manager.iter_archive method
|
119 |
+
#
|
120 |
+
# This is because dl_manager.download_and_extract
|
121 |
+
# doesn't work to stream TAR archives in streaming mode.
|
122 |
+
# (we have to stream the files of a TAR archive one by one)
|
123 |
+
#
|
124 |
+
# The iter_archive method returns an iterable of (path_within_archive, file_obj) for every
|
125 |
+
# file in a TAR archive.
|
126 |
+
|
127 |
return [
|
128 |
datasets.SplitGenerator(
|
129 |
name=datasets.Split.TRAIN,
|
130 |
gen_kwargs={
|
131 |
"local_extracted_archive_paths": local_extracted_archive_paths,
|
132 |
+
# use iter_archive here to access the files in the TAR archives:
|
133 |
"archives": [dl_manager.iter_archive(path) for path in archive_paths],
|
134 |
"manifest_path": manifest_path
|
135 |
},
|
|
|
152 |
"duration_ms": duration
|
153 |
}
|
154 |
|
|
|
155 |
for local_extracted_archive_path, archive in zip(local_extracted_archive_paths, archives):
|
156 |
+
# Here we iterate over all the files within the TAR archive:
|
157 |
for audio_filename, audio_file in archive:
|
158 |
+
# if an audio file exists locally (i.e. in default, non-streaming mode) set the full path to it
|
159 |
+
# joining path to directory that the archive was extracted to and audio filename.
|
160 |
path = os.path.join(local_extracted_archive_path, audio_filename) if local_extracted_archive_path \
|
161 |
else audio_filename
|
162 |
yield audio_filename, {
|