SoundProfiler commited on
Commit
e20f826
·
1 Parent(s): d256bad

new QuEsT

Browse files
Files changed (6) hide show
  1. LICENSE.md +9 -0
  2. README.md +79 -3
  3. build_parquet.py +218 -0
  4. data/test.parquet +3 -0
  5. data/train.parquet +3 -0
  6. quest.py +73 -0
LICENSE.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [Alex Steve Chung Alvarez]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.md CHANGED
@@ -1,3 +1,79 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+ # Dataset Card for QuEsT
6
+
7
+ <!-- Provide a quick summary of the dataset. -->
8
+
9
+ The Quechua Spanish Translations dataset (QuEsT) is a language pair dataset of quechua sentences and its translations to spanish.
10
+
11
+ ## Dataset Details
12
+
13
+ ### Dataset Description
14
+
15
+ <!-- Provide a longer summary of what this dataset is. -->
16
+ The QuEsT Dataset is conformed of two subsets: train and test. In this section we are going to refer as dataset to the train subset only.
17
+
18
+ The dataset consists of pairs of audios and their transcriptions in the languages of Quechua Cuzco (quz) and Spanish (spa), each pair being conformed by the translation of the sentences from one language to the other.
19
+
20
+ We were able to collect about 42 minutes of Quechua and 34 minutes of Spanish from 6 speakers, being 2 men and 4 women.
21
+ Around 49 minutes (64% of the audio) were recorded from women, while around 27, (36%) from men.
22
+
23
+
24
+ - **Curated by:** Alex Steve Chung Alvarez
25
+ - **Funded by:** Vicerrectorate of Research from National University of Engineering, Lima - Peru
26
+ - **Shared by:** Alex Steve Chung Alvarez
27
+ - **Language(s) (NLP):** quechua, spanish
28
+ - **License:** MIT
29
+
30
+
31
+ ## Uses
32
+
33
+ <!-- Address questions around how the dataset is intended to be used. -->
34
+
35
+ ### Direct Use
36
+
37
+ <!-- This section describes suitable use cases for the dataset. -->
38
+
39
+ The aim of this dataset is to train text-to-speech models and machine translation models with quechua and/or spanish languages.
40
+
41
+ ## Dataset Structure
42
+
43
+ <!-- This section provides a description of the dataset fields, and additional information about the dataset structure such as criteria used to create the splits, relationships between data points, etc. -->
44
+
45
+ ### Quest
46
+ - train
47
+ - speaker_name
48
+ - transcripts.txt
49
+ - language id (qu, es)
50
+ - *audio_files.wav
51
+ - test
52
+ - languag id (qu, es)
53
+ - *audio_files.wav
54
+
55
+ ## Dataset Creation
56
+
57
+ ### Source Data
58
+
59
+ <!-- This section describes the source data (e.g. news text and headlines, social media posts, translated sentences, ...). -->
60
+
61
+ Crowdsourced data of quechua speakers from Cusco.
62
+
63
+
64
+ ## Citation [optional]
65
+
66
+ <!-- If there is a paper or blog post introducing the dataset, the APA and Bibtex information for that should go in this section. -->
67
+
68
+ **BibTeX:**
69
+
70
+ [More Information Needed]
71
+
72
+
73
+ ## Dataset Card Authors [optional]
74
+
75
+ Alex Steve Chung Alvarez
76
+
77
+ ## Dataset Card Contact
78
+
79
+ schunga@uni.pe
build_parquet.py ADDED
@@ -0,0 +1,218 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ # Robust build_parquet.py
3
+ # Usage examples:
4
+ # python build_parquet.py
5
+ # python build_parquet.py --root . --splits train test
6
+ # python build_parquet.py --root /abs/path/to/repo
7
+ # Requirements: datasets==3.*, pyarrow==17.*, soundfile==0.12.*
8
+
9
+ import argparse, csv, re, sys, zipfile
10
+ from pathlib import Path
11
+ from datasets import Dataset, Audio
12
+
13
+ AUDIO_EXTS = {".wav", ".flac", ".mp3", ".ogg", ".m4a"}
14
+ ALLOW_MISSING_TEXT_SPLITS = {"test"}
15
+ PATTERNS = [
16
+ re.compile(r"nombre_(qu|es)_(\d+)$", re.IGNORECASE),
17
+ re.compile(r"(?:.*_)?(qu|es)_(\d+)$", re.IGNORECASE),
18
+ re.compile(r"(\d+)_(qu|es)$", re.IGNORECASE),
19
+ ]
20
+
21
+ def parse_args():
22
+ ap = argparse.ArgumentParser()
23
+ ap.add_argument("--root", type=Path, default=Path.cwd(), help="Repo root where transcripts.txt lives")
24
+ ap.add_argument("--splits", nargs="*", default=["train","test"], help="Split directories to scan")
25
+ return ap.parse_args()
26
+
27
+ def read_transcripts(path: Path):
28
+ id2pair = {}
29
+ if not path.exists():
30
+ print(f"[ERR] transcripts.txt not found: {path}", file=sys.stderr)
31
+ sys.exit(1)
32
+ with path.open(encoding="utf-8") as f:
33
+ reader = csv.reader(f, delimiter='|', quotechar='"')
34
+ for row in reader:
35
+ if not row or len(row) < 3:
36
+ continue
37
+ rid, quz, es = row[0].strip(), row[1].strip(), row[2].strip()
38
+ id2pair[rid] = {"quz": quz, "es": es}
39
+ id2pair[rid.lstrip("0") or "0"] = {"quz": quz, "es": es}
40
+ print(f"[OK] transcripts loaded: {len(id2pair)//2} unique ids")
41
+ return id2pair
42
+
43
+ def parse_lang_id(stem: str):
44
+ for rgx in PATTERNS:
45
+ m = rgx.search(stem)
46
+ if m:
47
+ g1, g2 = m.groups()
48
+ if g1.lower() in {"qu","es"}: return g1.lower(), g2
49
+ if g2.lower() in {"qu","es"}: return g2.lower(), g1
50
+ return None, None
51
+
52
+ def _flatten_if_nested(sp_dir: Path, split_name: str):
53
+ """
54
+ If sp_dir contains a single subdir with the same name (train/test) or just one folder,
55
+ move its contents up to sp_dir and remove the nested dir.
56
+ """
57
+ if not sp_dir.exists():
58
+ return
59
+ # If there are files already at top-level, do nothing
60
+ top_files = [p for p in sp_dir.iterdir() if p.is_file()]
61
+ if top_files:
62
+ return
63
+ # Find immediate subdirs
64
+ subdirs = [p for p in sp_dir.iterdir() if p.is_dir()]
65
+ if len(subdirs) != 1:
66
+ return
67
+ nested = subdirs[0]
68
+ # Flatten only if nested is the same name or if sp_dir has exactly one subdir and no files
69
+ if nested.name == split_name or True:
70
+ for item in nested.iterdir():
71
+ item.rename(sp_dir / item.name)
72
+ nested.rmdir()
73
+
74
+ def ensure_splits_exist_or_extract(root: Path, splits):
75
+ found_any = False
76
+ for sp in splits:
77
+ sp_dir = root / sp
78
+ sp_zip = root / f"{sp}.zip"
79
+
80
+ if sp_dir.exists():
81
+ found_any = True
82
+ continue
83
+
84
+ if sp_zip.exists() and zipfile.is_zipfile(sp_zip):
85
+ print(f"[INFO] Extracting {sp_zip} -> {sp_dir}")
86
+ sp_dir.mkdir(parents=True, exist_ok=True)
87
+ with zipfile.ZipFile(sp_zip, 'r') as zf:
88
+ zf.extractall(sp_dir)
89
+ _flatten_if_nested(sp_dir, sp) # <-- add this line
90
+ found_any = True
91
+ else:
92
+ if sp_zip.exists():
93
+ print(f"[WARN] {sp_zip} exists but is not a valid zip (maybe an LFS pointer?). Skipping.")
94
+ return found_any
95
+
96
+
97
+ def collect_rows(root: Path, splits, id2pair):
98
+ rows, counted = [], 0
99
+ missing_details, kept_missing, skipped_missing = [], 0, 0
100
+
101
+ have_split_dirs = any((root/sp).exists() for sp in splits)
102
+ if not have_split_dirs:
103
+ # try to auto-extract if zips exist
104
+ if ensure_splits_exist_or_extract(root, splits):
105
+ have_split_dirs = True
106
+
107
+ if have_split_dirs:
108
+ # standard split traversal
109
+ for sp in splits:
110
+ sp_dir = root / sp
111
+ if not sp_dir.exists():
112
+ print(f"[WARN] split folder not found: {sp_dir} (skipping)")
113
+ continue
114
+ for wav in sp_dir.rglob("*"):
115
+ if wav.suffix.lower() not in AUDIO_EXTS: continue
116
+ lang, idx = parse_lang_id(wav.stem)
117
+ if not idx or not lang: continue
118
+ pair = id2pair.get(idx) or id2pair.get(idx.lstrip("0") or "0")
119
+ tq = pair["quz"] if pair else None
120
+ te = pair["es"] if pair else None
121
+ text = tq if lang == "qu" else te
122
+ rel = wav.relative_to(root).as_posix()
123
+ has_transcription = text is not None and text.strip() != ""
124
+ if not has_transcription:
125
+ missing_details.append({
126
+ "path": rel,
127
+ "lang": lang,
128
+ "id": idx,
129
+ "split": sp
130
+ })
131
+ if sp in ALLOW_MISSING_TEXT_SPLITS:
132
+ kept_missing += 1
133
+ else:
134
+ skipped_missing += 1
135
+ continue
136
+ rows.append({
137
+ "id": idx,
138
+ "language": lang,
139
+ "path": rel,
140
+ "text": text,
141
+ "has_transcription": has_transcription,
142
+ "split": sp
143
+ })
144
+ counted += 1
145
+ else:
146
+ # no split dirs at all: index every wav under root as train
147
+ print("[INFO] No split folders found; indexing all audio under root as split='train'")
148
+ for wav in root.rglob("*"):
149
+ if wav.suffix.lower() not in AUDIO_EXTS: continue
150
+ lang, idx = parse_lang_id(wav.stem)
151
+ if not idx or not lang: continue
152
+ pair = id2pair.get(idx) or id2pair.get(idx.lstrip("0") or "0")
153
+ tq = pair["quz"] if pair else None
154
+ te = pair["es"] if pair else None
155
+ text = tq if lang == "qu" else te
156
+ rel = wav.relative_to(root).as_posix()
157
+ has_transcription = text is not None and text.strip() != ""
158
+ if not has_transcription:
159
+ missing_details.append({
160
+ "path": rel,
161
+ "lang": lang,
162
+ "id": idx,
163
+ "split": "train"
164
+ })
165
+ if "train" in ALLOW_MISSING_TEXT_SPLITS:
166
+ kept_missing += 1
167
+ else:
168
+ skipped_missing += 1
169
+ continue
170
+ rows.append({
171
+ "id": idx,
172
+ "language": lang,
173
+ "path": rel,
174
+ "text": text,
175
+ "has_transcription": has_transcription,
176
+ "split": "train"
177
+ })
178
+ counted += 1
179
+
180
+ print(f"[OK] audio files indexed: {counted}")
181
+ if kept_missing:
182
+ print(f"[INFO] samples kept without text: {kept_missing} (allowed splits: {', '.join(sorted(ALLOW_MISSING_TEXT_SPLITS))})")
183
+ if skipped_missing:
184
+ print(f"[WARN] samples skipped due to missing text: {skipped_missing}")
185
+ if missing_details:
186
+ for miss in missing_details[:10]:
187
+ flag = "kept" if miss["split"] in ALLOW_MISSING_TEXT_SPLITS else "skipped"
188
+ print(f" - {miss['path']} (id={miss['id']}, lang={miss['lang']}, split={miss['split']}, {flag})")
189
+ if len(missing_details) > 10:
190
+ print(f" ... {len(missing_details) - 10} more")
191
+ return rows
192
+
193
+ def main():
194
+ args = parse_args()
195
+ root = args.root.resolve()
196
+ print(f"[INFO] repo root: {root}")
197
+ id2pair = read_transcripts(root / "transcripts.txt")
198
+ rows = collect_rows(root, args.splits, id2pair)
199
+ if not rows:
200
+ print("[ERR] no audio rows collected. Check paths, zips, or patterns.", file=sys.stderr)
201
+ sys.exit(2)
202
+
203
+ ds_all = Dataset.from_list(rows).cast_column("path", Audio(sampling_rate=None))
204
+
205
+ out_dir = root / "data"
206
+ out_dir.mkdir(parents=True, exist_ok=True)
207
+
208
+ splits_present = sorted({r["split"] for r in rows})
209
+ for sp in splits_present:
210
+ ds = ds_all.filter(lambda x: x["split"] == sp).remove_columns(["split"])
211
+ out = out_dir / f"{sp}.parquet"
212
+ ds.to_parquet(out)
213
+ print(f"[OK] wrote {out} ({len(ds)} rows)")
214
+
215
+ print("[DONE] Parquet build complete.")
216
+
217
+ if __name__ == "__main__":
218
+ main()
data/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7f88c4b8919f5c335c5306463d1a26910bf72d254cc9c5d090fd7ee22ac917b6
3
+ size 9207
data/train.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2dcb07a62ea7a641a9b17129c2a5d0b11bb98da207c08d6ce4c79559bd7b640c
3
+ size 61983
quest.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # quest.py — for VoiceProfiler/QuEsT
2
+ # Keeps `text_quz` (Quechua) and `text_es` (Spanish), plus a unified `text` column for the viewer.
3
+
4
+ import os
5
+ import datasets
6
+ from datasets import load_dataset, Audio
7
+
8
+ class QuEsT(datasets.GeneratorBasedBuilder):
9
+ VERSION = datasets.Version("1.0.0")
10
+ BUILDER_CONFIGS = [
11
+ datasets.BuilderConfig(name="default", version=VERSION, description="Default configuration"),
12
+ ]
13
+ DEFAULT_CONFIG_NAME = "default"
14
+
15
+ def _info(self):
16
+ return datasets.DatasetInfo(
17
+ description="Quechua–Spanish speech dataset (QuEsT) with aligned transcripts.",
18
+ features=datasets.Features({
19
+ "id": datasets.Value("string"),
20
+ "language": datasets.Value("string"),
21
+ "text": datasets.Value("string"),
22
+ "has_transcription": datasets.Value("bool"),
23
+ "audio": Audio(sampling_rate=None, mono=True),
24
+ }),
25
+ )
26
+
27
+ def _split_generators(self, dl_manager):
28
+ base = os.path.dirname(os.path.abspath(__file__))
29
+ return [
30
+ datasets.SplitGenerator(name=datasets.Split.TRAIN,
31
+ gen_kwargs={"parquet_path": os.path.join(base, "data", "train.parquet")}),
32
+ datasets.SplitGenerator(name=datasets.Split.TEST,
33
+ gen_kwargs={"parquet_path": os.path.join(base, "data", "test.parquet")}),
34
+ ]
35
+
36
+ def _generate_examples(self, parquet_path: str):
37
+ ds = load_dataset("parquet", data_files=parquet_path, split="train")
38
+
39
+ cols = set(ds.column_names)
40
+ length = len(ds)
41
+
42
+ # Normalize possible alternate column names
43
+ if "audio" in cols and "path" not in cols:
44
+ ds = ds.rename_column("audio", "path")
45
+ if "label" in cols and "text" not in cols:
46
+ ds = ds.rename_column("label", "text")
47
+ if "lang" in cols and "language" not in cols:
48
+ ds = ds.rename_column("lang", "language")
49
+ if "has_transcription" not in ds.column_names:
50
+ texts = ds["text"] if "text" in ds.column_names else [None] * length
51
+ default = [False if t in (None, "") else True for t in texts]
52
+ ds = ds.add_column("has_transcription", default)
53
+
54
+ # Ensure required columns exist
55
+ for c in ["id", "language", "text", "path", "has_transcription"]:
56
+ if c not in ds.column_names:
57
+ fill = [None] * length
58
+ if c == "has_transcription":
59
+ fill = [False] * length
60
+ ds = ds.add_column(c, fill)
61
+
62
+ # Cast to Audio() for playback in viewer
63
+ ds = ds.cast_column("path", Audio(sampling_rate=None, mono=True))
64
+ ds = ds.rename_column("path", "audio")
65
+
66
+ # Keep only desired columns (and in order)
67
+ keep = ["id", "language", "text", "has_transcription", "audio"]
68
+ drop = [c for c in ds.column_names if c not in keep]
69
+ if drop:
70
+ ds = ds.remove_columns(drop)
71
+
72
+ for i, ex in enumerate(ds):
73
+ yield i, ex