HugoLaurencon HF staff commited on
Commit
7a80915
1 Parent(s): d7f8aa9

first commit

Browse files
Files changed (1) hide show
  1. libri_light.py +142 -0
libri_light.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2021 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """Libri-Light audio dataset."""
18
+
19
+
20
+ import json
21
+
22
+ import datasets
23
+
24
+
25
+ _CITATION = """\
26
+ @INPROCEEDINGS{librilight,
27
+ author={J. Kahn and M. Rivière and W. Zheng and E. Kharitonov and Q. Xu and P. E. Mazaré and J. Karadayi and V. Liptchinsky and R. Collobert and C. Fuegen and T. Likhomanenko and G. Synnaeve and A. Joulin and A. Mohamed and E. Dupoux},
28
+ booktitle={ICASSP 2020 - 2020 IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP)},
29
+ title={Libri-Light: A Benchmark for ASR with Limited or No Supervision},
30
+ year={2020},
31
+ pages={7669-7673},
32
+ note = {\url{https://github.com/facebookresearch/libri-light}},
33
+ }
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ Libri-light is a large dataset of 60K hours of unlabelled speech from audiobooks in English.
39
+ It is a benchmark for the training of automatic speech recognition (ASR) systems with limited or no supervision.
40
+ """
41
+
42
+ _HOMEPAGE = "https://ai.facebook.com/tools/libri-light/"
43
+
44
+ _LICENSE = """\
45
+ MIT License
46
+
47
+ Copyright (c) Facebook, Inc. and its affiliates.
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining a copy
50
+ of this software and associated documentation files (the "Software"), to deal
51
+ in the Software without restriction, including without limitation the rights
52
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
53
+ copies of the Software, and to permit persons to whom the Software is
54
+ furnished to do so, subject to the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be included in all
57
+ copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
60
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
61
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
62
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
63
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
64
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
65
+ SOFTWARE.
66
+ """
67
+
68
+ _DL_URL = "https://dl.fbaipublicfiles.com/librilight/data/{name}.tar"
69
+
70
+
71
+ class LibriLightConfig(datasets.BuilderConfig):
72
+ """BuilderConfig for Libri-Light."""
73
+
74
+ def __init__(self, **kwargs):
75
+ super(LibriLightConfig, self).__init__(version=datasets.Version("2.1.0", ""), **kwargs)
76
+
77
+
78
+ class LibriLight(datasets.GeneratorBasedBuilder):
79
+ """Libri-Light dataset."""
80
+
81
+ BUILDER_CONFIGS = [
82
+ LibriLightConfig(name="small", description="577 hours, 35 GB."),
83
+ LibriLightConfig(name="medium", description="5193 hours, 321 GB."),
84
+ LibriLightConfig(name="large", description="51934 hours, 3.05 TB."),
85
+ ]
86
+
87
+ def _info(self):
88
+ features = datasets.Features(
89
+ {
90
+ "id": datasets.Value("string"),
91
+ "file": datasets.Value("string"),
92
+ "audio": datasets.Audio(sampling_rate=16_000),
93
+ "speaker_id": datasets.Value("int64"),
94
+ "metadata": datasets.Value("dict"),
95
+ }
96
+ )
97
+
98
+ return datasets.DatasetInfo(
99
+ description=_DESCRIPTION,
100
+ features=features,
101
+ homepage=_HOMEPAGE,
102
+ license=_LICENSE,
103
+ citation=_CITATION,
104
+ )
105
+
106
+ def _split_generators(self, dl_manager):
107
+ archive_path = dl_manager.download(_DL_URL.format(name=self.config.name))
108
+ # (Optional) In non-streaming mode, we can extract the archive locally to have actual local audio files:
109
+ local_extracted_archive = dl_manager.extract(archive_path) if not dl_manager.is_streaming else {}
110
+
111
+ return [
112
+ datasets.SplitGenerator(
113
+ name=datasets.Split.TRAIN,
114
+ gen_kwargs={
115
+ "local_extracted_archive": local_extracted_archive.get("f{self.config.name}_train"),
116
+ "files": dl_manager.iter_archive(archive_path["f{self.config.name}_train"]),
117
+ },
118
+ ),
119
+ ]
120
+
121
+ def _generate_examples(self, files, local_extracted_archive):
122
+ """Generate examples from a Libri-Light archive_path."""
123
+ key = 0
124
+ for path, f in files:
125
+ if path.endswith(".flac"):
126
+ path_split = path.split("/")
127
+ audio_file = path._split[-1]
128
+ id_ = audio_file.replace(".flac", "")
129
+ file = path if local_extracted_archive else audio_file
130
+ audio = {"path": file, "bytes": f.read()}
131
+ speaker_id = int(path_split[-2])
132
+ path_json = path.replace(".flac", ".json")
133
+ with open(path_json) as json_file:
134
+ metadata = json.load(json_file)
135
+ yield key, {
136
+ "id": id_,
137
+ "file": file,
138
+ "audio": audio,
139
+ "speaker_id": speaker_id,
140
+ "metadata": metadata,
141
+ }
142
+ key += 1