import csv import os import datasets import pandas as pd from datasets import Split # Metadata _DESCRIPTION = """\ Mumospee is a continuously growing, comprehensive, multilingual dataset across different modalities. This is the small version include no more 1000 rows. """ _LICENSE = "cc0-1.0" _LANGUAGES = ["en", "bg", "de", "ar", "fr"] _TAGS = ["CoVoST", "GigaSpeech", "PeopleSpeech", "Librispeech", "LibriTTS", "Emilia", "MOSEL"] _SPLITS = ["train", "validation", "test"] # BuilderConfig class for your dataset class MumospeeDatasetConfig(datasets.BuilderConfig): def __init__(self, name, download_audio=None, language=None, tag=None, **kwargs): super().__init__(**kwargs) self.name = name self.language = language self.tag = tag self.download_audio = download_audio class MumospeeDataset(datasets.GeneratorBasedBuilder): VERSION = datasets.Version("1.0.0") # Define the available configurations (could be subsets like split or language) BUILDER_CONFIGS = [ MumospeeDatasetConfig( version=datasets.Version("1.0.0"), description=_DESCRIPTION, name="train", download_audio=None, language=None, tag=None ), MumospeeDatasetConfig( version=datasets.Version("1.0.0"), description=_DESCRIPTION, name="test", download_audio=None, language=None, tag=None ), MumospeeDatasetConfig( version=datasets.Version("1.0.0"), description=_DESCRIPTION, name="validation", download_audio=None, language=None, tag=None ) ] DEFAULT_CONFIG_NAME = "train" def _info(self): # Define the features of your dataset features = datasets.Features({ "path": datasets.Value("string"), "url": datasets.Value("string"), "type": datasets.Value("string"), "duration": datasets.Value("string"), "language": datasets.Value("string"), "transcript": datasets.Value("string"), "tag": datasets.Value("string"), "split": datasets.Value("string"), "license": datasets.Value("string") }) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, license=_LICENSE, ) def _adapt_args(self, arg, accepted_arg): """ Adpat the input and make sure it outs as list and all the elements within the list are accpeted. """ if arg: if isinstance(arg, str): adapted_arg = [arg] else: adapted_arg = arg for aa in adapted_arg: if aa not in accepted_arg: raise ValueError(f"Invalid input: '{aa}'. Accepted values are: {', '.join(accepted_arg)}.") else: adapted_arg = accepted_arg return adapted_arg def _split_generators(self, dl_manager): csv_path = dl_manager.download_and_extract("dataset.csv") if self.config.name==None: return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={"filepath": csv_path, "dl_manager": dl_manager} ), datasets.SplitGenerator( name=datasets.Split.VALIDATION, gen_kwargs={"filepath": csv_path, "dl_manager": dl_manager} ), datasets.SplitGenerator( name=datasets.Split.TEST, gen_kwargs={"filepath": csv_path, "dl_manager": dl_manager} ), ] else: return [ datasets.SplitGenerator( name = getattr(Split, self.config.name.upper()), gen_kwargs={"filepath": csv_path, "dl_manager": dl_manager} ), ] def _generate_examples(self, filepath, dl_manager): data = pd.read_csv(filepath) name = self.config.name language = self.config.language tag = self.config.tag download_audio = self.config.download_audio all_splits=[] # If split is None, generate examples for all splits if name is None: all_splits = _SPLITS else: all_splits = [name] print(f"Split input is {name}, so get split of {all_splits}.") # Split base on name split train, test, validation. data_split = data[data["split"]==name] if data_split.empty: print(f"No data found for split='{name}'. Skipping this split.") return # Split based on tags. if tag is not None: tag_list = self._adapt_args(tag, _TAGS) data_split = data_split[data_split["tag"].isin(tag_list)] else: print(f"No specific tag provided, including all tags in split='{name}', language='{language or 'all'}'.") # split based on language. if language is not None: language_list = self._adapt_args(language, _LANGUAGES) data_split = data_split[data_split["language"].isin(language_list)] else: print(f"No specific language provided, including all languages in split='{name}', tag='{tag or 'all'}'.") if data_split.empty: print(f"No data found for split='{name}', language='{language}', tag='{tag}'. Skip this one.") return # Generate examples for i, row in data_split.iterrows(): # download the url file if download_audio: external_url = row["url"] dl_manager.download(external_url) yield i, { "path": row["path"], #"local_path": row["local_path"], "url": row["url"], "type": row["type"], "duration": float(row["duration"]), "language": row["language"], "transcript": row["transcript"], "tag": row["tag"], "split": row["split"], "license": row["license"] }