Datasets:
Download quest.py from VoiceProfiler/QuEsT: direct link, hf CLI and curl.
- Browser
- Download file 3.07 kB
-
https://huggingface.co/datasets/VoiceProfiler/QuEsT/resolve/main/quest.py
- Command line
-
hf download hf://datasets/VoiceProfiler/QuEsT/quest.py
-
curl -L -o quest.py https://huggingface.co/datasets/VoiceProfiler/QuEsT/resolve/main/quest.py
3.07 kB
| # quest.py — for VoiceProfiler/QuEsT | |
| # Keeps `text_quz` (Quechua) and `text_es` (Spanish), plus a unified `text` column for the viewer. | |
| import os | |
| import datasets | |
| from datasets import load_dataset, Audio | |
| class QuEsT(datasets.GeneratorBasedBuilder): | |
| VERSION = datasets.Version("1.0.0") | |
| BUILDER_CONFIGS = [ | |
| datasets.BuilderConfig(name="default", version=VERSION, description="Default configuration"), | |
| ] | |
| DEFAULT_CONFIG_NAME = "default" | |
| def _info(self): | |
| return datasets.DatasetInfo( | |
| description="Quechua–Spanish speech dataset (QuEsT) with aligned transcripts.", | |
| features=datasets.Features({ | |
| "id": datasets.Value("string"), | |
| "language": datasets.Value("string"), | |
| "text": datasets.Value("string"), | |
| "has_transcription": datasets.Value("bool"), | |
| "audio": Audio(sampling_rate=None, mono=True), | |
| }), | |
| ) | |
| def _split_generators(self, dl_manager): | |
| base = os.path.dirname(os.path.abspath(__file__)) | |
| return [ | |
| datasets.SplitGenerator(name=datasets.Split.TRAIN, | |
| gen_kwargs={"parquet_path": os.path.join(base, "data", "train.parquet")}), | |
| datasets.SplitGenerator(name=datasets.Split.TEST, | |
| gen_kwargs={"parquet_path": os.path.join(base, "data", "test.parquet")}), | |
| ] | |
| def _generate_examples(self, parquet_path: str): | |
| ds = load_dataset("parquet", data_files=parquet_path, split="train") | |
| cols = set(ds.column_names) | |
| length = len(ds) | |
| # Normalize possible alternate column names | |
| if "audio" in cols and "path" not in cols: | |
| ds = ds.rename_column("audio", "path") | |
| if "label" in cols and "text" not in cols: | |
| ds = ds.rename_column("label", "text") | |
| if "lang" in cols and "language" not in cols: | |
| ds = ds.rename_column("lang", "language") | |
| if "has_transcription" not in ds.column_names: | |
| texts = ds["text"] if "text" in ds.column_names else [None] * length | |
| default = [False if t in (None, "") else True for t in texts] | |
| ds = ds.add_column("has_transcription", default) | |
| # Ensure required columns exist | |
| for c in ["id", "language", "text", "path", "has_transcription"]: | |
| if c not in ds.column_names: | |
| fill = [None] * length | |
| if c == "has_transcription": | |
| fill = [False] * length | |
| ds = ds.add_column(c, fill) | |
| # Cast to Audio() for playback in viewer | |
| ds = ds.cast_column("path", Audio(sampling_rate=None, mono=True)) | |
| ds = ds.rename_column("path", "audio") | |
| # Keep only desired columns (and in order) | |
| keep = ["id", "language", "text", "has_transcription", "audio"] | |
| drop = [c for c in ds.column_names if c not in keep] | |
| if drop: | |
| ds = ds.remove_columns(drop) | |
| for i, ex in enumerate(ds): | |
| yield i, ex | |