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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
# TODO: Address all TODOs and remove all explanatory comments
|
16 |
+
"""TODO: Add a description here."""
|
17 |
+
|
18 |
+
|
19 |
+
import csv
|
20 |
+
import json
|
21 |
+
import os
|
22 |
+
|
23 |
+
import datasets
|
24 |
+
|
25 |
+
_CITATION = """\
|
26 |
+
@misc{cooper2021generalization,
|
27 |
+
title={Generalization Ability of MOS Prediction Networks},
|
28 |
+
author={Erica Cooper and Wen-Chin Huang and Tomoki Toda and Junichi Yamagishi},
|
29 |
+
year={2021},
|
30 |
+
eprint={2110.02635},
|
31 |
+
archivePrefix={arXiv},
|
32 |
+
primaryClass={eess.AS}
|
33 |
+
}
|
34 |
+
"""
|
35 |
+
|
36 |
+
# TODO: Add description of the dataset here
|
37 |
+
# You can copy an official description
|
38 |
+
_DESCRIPTION = """\
|
39 |
+
This dataset is for internal use only. For voicemos challenge
|
40 |
+
"""
|
41 |
+
|
42 |
+
# TODO: Add a link to an official homepage for the dataset here
|
43 |
+
_HOMEPAGE = "https://codalab.lisn.upsaclay.fr/competitions/695"
|
44 |
+
|
45 |
+
# TODO: Add the licence for the dataset here if you can find it
|
46 |
+
_LICENSE = "INTERNAL"
|
47 |
+
|
48 |
+
|
49 |
+
class BvccDataset(datasets.GeneratorBasedBuilder):
|
50 |
+
"""BVCC dataset for voicemos challenge 2022"""
|
51 |
+
|
52 |
+
VERSION = datasets.Version("1.1.0")
|
53 |
+
|
54 |
+
BUILDER_CONFIGS = [
|
55 |
+
datasets.BuilderConfig(
|
56 |
+
name="main_track",
|
57 |
+
version=VERSION,
|
58 |
+
description="main track dataset by wavfiles",
|
59 |
+
),
|
60 |
+
datasets.BuilderConfig(
|
61 |
+
name="main_track_listeners",
|
62 |
+
version=VERSION,
|
63 |
+
description="main track dataset by listener rating",
|
64 |
+
),
|
65 |
+
datasets.BuilderConfig(
|
66 |
+
name="ood_track", version=VERSION, description="Out of domain dataset"
|
67 |
+
),
|
68 |
+
datasets.BuilderConfig(
|
69 |
+
name="ood_track_unlabeled",
|
70 |
+
version=VERSION,
|
71 |
+
description="Out of domain dataset unlabeled",
|
72 |
+
),
|
73 |
+
datasets.BuilderConfig(
|
74 |
+
name="ood_track_listeners",
|
75 |
+
version=VERSION,
|
76 |
+
description="ood track dataset by listener rating",
|
77 |
+
),
|
78 |
+
]
|
79 |
+
|
80 |
+
DEFAULT_CONFIG_NAME = "main_track" # It's not mandatory to have a default configuration. Just use one if it make sense.
|
81 |
+
|
82 |
+
def _info(self):
|
83 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
84 |
+
if (
|
85 |
+
self.config.name == "main_track"
|
86 |
+
): # This is the name of the configuration selected in BUILDER_CONFIGS above
|
87 |
+
features = datasets.Features(
|
88 |
+
{
|
89 |
+
"path": datasets.Value("string"),
|
90 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
91 |
+
"sysID": datasets.Value("string"),
|
92 |
+
"uttID": datasets.Value("string"),
|
93 |
+
"averaged rating": datasets.Value("float32"),
|
94 |
+
# These are the features of your dataset like images, labels ...
|
95 |
+
}
|
96 |
+
)
|
97 |
+
elif self.config.name == "main_track_listeners":
|
98 |
+
# sysID,uttID,rating,ignore,listenerinfo
|
99 |
+
# {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT
|
100 |
+
features = datasets.Features(
|
101 |
+
{
|
102 |
+
"path": datasets.Value("string"),
|
103 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
104 |
+
"sysID": datasets.Value("string"),
|
105 |
+
"uttID": datasets.Value("string"),
|
106 |
+
"rating": datasets.Value("int8"),
|
107 |
+
"age range": datasets.Value("string"),
|
108 |
+
"listener id": datasets.Value("string"),
|
109 |
+
"gender": datasets.Value("string"),
|
110 |
+
"hearing impairment": datasets.Value("string"),
|
111 |
+
}
|
112 |
+
)
|
113 |
+
elif (
|
114 |
+
self.config.name == "ood_track"
|
115 |
+
): # This is the name of the configuration selected in BUILDER_CONFIGS above
|
116 |
+
features = datasets.Features(
|
117 |
+
{
|
118 |
+
"path": datasets.Value("string"),
|
119 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
120 |
+
"sysID": datasets.Value("string"),
|
121 |
+
"uttID": datasets.Value("string"),
|
122 |
+
"averaged rating": datasets.Value("float32"),
|
123 |
+
# These are the features of your dataset like images, labels ...
|
124 |
+
}
|
125 |
+
)
|
126 |
+
elif self.config.name == "ood_track_listeners":
|
127 |
+
# sysID,uttID,rating,ignore,listenerinfo
|
128 |
+
# {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT
|
129 |
+
features = datasets.Features(
|
130 |
+
{
|
131 |
+
"path": datasets.Value("string"),
|
132 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
133 |
+
"sysID": datasets.Value("string"),
|
134 |
+
"uttID": datasets.Value("string"),
|
135 |
+
"rating": datasets.Value("int8"),
|
136 |
+
"age range": datasets.Value("string"),
|
137 |
+
"listener id": datasets.Value("string"),
|
138 |
+
"gender": datasets.Value("string"),
|
139 |
+
"hearing impairment": datasets.Value("string"),
|
140 |
+
}
|
141 |
+
)
|
142 |
+
elif self.config.name == "ood_track_unlabeled":
|
143 |
+
# sysID,uttID,rating,ignore,listenerinfo
|
144 |
+
# {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT
|
145 |
+
features = datasets.Features(
|
146 |
+
{
|
147 |
+
"path": datasets.Value("string"),
|
148 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
149 |
+
"sysID": datasets.Value("string"),
|
150 |
+
"uttID": datasets.Value("string"),
|
151 |
+
}
|
152 |
+
)
|
153 |
+
else:
|
154 |
+
raise ValueError(f"invalid config name {self.config.name}")
|
155 |
+
return datasets.DatasetInfo(
|
156 |
+
description=_DESCRIPTION,
|
157 |
+
features=features,
|
158 |
+
homepage=_HOMEPAGE,
|
159 |
+
license=_LICENSE,
|
160 |
+
citation=_CITATION,
|
161 |
+
)
|
162 |
+
|
163 |
+
def _split_generators(self, dl_manager):
|
164 |
+
# TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
|
165 |
+
# If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
|
166 |
+
|
167 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS
|
168 |
+
# It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
|
169 |
+
# By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
|
170 |
+
data_dir = self.config.data_dir
|
171 |
+
if "listeners" in self.config.name:
|
172 |
+
return [
|
173 |
+
datasets.SplitGenerator(
|
174 |
+
name=datasets.Split.TRAIN,
|
175 |
+
# These kwargs will be passed to _generate_examples
|
176 |
+
gen_kwargs={
|
177 |
+
"filepath": os.path.join(data_dir, "DATA/sets/TRAINSET"),
|
178 |
+
"split": "train",
|
179 |
+
},
|
180 |
+
),
|
181 |
+
datasets.SplitGenerator(
|
182 |
+
name=datasets.Split.VALIDATION,
|
183 |
+
# These kwargs will be passed to _generate_examples
|
184 |
+
gen_kwargs={
|
185 |
+
"filepath": os.path.join(data_dir, "DATA/sets/DEVSET"),
|
186 |
+
"split": "dev",
|
187 |
+
},
|
188 |
+
),
|
189 |
+
datasets.SplitGenerator(
|
190 |
+
name=datasets.Split.TEST,
|
191 |
+
# These kwargs will be passed to _generate_examples
|
192 |
+
gen_kwargs={
|
193 |
+
"filepath": os.path.join(data_dir, "DATA/sets/TESTSET"),
|
194 |
+
"split": "test",
|
195 |
+
},
|
196 |
+
),
|
197 |
+
]
|
198 |
+
elif "unlabeled" in self.config.name:
|
199 |
+
return [
|
200 |
+
datasets.SplitGenerator(
|
201 |
+
name=datasets.Split.TRAIN,
|
202 |
+
# These kwargs will be passed to _generate_examples
|
203 |
+
gen_kwargs={
|
204 |
+
"filepath": os.path.join(
|
205 |
+
data_dir, "DATA/sets/unlabeled_mos_list.txt"
|
206 |
+
),
|
207 |
+
"split": "train",
|
208 |
+
},
|
209 |
+
),
|
210 |
+
]
|
211 |
+
else:
|
212 |
+
return [
|
213 |
+
datasets.SplitGenerator(
|
214 |
+
name=datasets.Split.TRAIN,
|
215 |
+
# These kwargs will be passed to _generate_examples
|
216 |
+
gen_kwargs={
|
217 |
+
"filepath": os.path.join(
|
218 |
+
data_dir, "DATA/sets/train_mos_list.txt"
|
219 |
+
),
|
220 |
+
"split": "train",
|
221 |
+
},
|
222 |
+
),
|
223 |
+
datasets.SplitGenerator(
|
224 |
+
name=datasets.Split.VALIDATION,
|
225 |
+
# These kwargs will be passed to _generate_examples
|
226 |
+
gen_kwargs={
|
227 |
+
"filepath": os.path.join(
|
228 |
+
data_dir, "DATA/sets/val_mos_list.txt"
|
229 |
+
),
|
230 |
+
"split": "dev",
|
231 |
+
},
|
232 |
+
),
|
233 |
+
datasets.SplitGenerator(
|
234 |
+
name=datasets.Split.TEST,
|
235 |
+
# These kwargs will be passed to _generate_examples
|
236 |
+
gen_kwargs={
|
237 |
+
"filepath": os.path.join(data_dir, "DATA/sets/TESTSET"),
|
238 |
+
"split": "test",
|
239 |
+
},
|
240 |
+
),
|
241 |
+
]
|
242 |
+
|
243 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
244 |
+
def _generate_examples(self, filepath, split):
|
245 |
+
# TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
|
246 |
+
# The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
|
247 |
+
with open(filepath, encoding="utf-8") as f:
|
248 |
+
for key, row in enumerate(f.readlines()):
|
249 |
+
data = row.strip().split(",")
|
250 |
+
if self.config.name == "main_track":
|
251 |
+
sysID, uttID = data[0].split("-")
|
252 |
+
uttID = uttID.replace(".wav", "")
|
253 |
+
if len(data) > 1:
|
254 |
+
score = data[1]
|
255 |
+
else:
|
256 |
+
score = 999
|
257 |
+
# Yields examples as (key, example) tuples
|
258 |
+
path = os.path.join(self.config.data_dir, "DATA/wav/", data[0])
|
259 |
+
yield key, {
|
260 |
+
"path": path,
|
261 |
+
"audio": path,
|
262 |
+
"sysID": sysID,
|
263 |
+
"uttID": uttID,
|
264 |
+
"averaged rating": score,
|
265 |
+
}
|
266 |
+
elif self.config.name == "main_track_listeners":
|
267 |
+
if len(data) > 1:
|
268 |
+
rating = data[1]
|
269 |
+
sysID, path, rating, _, listenerinfo = data
|
270 |
+
_, age, listenrID, gender, _, _, hearingImpairement = (
|
271 |
+
listenerinfo.split("_")
|
272 |
+
)
|
273 |
+
else:
|
274 |
+
sysID, uttID = data[0].split("-")
|
275 |
+
uttID = uttID.replace(".wav", "")
|
276 |
+
rating = 999
|
277 |
+
age = 999
|
278 |
+
listenrID = 999
|
279 |
+
gender = 999
|
280 |
+
path = data[0]
|
281 |
+
uttID = path.split("-")[-1]
|
282 |
+
uttID = uttID.replace(".wav", "")
|
283 |
+
path = os.path.join(self.config.data_dir, "DATA/wav/", path)
|
284 |
+
yield key, {
|
285 |
+
"path": path,
|
286 |
+
"audio": path,
|
287 |
+
"sysID": sysID,
|
288 |
+
"uttID": uttID,
|
289 |
+
"rating": rating,
|
290 |
+
"age range": age,
|
291 |
+
"listener id": listenrID,
|
292 |
+
"gender": gender,
|
293 |
+
"hearing impairment": hearingImpairement,
|
294 |
+
}
|
295 |
+
if self.config.name == "ood_track":
|
296 |
+
sysID, uttID = data[0].split("-")
|
297 |
+
uttID = uttID.replace(".wav", "")
|
298 |
+
if len(data) > 1:
|
299 |
+
score = data[1]
|
300 |
+
else:
|
301 |
+
score = 999
|
302 |
+
# Yields examples as (key, example) tuples
|
303 |
+
path = os.path.join(self.config.data_dir, "DATA/wav/", data[0])
|
304 |
+
yield key, {
|
305 |
+
"path": path,
|
306 |
+
"audio": path,
|
307 |
+
"sysID": sysID,
|
308 |
+
"uttID": uttID,
|
309 |
+
"averaged rating": score,
|
310 |
+
}
|
311 |
+
elif self.config.name == "ood_track_listeners":
|
312 |
+
if len(data) > 1:
|
313 |
+
rating = data[1]
|
314 |
+
sysID, path, rating, _, listenerinfo = data
|
315 |
+
_, age, listenrID, gender, _, _, hearingImpairement = (
|
316 |
+
listenerinfo.split("_")
|
317 |
+
)
|
318 |
+
else:
|
319 |
+
sysID, uttID = data[0].split("-")
|
320 |
+
uttID = uttID.replace(".wav", "")
|
321 |
+
path = data[0]
|
322 |
+
rating = 999
|
323 |
+
age = 999
|
324 |
+
listenrID = 999
|
325 |
+
gender = 999
|
326 |
+
uttID = path.split("-")[-1]
|
327 |
+
uttID = uttID.replace(".wav", "")
|
328 |
+
path = os.path.join(self.config.data_dir, "DATA/wav/", path)
|
329 |
+
yield key, {
|
330 |
+
"path": path,
|
331 |
+
"audio": path,
|
332 |
+
"sysID": sysID,
|
333 |
+
"uttID": uttID,
|
334 |
+
"rating": rating,
|
335 |
+
"age range": age,
|
336 |
+
"listener id": listenrID,
|
337 |
+
"gender": gender,
|
338 |
+
"hearing impairment": hearingImpairement,
|
339 |
+
}
|
340 |
+
if self.config.name == "ood_track_unlabeled":
|
341 |
+
sysID, uttID = data[0].strip().split("-")
|
342 |
+
uttID = uttID.replace(".wav", "")
|
343 |
+
# Yields examples as (key, example) tuples
|
344 |
+
path = os.path.join(
|
345 |
+
self.config.data_dir, "DATA/wav/", data[0].strip()
|
346 |
+
)
|
347 |
+
yield key, {
|
348 |
+
"path": path,
|
349 |
+
"audio": path,
|
350 |
+
"sysID": sysID,
|
351 |
+
"uttID": uttID,
|
352 |
+
}
|