Datasets:

Languages:
Thai
ArXiv:
License:
holylovenia commited on
Commit
db11d4c
1 Parent(s): 5ea31d2

Upload gowajee.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. gowajee.py +198 -0
gowajee.py ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ import pandas as pd
21
+
22
+ from seacrowd.utils.configs import SEACrowdConfig
23
+ from seacrowd.utils.constants import (SCHEMA_TO_FEATURES, TASK_TO_SCHEMA,
24
+ Licenses, Tasks)
25
+
26
+ _CITATION = """
27
+ @techreport{gowajee,
28
+ title = {{Gowajee Corpus}},
29
+ author = {Ekapol Chuangsuwanich and Atiwong Suchato and Korrawe Karunratanakul and Burin Naowarat and Chompakorn CChaichot
30
+ and Penpicha Sangsa-nga and Thunyathon Anutarases and Nitchakran Chaipojjana and Yuatyong Chaichana},
31
+ year = {2020},
32
+ institution = {Chulalongkorn University, Faculty of Engineering, Computer Engineering Department},
33
+ month = {12},
34
+ Date-Added = {2023-07-30},
35
+ url = {https://github.com/ekapolc/gowajee_corpus}
36
+ note = {Version 0.9.3}
37
+ }
38
+ """
39
+
40
+ _DATASETNAME = "gowajee"
41
+
42
+ _DESCRIPTION = """
43
+ The Gowajee corpus was collected in the Automatic Speech Recognition class offered at
44
+ Chulalongkorn University as a homework assignment. Each group was asked to come up with an
45
+ example smart home application.
46
+ """
47
+
48
+ _HOMEPAGE = "https://github.com/ekapolc/gowajee_corpus"
49
+
50
+ _LANGUAGES = ["tha"]
51
+
52
+ _LICENSE = Licenses.MIT.value
53
+
54
+ _LOCAL = False
55
+
56
+ _URL = "https://drive.google.com/file/d/1soriRMMuZI5w5RZOjAnbpocBZxT6i1-l/view" # ~1.5GB
57
+
58
+ _SUPPORTED_TASKS = [Tasks.SPEECH_TO_TEXT_TRANSLATION]
59
+ _SEACROWD_SCHEMA = f"seacrowd_{TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]].lower()}" # sptext
60
+
61
+ _SOURCE_VERSION = "0.9.3"
62
+
63
+ _SEACROWD_VERSION = "2024.06.20"
64
+
65
+
66
+ class GowajeeDataset(datasets.GeneratorBasedBuilder):
67
+ """Automatic Speech Recognition dataset on smart home application where the wakeword is "Gowajee"."""
68
+
69
+ SOURCE_VERSION = datasets.Version(_SOURCE_VERSION)
70
+ SEACROWD_VERSION = datasets.Version(_SEACROWD_VERSION)
71
+
72
+ BUILDER_CONFIGS = [
73
+ SEACrowdConfig(
74
+ name=f"{_DATASETNAME}_source",
75
+ version=SOURCE_VERSION,
76
+ description=f"{_DATASETNAME} source schema",
77
+ schema="source",
78
+ subset_id=_DATASETNAME,
79
+ ),
80
+ SEACrowdConfig(
81
+ name=f"{_DATASETNAME}_{_SEACROWD_SCHEMA}",
82
+ version=SEACROWD_VERSION,
83
+ description=f"{_DATASETNAME} SEACrowd schema",
84
+ schema=_SEACROWD_SCHEMA,
85
+ subset_id=_DATASETNAME,
86
+ ),
87
+ ]
88
+
89
+ DEFAULT_CONFIG_NAME = f"{_DATASETNAME}_source"
90
+
91
+ def _info(self) -> datasets.DatasetInfo:
92
+ if self.config.schema == "source":
93
+ features = datasets.Features(
94
+ {
95
+ "audio": datasets.Audio(sampling_rate=16_000),
96
+ "transcription": datasets.Value("string"),
97
+ "speaker_id": datasets.Value("string"),
98
+ }
99
+ )
100
+ elif self.config.schema == _SEACROWD_SCHEMA:
101
+ features = SCHEMA_TO_FEATURES[TASK_TO_SCHEMA[_SUPPORTED_TASKS[0]]] # speech_text_features
102
+
103
+ return datasets.DatasetInfo(
104
+ description=_DESCRIPTION,
105
+ features=features,
106
+ homepage=_HOMEPAGE,
107
+ license=_LICENSE,
108
+ citation=_CITATION,
109
+ )
110
+
111
+ def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
112
+ """Returns SplitGenerators."""
113
+ # check if gdown is installed
114
+ try:
115
+ import gdown
116
+ except ImportError as err:
117
+ raise ImportError("Please install `gdown` to enable downloading data from google drive.") from err
118
+
119
+ # download data from gdrive
120
+ output_dir = Path.cwd() / "data" / "gowajee"
121
+ output_dir.mkdir(parents=True, exist_ok=True)
122
+ output_file = output_dir / "gowajee_v0-9-3.zip"
123
+ if not output_file.exists():
124
+ gdown.download(_URL, str(output_file), fuzzy=True)
125
+ else:
126
+ print(f"File already downloaded: {str(output_file)}")
127
+
128
+ # extract data
129
+ data_dir = Path(dl_manager.extract(output_file)) / "v0.9.2"
130
+
131
+ return [
132
+ datasets.SplitGenerator(
133
+ name=datasets.Split.TRAIN,
134
+ gen_kwargs={
135
+ "data_dir": data_dir,
136
+ "split": "train",
137
+ },
138
+ ),
139
+ datasets.SplitGenerator(
140
+ name=datasets.Split.TEST,
141
+ gen_kwargs={
142
+ "data_dir": data_dir,
143
+ "split": "test",
144
+ },
145
+ ),
146
+ datasets.SplitGenerator(
147
+ name=datasets.Split.VALIDATION,
148
+ gen_kwargs={
149
+ "data_dir": data_dir,
150
+ "split": "dev",
151
+ },
152
+ ),
153
+ ]
154
+
155
+ def _generate_examples(self, data_dir: Path, split: str) -> Tuple[int, Dict]:
156
+ """Yields examples as (key, example) tuples."""
157
+
158
+ text_file = data_dir / split / "text"
159
+ utt2spk_file = data_dir / split / "utt2spk"
160
+ wav_scp_file = data_dir / split / "wav.scp"
161
+
162
+ # load the data
163
+ with open(text_file, "r", encoding="utf-8") as f:
164
+ text_lines = f.readlines()
165
+ text_lines = [line.strip().split(" ", 1) for line in text_lines]
166
+ with open(utt2spk_file, "r", encoding="utf-8") as f:
167
+ utt2spk_lines = f.readlines()
168
+ utt2spk_lines = [line.strip().split(" ") for line in utt2spk_lines]
169
+ with open(wav_scp_file, "r", encoding="utf-8") as f:
170
+ wav_scp_lines = f.readlines()
171
+ wav_scp_lines = [line.strip().split(" ", 1) for line in wav_scp_lines]
172
+
173
+ assert len(text_lines) == len(utt2spk_lines) == len(wav_scp_lines), f"Length of text_lines: {len(text_lines)}, utt2spk_lines: {len(utt2spk_lines)}, wav_scp_lines: {len(wav_scp_lines)}"
174
+
175
+ text_df = pd.DataFrame(text_lines, columns=["utt_id", "text"])
176
+ utt2spk_df = pd.DataFrame(utt2spk_lines, columns=["utt_id", "speaker"])
177
+ wav_df = pd.DataFrame(wav_scp_lines, columns=["utt_id", "wav_path"])
178
+ merged_df = pd.merge(text_df, utt2spk_df, on="utt_id")
179
+ merged_df = pd.merge(merged_df, wav_df, on="utt_id")
180
+
181
+ for _, row in merged_df.iterrows():
182
+ wav_file = data_dir / row["wav_path"]
183
+
184
+ if self.config.schema == "source":
185
+ yield row["utt_id"], {
186
+ "audio": str(wav_file),
187
+ "transcription": row["text"],
188
+ "speaker_id": row["speaker"],
189
+ }
190
+ elif self.config.schema == _SEACROWD_SCHEMA:
191
+ yield row["utt_id"], {
192
+ "id": row["utt_id"],
193
+ "path": str(wav_file),
194
+ "audio": str(wav_file),
195
+ "text": row["text"],
196
+ "speaker_id": row["speaker"],
197
+ "metadata": None,
198
+ }