Datasets:
License:
File size: 6,380 Bytes
05da4fa 734c8eb 927b3bd 99901de 734c8eb 05da4fa 734c8eb 05da4fa 4f3b886 05da4fa aa6b49f 6663a58 57ad8b5 05da4fa 1b9fccd 6720bec c712e3e 6720bec 7f02aff 0b40ec6 7f02aff 6663a58 1b9fccd 05da4fa 927b3bd 21e571a fab0268 0b40ec6 224edaa 09e946b 927b3bd fab0268 734c8eb 05da4fa 21e571a 05da4fa 734c8eb 05da4fa 734c8eb 21e571a 421aac0 7f02aff c55b167 7f02aff c55b167 7f02aff 21e571a 734c8eb 927b3bd f2fe1c2 6d32bc3 99901de 6720bec 68934f5 6720bec 68934f5 6720bec 68934f5 6720bec 99901de 6720bec 68934f5 6720bec 927b3bd 6663a58 d4ce4be 6663a58 795f52c d4ce4be 06d9173 0b40ec6 6f2769e 6720bec 8387f24 6720bec 6663a58 74cf219 6720bec 74cf219 420f11e 74cf219 ee6d1f9 99901de 6720bec 74cf219 0982e8c 74cf219 0982e8c 6720bec 927b3bd 1b9fccd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
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"]
}
|