Datasets:

Modalities:
Audio
Text
ArXiv:
Libraries:
Datasets
License:
File size: 3,267 Bytes
9f6d2ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import glob

import datasets


_LANGUAGES = sorted(
    [
        "en", "de", "fr", "es", "pl", "it", "ro", "hu", "cs", "nl", "fi", "hr",
        "sk", "sl", "et", "lt", "pt", "bg", "el", "lv", "mt", "sv", "da"
    ]
)
_LANGUAGES_V2 = [f"{x}_v2" for x in _LANGUAGES]

_YEARS = list(range(2009, 2020 + 1))

_CONFIG_TO_LANGS = {
    "400k": _LANGUAGES,
    "100k": _LANGUAGES,
    "10k": _LANGUAGES,
}

_CONFIG_TO_YEARS = {
    "400k": _YEARS + [f"{y}_2" for y in _YEARS],
    "100k": _YEARS,
    "10k": [2019, 2020],
    # "asr": _YEARS
}
for lang in _LANGUAGES:
    _CONFIG_TO_YEARS[lang] = _YEARS

_BASE_URL = "https://dl.fbaipublicfiles.com/voxpopuli/"

_DATA_URL = _BASE_URL + "audios/{lang}_{year}.tar"

_META_URL = _BASE_URL + "https://dl.fbaipublicfiles.com/voxpopuli/annotations/unlabelled_v2.tsv.gz"


class Voxpopuli(datasets.GeneratorBasedBuilder):
    """The Voxpopuli dataset."""

    VERSION = datasets.Version("1.0.0")  # TODO ??
    BUILDER_CONFIGS = [
        datasets.BuilderConfig(
            name=name,
            # version=VERSION,
            description="",  # TODO
            )
        for name in _LANGUAGES + ["10k", "100k", "400k"]
    ]
    # DEFAULT_CONFIG_NAME = "400k"
    # DEFAULT_WRITER_BATCH_SIZE = 1

    def _info(self):
        features = datasets.Features(
            {
                "path": datasets.Value("string"),
                "language": datasets.ClassLabel(names=_LANGUAGES),
                "year": datasets.Value("int16"),
                "audio": datasets.Audio(sampling_rate=16_000),
            }
        )
        return datasets.DatasetInfo(
            # description=_DESCRIPTION,
            features=features,
            # homepage=_HOMEPAGE,
            # license=_LICENSE,
            # citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        # dl_manager.download_config.num_proc = len(_VOXPOPULI_AUDIO_URLS)  # TODO

        # metadata_path = dl_manager.download_and_extract(_META_URL)

        languages = [self.config.name] if self.config.name in _LANGUAGES else _LANGUAGES
        years = _CONFIG_TO_YEARS[self.config.name]
        # urls = [_DATA_URL.format(lang=language, year=year) for language in ["hr", "et"] for year in [2020]]
        urls = [_DATA_URL.format(lang=language, year=year) for language in languages for year in years]

        langs_data_dirs = dl_manager.download_and_extract(urls)
        print(langs_data_dirs)
        print(glob.glob(f"{langs_data_dirs[0]}/**/*.ogg", recursive=True))

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "data_dirs": langs_data_dirs,
                }
            ),
        ]

    def _generate_examples(self, data_dirs):
        for data_dir in data_dirs:
            for file in glob.glob(f"{data_dir}/**/*.ogg", recursive=True):
                path_components = file.split(os.sep)
                language, year = path_components[-3:-1]
                with open(file) as f:
                    yield file, {
                        "path": file,
                        "language": language,
                        "year": year,
                        "audio": {"path": file}
                    }