polinaeterna
commited on
Commit
·
9f6d2ae
1
Parent(s):
0d68a0f
simple version of script
Browse files- voxpopuli.py +105 -0
voxpopuli.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import glob
|
| 3 |
+
|
| 4 |
+
import datasets
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_LANGUAGES = sorted(
|
| 8 |
+
[
|
| 9 |
+
"en", "de", "fr", "es", "pl", "it", "ro", "hu", "cs", "nl", "fi", "hr",
|
| 10 |
+
"sk", "sl", "et", "lt", "pt", "bg", "el", "lv", "mt", "sv", "da"
|
| 11 |
+
]
|
| 12 |
+
)
|
| 13 |
+
_LANGUAGES_V2 = [f"{x}_v2" for x in _LANGUAGES]
|
| 14 |
+
|
| 15 |
+
_YEARS = list(range(2009, 2020 + 1))
|
| 16 |
+
|
| 17 |
+
_CONFIG_TO_LANGS = {
|
| 18 |
+
"400k": _LANGUAGES,
|
| 19 |
+
"100k": _LANGUAGES,
|
| 20 |
+
"10k": _LANGUAGES,
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
_CONFIG_TO_YEARS = {
|
| 24 |
+
"400k": _YEARS + [f"{y}_2" for y in _YEARS],
|
| 25 |
+
"100k": _YEARS,
|
| 26 |
+
"10k": [2019, 2020],
|
| 27 |
+
# "asr": _YEARS
|
| 28 |
+
}
|
| 29 |
+
for lang in _LANGUAGES:
|
| 30 |
+
_CONFIG_TO_YEARS[lang] = _YEARS
|
| 31 |
+
|
| 32 |
+
_BASE_URL = "https://dl.fbaipublicfiles.com/voxpopuli/"
|
| 33 |
+
|
| 34 |
+
_DATA_URL = _BASE_URL + "audios/{lang}_{year}.tar"
|
| 35 |
+
|
| 36 |
+
_META_URL = _BASE_URL + "https://dl.fbaipublicfiles.com/voxpopuli/annotations/unlabelled_v2.tsv.gz"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
class Voxpopuli(datasets.GeneratorBasedBuilder):
|
| 40 |
+
"""The Voxpopuli dataset."""
|
| 41 |
+
|
| 42 |
+
VERSION = datasets.Version("1.0.0") # TODO ??
|
| 43 |
+
BUILDER_CONFIGS = [
|
| 44 |
+
datasets.BuilderConfig(
|
| 45 |
+
name=name,
|
| 46 |
+
# version=VERSION,
|
| 47 |
+
description="", # TODO
|
| 48 |
+
)
|
| 49 |
+
for name in _LANGUAGES + ["10k", "100k", "400k"]
|
| 50 |
+
]
|
| 51 |
+
# DEFAULT_CONFIG_NAME = "400k"
|
| 52 |
+
# DEFAULT_WRITER_BATCH_SIZE = 1
|
| 53 |
+
|
| 54 |
+
def _info(self):
|
| 55 |
+
features = datasets.Features(
|
| 56 |
+
{
|
| 57 |
+
"path": datasets.Value("string"),
|
| 58 |
+
"language": datasets.ClassLabel(names=_LANGUAGES),
|
| 59 |
+
"year": datasets.Value("int16"),
|
| 60 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
| 61 |
+
}
|
| 62 |
+
)
|
| 63 |
+
return datasets.DatasetInfo(
|
| 64 |
+
# description=_DESCRIPTION,
|
| 65 |
+
features=features,
|
| 66 |
+
# homepage=_HOMEPAGE,
|
| 67 |
+
# license=_LICENSE,
|
| 68 |
+
# citation=_CITATION,
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
def _split_generators(self, dl_manager):
|
| 72 |
+
# dl_manager.download_config.num_proc = len(_VOXPOPULI_AUDIO_URLS) # TODO
|
| 73 |
+
|
| 74 |
+
# metadata_path = dl_manager.download_and_extract(_META_URL)
|
| 75 |
+
|
| 76 |
+
languages = [self.config.name] if self.config.name in _LANGUAGES else _LANGUAGES
|
| 77 |
+
years = _CONFIG_TO_YEARS[self.config.name]
|
| 78 |
+
# urls = [_DATA_URL.format(lang=language, year=year) for language in ["hr", "et"] for year in [2020]]
|
| 79 |
+
urls = [_DATA_URL.format(lang=language, year=year) for language in languages for year in years]
|
| 80 |
+
|
| 81 |
+
langs_data_dirs = dl_manager.download_and_extract(urls)
|
| 82 |
+
print(langs_data_dirs)
|
| 83 |
+
print(glob.glob(f"{langs_data_dirs[0]}/**/*.ogg", recursive=True))
|
| 84 |
+
|
| 85 |
+
return [
|
| 86 |
+
datasets.SplitGenerator(
|
| 87 |
+
name=datasets.Split.TRAIN,
|
| 88 |
+
gen_kwargs={
|
| 89 |
+
"data_dirs": langs_data_dirs,
|
| 90 |
+
}
|
| 91 |
+
),
|
| 92 |
+
]
|
| 93 |
+
|
| 94 |
+
def _generate_examples(self, data_dirs):
|
| 95 |
+
for data_dir in data_dirs:
|
| 96 |
+
for file in glob.glob(f"{data_dir}/**/*.ogg", recursive=True):
|
| 97 |
+
path_components = file.split(os.sep)
|
| 98 |
+
language, year = path_components[-3:-1]
|
| 99 |
+
with open(file) as f:
|
| 100 |
+
yield file, {
|
| 101 |
+
"path": file,
|
| 102 |
+
"language": language,
|
| 103 |
+
"year": year,
|
| 104 |
+
"audio": {"path": file}
|
| 105 |
+
}
|