File size: 4,934 Bytes
5820821 f50b5e1 5820821 f50b5e1 62eb364 5820821 f50b5e1 5820821 62eb364 f50b5e1 5820821 f50b5e1 5820821 62eb364 f50b5e1 5820821 f50b5e1 5820821 f50b5e1 5820821 62eb364 f50b5e1 62eb364 5820821 62eb364 5820821 f50b5e1 5820821 f50b5e1 62eb364 f50b5e1 5820821 62eb364 5820821 62eb364 5820821 f50b5e1 5820821 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import csv
import os
from typing import Iterator, Tuple
import datasets
_DESCRIPTION = """\
Bu dataset mp3 formatdagi audio fayllar va tsv metadata fayllardan iborat.
Audio fayllar .tar arxiv ichida saqlangan va tsv faylda fayl nomlari (masalan, H3H38EY38D8.mp3) keltirilgan.
Katta datasetning faqat 100 tadan yozuvi olingan mini versiyasi.
"""
_HOMEPAGE = "https://huggingface.co/datasets/Elyordev/new_dataset_stt_mini"
_LICENSE = "MIT"
# Har bir split uchun .tsv va .tar fayllarning repo ichidagi joylashuvi (mini variantda ham xuddi shu).
_URLS = {
"train": {
"tsv": "train/train.tsv",
"tar": "train/train.tar",
},
"validation": {
"tsv": "validation/validation.tsv",
"tar": "validation/validation.tar",
},
"test": {
"tsv": "test/test.tsv",
"tar": "test/test.tar",
},
}
class MyMiniDatasetSTTConfig(datasets.BuilderConfig):
def __init__(self, **kwargs):
super(MyMiniDatasetSTTConfig, self).__init__(**kwargs)
class MyMiniDatasetSTT(datasets.GeneratorBasedBuilder):
VERSION = datasets.Version("1.0.0")
BUILDER_CONFIGS = [
MyMiniDatasetSTTConfig(
name="default",
version=VERSION,
description="Mini STT dataset with mp3 audios in tar archives (100 examples per split)",
),
]
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
"id": datasets.Value("string"),
"path": datasets.Value("string"), # Fayl nomi, masalan: H3H38EY38D8.mp3
"sentence": datasets.Value("string"),
"duration": datasets.Value("float"),
"age": datasets.Value("string"),
"gender": datasets.Value("string"),
"accents": datasets.Value("string"),
"locale": datasets.Value("string"),
# Audio feature: datasets.Audio avtomatik tarzda tar URI orqali yuklaydi
"audio": datasets.Audio(sampling_rate=16000),
}),
supervised_keys=None,
homepage=_HOMEPAGE,
license=_LICENSE,
)
def _split_generators(self, dl_manager):
"""
Har bir split uchun .tsv va .tar fayllarni yuklab olamiz.
"""
downloaded_files = {}
for split in _URLS:
downloaded_files[split] = {
"tsv": dl_manager.download_and_extract(_URLS[split]["tsv"]),
"tar": dl_manager.download_and_extract(_URLS[split]["tar"]),
}
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
"tsv_path": downloaded_files["train"]["tsv"],
"tar_path": downloaded_files["train"]["tar"],
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
gen_kwargs={
"tsv_path": downloaded_files["validation"]["tsv"],
"tar_path": downloaded_files["validation"]["tar"],
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
gen_kwargs={
"tsv_path": downloaded_files["test"]["tsv"],
"tar_path": downloaded_files["test"]["tar"],
},
),
]
def _generate_examples(self, tsv_path: str, tar_path: str) -> Iterator[Tuple[int, dict]]:
"""
Har bir .tsv fayldagi qatordan misol (example) yaratamiz.
Audio faylga murojaat qilish uchun "tar://" sintaksisidan foydalanamiz:
"tar://<tar fayl yo'li>#<tsv fayldagi path>".
Katta datasetni cheklash uchun 100 misoldan keyin break qilamiz.
"""
with open(tsv_path, encoding="utf-8") as f:
reader = csv.DictReader(f, delimiter="\t")
for idx, row in enumerate(reader):
if idx >= 100:
# faqat 100 ta misol bilan to'xtatamiz
break
mp3_file = row["path"]
# Audio fayl uchun URI: masalan, "tar://.../train.tar#H3H38EY38D8.mp3"
audio_ref = f"tar://{tar_path}#{mp3_file}"
yield idx, {
"id": row["id"],
"path": mp3_file,
"sentence": row["sentence"],
"duration": float(row.get("duration", 0.0)),
"age": row.get("age", ""),
"gender": row.get("gender", ""),
"accents": row.get("accents", ""),
"locale": row.get("locale", ""),
"audio": audio_ref,
}
|