Datasets:

Languages:
Vietnamese
ArXiv:
License:
holylovenia commited on
Commit
f5bf8b6
1 Parent(s): 12e58e2

Upload bud500.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. bud500.py +174 -0
bud500.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The HuggingFace Datasets Authors and the current dataset script contributor.
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
+ from pathlib import Path
17
+ from typing import Dict, List, Tuple
18
+
19
+ import datasets
20
+ from huggingface_hub import HfFileSystem
21
+ from pyarrow import parquet as pq
22
+
23
+ from seacrowd.utils.configs import SEACrowdConfig
24
+ from seacrowd.utils.constants import SCHEMA_TO_FEATURES, TASK_TO_SCHEMA, Licenses, Tasks
25
+
26
+ _CITATION = """\
27
+ @misc{Bud500,
28
+ author = {Anh Pham, Khanh Linh Tran, Linh Nguyen, Thanh Duy Cao, Phuc Phan, Duong A. Nguyen},
29
+ title = {Bud500: A Comprehensive Vietnamese ASR Dataset},
30
+ url = {https://github.com/quocanh34/Bud500},
31
+ year = {2024}
32
+ }
33
+ """
34
+
35
+ _DATASETNAME = "bud500"
36
+
37
+ _DESCRIPTION = """\
38
+ Bud500 is a diverse Vietnamese speech corpus designed to support ASR research
39
+ community. With aprroximately 500 hours of audio, it covers a broad spectrum of
40
+ topics including podcast, travel, book, food, and so on, while spanning accents
41
+ from Vietnam's North, South, and Central regions. Derived from free public audio
42
+ resources, this publicly accessible dataset is designed to significantly enhance
43
+ the work of developers and researchers in the field of speech recognition.
44
+ Before using this dataloader, please accept the acknowledgement at
45
+ https://huggingface.co/datasets/linhtran92/viet_bud500 and use huggingface-cli
46
+ login for authentication.
47
+ """
48
+
49
+ _HOMEPAGE = "https://huggingface.co/datasets/linhtran92/viet_bud500"
50
+
51
+ _LANGUAGES = ["vie"]
52
+
53
+ _LICENSE = Licenses.APACHE_2_0.value
54
+
55
+ _LOCAL = False
56
+
57
+ _BASE_URL = "https://huggingface.co/datasets/linhtran92/viet_bud500/resolve/main/data/{filename}"
58
+
59
+ _SUPPORTED_TASKS = [Tasks.SPEECH_RECOGNITION]
60
+ _SEACROWD_SCHEMA = f"seacrowd_{TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()}" # sptext
61
+
62
+ _SOURCE_VERSION = "1.0.0"
63
+
64
+ _SEACROWD_VERSION = "2024.06.20"
65
+
66
+
67
+ class Bud500Dataset(datasets.GeneratorBasedBuilder):
68
+ """A diverse Vietnamese speech corpus with aprroximately 500 hours of audio."""
69
+
70
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
71
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
72
+
73
+ BUILDER_CONFIGS = [
74
+ SEACrowdConfig(
75
+ name=f"{_DATASETNAME}_source",
76
+ version=SOURCE_VERSION,
77
+ description=f"{_DATASETNAME} source schema",
78
+ schema="source",
79
+ subset_id=_DATASETNAME,
80
+ ),
81
+ SEACrowdConfig(
82
+ name=f"{_DATASETNAME}_{_SEACROWD_SCHEMA}",
83
+ version=SEACROWD_VERSION,
84
+ description=f"{_DATASETNAME} SEACrowd schema",
85
+ schema=_SEACROWD_SCHEMA,
86
+ subset_id=_DATASETNAME,
87
+ ),
88
+ ]
89
+
90
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
91
+
92
+ def _info(self) -> datasets.DatasetInfo:
93
+ if self.config.schema == "source":
94
+ features = datasets.Features(
95
+ {
96
+ "audio": datasets.Audio(sampling_rate=16_000),
97
+ "transcription": datasets.Value("string"),
98
+ }
99
+ )
100
+ elif self.config.schema == _SEACROWD_SCHEMA:
101
+ features = SCHEMA_TO_FEATURES[
102
+ TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]]
103
+ ] # speech_text_features
104
+
105
+ return datasets.DatasetInfo(
106
+ description=_DESCRIPTION,
107
+ features=features,
108
+ homepage=_HOMEPAGE,
109
+ license=_LICENSE,
110
+ citation=_CITATION,
111
+ )
112
+
113
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
114
+ """Returns SplitGenerators."""
115
+ file_list = HfFileSystem().ls("datasets/linhtran92/viet_bud500/data", detail=False)
116
+ train_urls, test_urls, val_urls = [], [], []
117
+
118
+ for filename in file_list:
119
+ if filename.endswith(".parquet"):
120
+ filename = filename.split("/")[-1]
121
+ split = filename.split("-")[0]
122
+ url = _BASE_URL.format(filename=filename)
123
+
124
+ if split == "train":
125
+ train_urls.append(url)
126
+ elif split == "test":
127
+ test_urls.append(url)
128
+ elif split == "validation":
129
+ val_urls.append(url)
130
+
131
+ train_paths = list(map(Path, dl_manager.download(sorted(train_urls))))
132
+ test_paths = list(map(Path, dl_manager.download(sorted(test_urls))))
133
+ val_paths = list(map(Path, dl_manager.download(sorted(val_urls))))
134
+ return [
135
+ datasets.SplitGenerator(
136
+ name=datasets.Split.TRAIN,
137
+ gen_kwargs={"data_paths": train_paths},
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.TEST,
141
+ gen_kwargs={"data_paths": test_paths},
142
+ ),
143
+ datasets.SplitGenerator(
144
+ name=datasets.Split.VALIDATION,
145
+ gen_kwargs={"data_paths": val_paths},
146
+ ),
147
+ ]
148
+
149
+ def _generate_examples(self, data_paths: Path) -> Tuple[int, Dict]:
150
+ """Yields examples as (key, example) tuples."""
151
+ key = 0
152
+ for data_path in data_paths:
153
+ with open(data_path, "rb") as f:
154
+ pf = pq.ParquetFile(f)
155
+
156
+ for row_group in range(pf.num_row_groups):
157
+ df = pf.read_row_group(row_group).to_pandas()
158
+
159
+ for row in df.itertuples():
160
+ if self.config.schema == "source":
161
+ yield key, {
162
+ "audio": row.audio,
163
+ "transcription": row.transcription,
164
+ }
165
+ elif self.config.schema == _SEACROWD_SCHEMA:
166
+ yield key, {
167
+ "id": str(key),
168
+ "path": None,
169
+ "audio": row.audio,
170
+ "text": row.transcription,
171
+ "speaker_id": None,
172
+ "metadata": None,
173
+ }
174
+ key += 1