# coding=utf-8 # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # TODO: Address all TODOs and remove all explanatory comments """TODO: Add a description here.""" import csv import json import os import datasets _CITATION = """\ @misc{cooper2021generalization, title={Generalization Ability of MOS Prediction Networks}, author={Erica Cooper and Wen-Chin Huang and Tomoki Toda and Junichi Yamagishi}, year={2021}, eprint={2110.02635}, archivePrefix={arXiv}, primaryClass={eess.AS} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ This dataset is for internal use only. For voicemos challenge """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "https://codalab.lisn.upsaclay.fr/competitions/695" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "INTERNAL" class BvccDataset(datasets.GeneratorBasedBuilder): """BVCC dataset for voicemos challenge 2022""" VERSION = datasets.Version("1.1.0") BUILDER_CONFIGS = [ datasets.BuilderConfig(name="main_track", version=VERSION, description="main track dataset by wavfiles"), datasets.BuilderConfig(name="main_track_listeners", version=VERSION, description="main track dataset by listener rating"), datasets.BuilderConfig(name="ood_track", version=VERSION, description="Out of domain dataset"), datasets.BuilderConfig(name="ood_track_unlabeled", version=VERSION, description="Out of domain dataset unlabeled"), datasets.BuilderConfig(name="ood_track_listeners", version=VERSION, description="ood track dataset by listener rating"), ] DEFAULT_CONFIG_NAME = "main_track" # It's not mandatory to have a default configuration. Just use one if it make sense. def _info(self): # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset if self.config.name == "main_track": # This is the name of the configuration selected in BUILDER_CONFIGS above features = datasets.Features( { "path": datasets.Value("string"), "audio" : datasets.Audio(sampling_rate=16_000), "sysID": datasets.Value("string"), "uttID": datasets.Value("string"), "averaged rating": datasets.Value("float32"), # These are the features of your dataset like images, labels ... } ) elif self.config.name == "main_track_listeners": # sysID,uttID,rating,ignore,listenerinfo # {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT features = datasets.Features( { "path": datasets.Value("string"), "audio" : datasets.Audio(sampling_rate=16_000), "sysID": datasets.Value("string"), "uttID": datasets.Value("string"), "rating": datasets.Value("int8"), "age range": datasets.Value("string"), "listener id": datasets.Value("string"), "gender": datasets.Value("string"), "hearing impairment": datasets.Value("string"), } ) elif self.config.name == "ood_track": # This is the name of the configuration selected in BUILDER_CONFIGS above features = datasets.Features( { "path": datasets.Value("string"), "audio" : datasets.Audio(sampling_rate=16_000), "sysID": datasets.Value("string"), "uttID": datasets.Value("string"), "averaged rating": datasets.Value("float32"), # These are the features of your dataset like images, labels ... } ) elif self.config.name == "ood_track_listeners": # sysID,uttID,rating,ignore,listenerinfo # {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT features = datasets.Features( { "path": datasets.Value("string"), "audio" : datasets.Audio(sampling_rate=16_000), "sysID": datasets.Value("string"), "uttID": datasets.Value("string"), "rating": datasets.Value("int8"), "age range": datasets.Value("string"), "listener id": datasets.Value("string"), "gender": datasets.Value("string"), "hearing impairment": datasets.Value("string"), } ) elif self.config.name == "ood_track_unlabeled": # sysID,uttID,rating,ignore,listenerinfo # {}_AGERANGE_LISTENERID_GENDER_[ignore]_[ignore]_HEARINGIMPAIRMENT features = datasets.Features( { "path": datasets.Value("string"), "audio" : datasets.Audio(sampling_rate=16_000), "sysID": datasets.Value("string"), "uttID": datasets.Value("string"), } ) else: raise ValueError(f"invalid config name {self.config.name}") return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLS # 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. # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive data_dir = self.config.data_dir if "listeners" in self.config.name: return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/TRAINSET"), "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/DEVSET"), "split": "dev", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/test.scp"), "split": "test", }, ), ] elif "unlabeled" in self.config.name: return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/unlabeled_mos_list.txt"), "split": "train", }, ), ] else: return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/train_mos_list.txt"), "split": "train", }, ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/val_mos_list.txt"), "split": "dev", }, ), datasets.SplitGenerator( name=datasets.Split.TEST, # These kwargs will be passed to _generate_examples gen_kwargs={ "filepath": os.path.join(data_dir,"DATA/sets/test.scp"), "split": "test", }, ), ] # method parameters are unpacked from `gen_kwargs` as given in `_split_generators` def _generate_examples(self, filepath, split): # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset. # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example. with open(filepath, encoding="utf-8") as f: for key, row in enumerate(f.readlines()): data = row.strip().split(',') if self.config.name == "main_track": sysID, uttID= data[0].split('-') uttID= uttID.replace('.wav', '') if len(data) > 1: score = data[1] else: score = 999 # Yields examples as (key, example) tuples path = os.path.join(self.config.data_dir, "DATA/wav/", data[0]) yield key, { "path": path, "audio": path, "sysID": sysID, "uttID": uttID, "averaged rating": score, } elif self.config.name == "main_track_listeners": if len(data) > 1: rating = data[1] sysID, path, rating, _, listenerinfo = data _, age, listenrID, gender, _ , _, hearingImpairement= listenerinfo.split("_") else: sysID, uttID= data[0].split('-') uttID= uttID.replace('.wav', '') rating = 999 age= 999 listenrID = 999 gender = 999 path = data[0] uttID = path.split('-')[-1] uttID = uttID.replace(".wav", "") path = os.path.join(self.config.data_dir, "DATA/wav/", path) yield key, { "path": path, "audio": path, "sysID": sysID, "uttID": uttID, "rating": rating, "age range": age, "listener id": listenrID, "gender": gender, "hearing impairment": hearingImpairement, } if self.config.name == "ood_track": sysID, uttID= data[0].split('-') uttID= uttID.replace('.wav', '') if len(data) > 1: score = data[1] else: score = 999 # Yields examples as (key, example) tuples path = os.path.join(self.config.data_dir, "DATA/wav/", data[0]) yield key, { "path": path, "audio": path, "sysID": sysID, "uttID": uttID, "averaged rating": score, } elif self.config.name == "ood_track_listeners": if len(data) > 1: rating = data[1] sysID, path, rating, _, listenerinfo = data _, age, listenrID, gender, _ , _, hearingImpairement= listenerinfo.split("_") else: sysID, uttID= data[0].split('-') uttID= uttID.replace('.wav', '') path = data[0] rating = 999 age= 999 listenrID = 999 gender = 999 uttID = path.split('-')[-1] uttID = uttID.replace(".wav", "") path = os.path.join(self.config.data_dir, "DATA/wav/", path) yield key, { "path": path, "audio": path, "sysID": sysID, "uttID": uttID, "rating": rating, "age range": age, "listener id": listenrID, "gender": gender, "hearing impairment": hearingImpairement, } if self.config.name == "ood_track_unlabeled": sysID, uttID= data[0].strip().split('-') uttID= uttID.replace('.wav', '') # Yields examples as (key, example) tuples path = os.path.join(self.config.data_dir, "DATA/wav/", data[0].strip()) yield key, { "path": path, "audio": path, "sysID": sysID, "uttID": uttID, }