root
commited on
Commit
•
4bcaf2a
1
Parent(s):
f789e31
full test
Browse files- data/vi/train_raw.tsv +1 -1
- gigaspeech2_metadata.py +164 -0
data/vi/train_raw.tsv
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
0-0-
|
2 |
0-0-1 fake label2
|
3 |
1-0-0 fake label3
|
4 |
1-0-1 fake label4
|
|
|
1 |
+
0-0-0 fake label1
|
2 |
0-0-1 fake label2
|
3 |
1-0-0 fake label3
|
4 |
1-0-1 fake label4
|
gigaspeech2_metadata.py
ADDED
@@ -0,0 +1,164 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from collections import OrderedDict
|
3 |
+
from pathlib import Path
|
4 |
+
import datasets
|
5 |
+
import glob
|
6 |
+
import os
|
7 |
+
|
8 |
+
from datasets.arrow_dataset import config
|
9 |
+
|
10 |
+
|
11 |
+
class Gigaspeech2Config(datasets.BuilderConfig):
|
12 |
+
"""BuilderConfig for Yodas."""
|
13 |
+
|
14 |
+
def __init__(self, config_name, version, **kwargs):
|
15 |
+
config_split = config_name.split("-")
|
16 |
+
self.language = config_split[0]
|
17 |
+
print(config_split)
|
18 |
+
self.split = config_split[1]
|
19 |
+
self.index = config_split[2] if len(config_split)>=3 else None
|
20 |
+
self.base_data_path = f"data/{self.language}"
|
21 |
+
|
22 |
+
description = (
|
23 |
+
f"Youtube speech to text dataset in {self.language}."
|
24 |
+
)
|
25 |
+
super(Gigaspeech2Config, self).__init__(
|
26 |
+
name=config_name,
|
27 |
+
version=datasets.Version(version),
|
28 |
+
description=description,
|
29 |
+
**kwargs,
|
30 |
+
)
|
31 |
+
|
32 |
+
|
33 |
+
DEFAULT_CONFIG_NAME = "all"
|
34 |
+
LANGS = ['id', 'th', 'vi']
|
35 |
+
LANGS_SPLITS={
|
36 |
+
"id":2,
|
37 |
+
"th":2,
|
38 |
+
"vi":2
|
39 |
+
}
|
40 |
+
VERSION = "1.0.1"
|
41 |
+
CONFIG_NAME=[]
|
42 |
+
for lang in LANGS:
|
43 |
+
CONFIG_NAME.append(f"{lang}-test")
|
44 |
+
CONFIG_NAME.append(f"{lang}-dev")
|
45 |
+
CONFIG_NAME.append(f"{lang}-train_raw")
|
46 |
+
CONFIG_NAME.append(f"{lang}-train_refine")
|
47 |
+
for i in range(LANGS_SPLITS[lang]):
|
48 |
+
CONFIG_NAME.append(f"{lang}-train_raw-{i}")
|
49 |
+
CONFIG_NAME.append(f"{lang}-train_refine-{i}")
|
50 |
+
|
51 |
+
class Gigaspeech2(datasets.GeneratorBasedBuilder):
|
52 |
+
"""Yodas dataset."""
|
53 |
+
|
54 |
+
BUILDER_CONFIGS = [
|
55 |
+
Gigaspeech2Config(config_name, version=VERSION) for config_name in CONFIG_NAME
|
56 |
+
]
|
57 |
+
|
58 |
+
VERSION = datasets.Version("1.0.1")
|
59 |
+
|
60 |
+
def _info(self):
|
61 |
+
return datasets.DatasetInfo(
|
62 |
+
description="Gigaspeech2",
|
63 |
+
features=datasets.Features(
|
64 |
+
OrderedDict(
|
65 |
+
[
|
66 |
+
# ("id", datasets.Value("string")),
|
67 |
+
# ("utt_id", datasets.Value("string")),
|
68 |
+
("audio", datasets.Audio(sampling_rate=16_000)),
|
69 |
+
("text", datasets.Value("string")),
|
70 |
+
]
|
71 |
+
)
|
72 |
+
),
|
73 |
+
supervised_keys=None,
|
74 |
+
homepage="", # TODO
|
75 |
+
citation="", # TODO
|
76 |
+
)
|
77 |
+
|
78 |
+
def _split_generators(self, dl_manager):
|
79 |
+
"""Returns SplitGenerators."""
|
80 |
+
# TODO
|
81 |
+
lang = self.config.language
|
82 |
+
split = self.config.split
|
83 |
+
index = self.config.index
|
84 |
+
if index is not None:
|
85 |
+
assert int(index)<LANGS_SPLITS[lang], f"split {self.config.name} not found"
|
86 |
+
|
87 |
+
text_file = dl_manager.download([f"{self.config.base_data_path}/{split}.tsv"])
|
88 |
+
if split == "test":
|
89 |
+
audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/{split}.tar.gz"])
|
90 |
+
elif split == "dev":
|
91 |
+
audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/{split}.tar.gz"])
|
92 |
+
elif index is not None:
|
93 |
+
audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/train/{index}.tar.gz"])
|
94 |
+
else:
|
95 |
+
audio_tar_files = dl_manager.download([f"{self.config.base_data_path}/train/{i}.tar.gz" for i in range(LANGS_SPLITS[lang])])
|
96 |
+
|
97 |
+
if dl_manager.is_streaming:
|
98 |
+
audio_archives = [dl_manager.iter_archive(audio_tar_file) for audio_tar_file in audio_tar_files]
|
99 |
+
|
100 |
+
else:
|
101 |
+
print("extracting audio ...")
|
102 |
+
extracted_audio_archives = dl_manager.extract(audio_tar_files)
|
103 |
+
|
104 |
+
audio_archives = []
|
105 |
+
for extracted_dir in extracted_audio_archives:
|
106 |
+
audio_archives.extend(glob.glob("{}/**/*.wav".format(str(extracted_dir)), recursive=True))
|
107 |
+
|
108 |
+
if split=="test":
|
109 |
+
dataset_split = datasets.Split.TEST
|
110 |
+
elif split=="dev":
|
111 |
+
dataset_split = datasets.Split.VALIDATION
|
112 |
+
else:
|
113 |
+
dataset_split = datasets.Split.TRAIN
|
114 |
+
|
115 |
+
return [
|
116 |
+
datasets.SplitGenerator(
|
117 |
+
name=dataset_split,
|
118 |
+
gen_kwargs={
|
119 |
+
"is_streaming": dl_manager.is_streaming,
|
120 |
+
"audio_archives": audio_archives,
|
121 |
+
'tsv_file': text_file[0],
|
122 |
+
},
|
123 |
+
),
|
124 |
+
]
|
125 |
+
|
126 |
+
def _generate_examples(self, is_streaming, audio_archives, tsv_file):
|
127 |
+
"""Yields examples."""
|
128 |
+
|
129 |
+
id_ = 0
|
130 |
+
|
131 |
+
with open(tsv_file, 'r') as f:
|
132 |
+
lines = f.read().splitlines()
|
133 |
+
lines = [line.split("\t") for line in lines]
|
134 |
+
id2label={line[0]:line[1] for line in lines}
|
135 |
+
|
136 |
+
if is_streaming:
|
137 |
+
for tar_file in audio_archives:
|
138 |
+
for path, audio_f in tar_file:
|
139 |
+
path = Path(path)
|
140 |
+
utt_id = path.stem
|
141 |
+
result = {
|
142 |
+
'id': id_,
|
143 |
+
'utt_id': utt_id,
|
144 |
+
'audio': {"path": None, "bytes": audio_f.read()},
|
145 |
+
'text': id2label[utt_id],
|
146 |
+
}
|
147 |
+
|
148 |
+
yield id_, result
|
149 |
+
id_ += 1
|
150 |
+
else:
|
151 |
+
print(id2label)
|
152 |
+
for audio_file in audio_archives:
|
153 |
+
utt_id = Path(audio_file).stem
|
154 |
+
result = {
|
155 |
+
'id': id_,
|
156 |
+
'utt_id': utt_id,
|
157 |
+
'audio': {"path": audio_file, "bytes": open(audio_file, 'rb').read()},
|
158 |
+
'text': id2label[utt_id]
|
159 |
+
}
|
160 |
+
|
161 |
+
yield id_, result
|
162 |
+
id_ += 1
|
163 |
+
|
164 |
+
|