kaushal98b
commited on
Commit
•
2bdfded
1
Parent(s):
6d9e83d
Add code files
Browse files- kathbath.py +153 -0
- languages.py +14 -0
- release_stats.py +22 -0
kathbath.py
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
""" Kathbath Dataset"""
|
2 |
+
|
3 |
+
import csv
|
4 |
+
import os
|
5 |
+
|
6 |
+
import datasets
|
7 |
+
from datasets.utils.py_utils import size_str
|
8 |
+
|
9 |
+
from .languages import LANGUAGES
|
10 |
+
from .release_stats import STATS
|
11 |
+
|
12 |
+
_CITATION = """\
|
13 |
+
@misc{https://doi.org/10.48550/arxiv.2208.11761,
|
14 |
+
doi = {10.48550/ARXIV.2208.11761},
|
15 |
+
url = {https://arxiv.org/abs/2208.11761},
|
16 |
+
author = {Javed, Tahir and Bhogale, Kaushal Santosh and Raman, Abhigyan and Kunchukuttan, Anoop and Kumar, Pratyush and Khapra, Mitesh M.},
|
17 |
+
title = {IndicSUPERB: A Speech Processing Universal Performance Benchmark for Indian languages},
|
18 |
+
publisher = {arXiv},
|
19 |
+
year = {2022},
|
20 |
+
copyright = {arXiv.org perpetual, non-exclusive license}
|
21 |
+
}
|
22 |
+
"""
|
23 |
+
|
24 |
+
_HOMEPAGE = "https://ai4bharat.iitm.ac.in/indic-superb/"
|
25 |
+
|
26 |
+
_LICENSE = "https://creativecommons.org/publicdomain/zero/1.0/"
|
27 |
+
|
28 |
+
_DATA_URL = "https://huggingface.co/datasets/ai4bharat/kathbath/resolve/main/data"
|
29 |
+
|
30 |
+
|
31 |
+
class KathbathConfig(datasets.BuilderConfig):
|
32 |
+
"""BuilderConfig for Kathbath."""
|
33 |
+
|
34 |
+
def __init__(self, name, version, **kwargs):
|
35 |
+
self.language = kwargs.pop("language", None)
|
36 |
+
self.release_date = kwargs.pop("release_date", None)
|
37 |
+
self.num_clips = kwargs.pop("num_clips", None)
|
38 |
+
self.num_speakers = kwargs.pop("num_speakers", None)
|
39 |
+
self.total_hr = kwargs.pop("total_hr", None)
|
40 |
+
self.size_bytes = kwargs.pop("size_bytes", None)
|
41 |
+
self.size_human = size_str(self.size_bytes)
|
42 |
+
description = (
|
43 |
+
f"Kathbath speech to text dataset in {self.language} released on {self.release_date}. "
|
44 |
+
f"The dataset comprises {self.total_hr} hours of transcribed speech data"
|
45 |
+
)
|
46 |
+
super(KathbathConfig, self).__init__(
|
47 |
+
name=name,
|
48 |
+
version=datasets.Version(version),
|
49 |
+
description=description,
|
50 |
+
**kwargs,
|
51 |
+
)
|
52 |
+
|
53 |
+
|
54 |
+
class Kathbath(datasets.GeneratorBasedBuilder):
|
55 |
+
DEFAULT_CONFIG_NAME = "_all_"
|
56 |
+
|
57 |
+
BUILDER_CONFIGS = [
|
58 |
+
KathbathConfig(
|
59 |
+
name=lang,
|
60 |
+
version=STATS["version"],
|
61 |
+
language=LANGUAGES[lang],
|
62 |
+
release_date=STATS["date"],
|
63 |
+
# num_clips=lang_stats["clips"],
|
64 |
+
# num_speakers=lang_stats["users"],
|
65 |
+
total_hr=float(lang_stats["totalHrs"]) if lang_stats["totalHrs"] else None,
|
66 |
+
size_bytes=int(lang_stats["size"]) if lang_stats["size"] else None,
|
67 |
+
)
|
68 |
+
for lang, lang_stats in STATS["locales"].items()
|
69 |
+
]
|
70 |
+
|
71 |
+
def _info(self):
|
72 |
+
total_languages = len(STATS["locales"])
|
73 |
+
total_hours = self.config.total_hr
|
74 |
+
description = (
|
75 |
+
"LibriVox-Indonesia is a speech dataset generated from LibriVox with only languages from Indonesia."
|
76 |
+
f"The dataset currently consists of {total_hours} hours of speech "
|
77 |
+
f"in {total_languages} languages, but more voices and languages are always added."
|
78 |
+
)
|
79 |
+
features = datasets.Features(
|
80 |
+
{
|
81 |
+
"path": datasets.Value("string"),
|
82 |
+
"language": datasets.Value("string"),
|
83 |
+
"speaker": datasets.Value("string"),
|
84 |
+
"sentence": datasets.Value("string"),
|
85 |
+
"audio": datasets.features.Audio(sampling_rate=16000)
|
86 |
+
}
|
87 |
+
)
|
88 |
+
|
89 |
+
return datasets.DatasetInfo(
|
90 |
+
description=description,
|
91 |
+
features=features,
|
92 |
+
supervised_keys=None,
|
93 |
+
homepage=_HOMEPAGE,
|
94 |
+
license=_LICENSE,
|
95 |
+
citation=_CITATION,
|
96 |
+
version=self.config.version,
|
97 |
+
)
|
98 |
+
|
99 |
+
def _split_generators(self, dl_manager):
|
100 |
+
"""Returns SplitGenerators."""
|
101 |
+
dl_manager.download_config.ignore_url_params = True
|
102 |
+
audio_path = {}
|
103 |
+
local_extracted_archive = {}
|
104 |
+
metadata_path = {}
|
105 |
+
split_type = {"train": datasets.Split.TRAIN, "valid": datasets.Split.VALIDATION, "test_unknown": datasets.Split.TEST, "test_known": datasets.Split.TEST}
|
106 |
+
for split in split_type:
|
107 |
+
audio_path[split] = dl_manager.download(f"{_DATA_URL}/audio_{split}.tar")
|
108 |
+
local_extracted_archive[split] = dl_manager.extract(audio_path[split]) if not dl_manager.is_streaming else None
|
109 |
+
metadata_path[split] = dl_manager.download(f"{_DATA_URL}/metadata_{split}.tsv")
|
110 |
+
path_to_clips = "kb_data_clean_m4a"
|
111 |
+
|
112 |
+
return [
|
113 |
+
datasets.SplitGenerator(
|
114 |
+
name=split_type[split],
|
115 |
+
gen_kwargs={
|
116 |
+
"local_extracted_archive": local_extracted_archive[split],
|
117 |
+
"audio_files": dl_manager.iter_archive(audio_path[split]),
|
118 |
+
"metadata_path": metadata_path[split],
|
119 |
+
"path_to_clips": path_to_clips,
|
120 |
+
},
|
121 |
+
) for split in split_type
|
122 |
+
]
|
123 |
+
|
124 |
+
def _generate_examples(
|
125 |
+
self,
|
126 |
+
local_extracted_archive,
|
127 |
+
audio_files,
|
128 |
+
metadata_path,
|
129 |
+
path_to_clips,
|
130 |
+
):
|
131 |
+
"""Yields examples."""
|
132 |
+
data_fields = list(self._info().features.keys())
|
133 |
+
metadata = {}
|
134 |
+
with open(metadata_path, "r", encoding="utf-8") as f:
|
135 |
+
reader = csv.DictReader(f, delimiter="\t")
|
136 |
+
for row in reader:
|
137 |
+
if self.config.name == "_all_" or self.config.name == row["language"]:
|
138 |
+
row["path"] = os.path.join(path_to_clips, row["path"])
|
139 |
+
# if data is incomplete, fill with empty values
|
140 |
+
for field in data_fields:
|
141 |
+
if field not in row:
|
142 |
+
row[field] = ""
|
143 |
+
metadata[row["path"]] = row
|
144 |
+
id_ = 0
|
145 |
+
for path, f in audio_files:
|
146 |
+
if path in metadata:
|
147 |
+
result = dict(metadata[path])
|
148 |
+
# set the audio feature and the path to the extracted file
|
149 |
+
path = os.path.join(local_extracted_archive, path) if local_extracted_archive else path
|
150 |
+
result["audio"] = {"path": path, "bytes": f.read()}
|
151 |
+
result["path"] = path
|
152 |
+
yield id_, result
|
153 |
+
id_ += 1
|
languages.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
LANGUAGES = {
|
2 |
+
"bn": "Bengali",
|
3 |
+
"gu": "Gujarati",
|
4 |
+
"hi": "Hindi",
|
5 |
+
"kn": "Kannada",
|
6 |
+
"ml": "Malayalam",
|
7 |
+
"mr": "Marathi",
|
8 |
+
"or": "Odia",
|
9 |
+
"pa": "Punjabi",
|
10 |
+
"sa": "Sanskrit",
|
11 |
+
"ta": "Tamil",
|
12 |
+
"te": "Telugu",
|
13 |
+
"ur": "Urdu"
|
14 |
+
}
|
release_stats.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
STATS = {
|
2 |
+
"name": "Kathbath",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"date": "2022-08-24",
|
5 |
+
"locales": {
|
6 |
+
"bn": {'totalHrs': 115.8},
|
7 |
+
"gu": {'totalHrs': 129.3},
|
8 |
+
"hi": {'totalHrs': 150.2},
|
9 |
+
"kn": {'totalHrs': 65.8},
|
10 |
+
"ml": {'totalHrs': 147.3},
|
11 |
+
"mr": {'totalHrs': 185.2},
|
12 |
+
"or": {'totalHrs': 111.6},
|
13 |
+
"pa": {'totalHrs': 136.9},
|
14 |
+
"sa": {'totalHrs': 115.5},
|
15 |
+
"ta": {'totalHrs': 185.5},
|
16 |
+
"te": {'totalHrs': 154.9},
|
17 |
+
"ur": {'totalHrs': 86.7},
|
18 |
+
"_all_": {'totalHrs': 1},
|
19 |
+
},
|
20 |
+
'totalDuration': 1, 'totalHrs': 1
|
21 |
+
}
|
22 |
+
|