Upload hinglish-compressed.py
Browse files- hinglish-compressed.py +88 -0
hinglish-compressed.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import datasets
|
5 |
+
|
6 |
+
# _ANNOT_URL = {
|
7 |
+
# "train": "https://huggingface.co/datasets/ujs/hinglish/resolve/main/data/metadata.csv",
|
8 |
+
# "test": "https://huggingface.co/datasets/ujs/hinglish/resolve/main/data/metadata-test.csv",
|
9 |
+
# }
|
10 |
+
|
11 |
+
_ANNOT_URL = {
|
12 |
+
"train": "./data/metadata.csv",
|
13 |
+
"test": "./data/metadata-test.csv"
|
14 |
+
}
|
15 |
+
|
16 |
+
# _DATA_URL = [
|
17 |
+
# "https://huggingface.co/datasets/ujs/hinglish/resolve/main/data/train.tar.gz",
|
18 |
+
# "https://huggingface.co/datasets/ujs/hinglish/resolve/main/data/test.tar.gz"
|
19 |
+
# ]
|
20 |
+
|
21 |
+
_DATA_URL = [
|
22 |
+
"./data/train.tar.gz",
|
23 |
+
"./data/test.tar.gz"
|
24 |
+
]
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
A Hugginface version of the Hindi-English code-switched dataset from OpenSLR-104.
|
28 |
+
"""
|
29 |
+
|
30 |
+
class HinglishDataset(datasets.GeneratorBasedBuilder):
|
31 |
+
VERSION = datasets.Version("1.0.0")
|
32 |
+
|
33 |
+
def _info(self):
|
34 |
+
return datasets.DatasetInfo(
|
35 |
+
description=_DESCRIPTION,
|
36 |
+
features=datasets.Features({
|
37 |
+
"path": datasets.Value("string"),
|
38 |
+
"audio": datasets.Audio(sampling_rate=16_000),
|
39 |
+
"sentence": datasets.Value("string"),
|
40 |
+
}),
|
41 |
+
supervised_keys=None,
|
42 |
+
)
|
43 |
+
|
44 |
+
def _split_generators(self, dl_manager):
|
45 |
+
prompts_paths = dl_manager.download(_ANNOT_URL)
|
46 |
+
archive = dl_manager.download(_DATA_URL)
|
47 |
+
train_dir = 'train'
|
48 |
+
test_dir = 'test'
|
49 |
+
return [
|
50 |
+
datasets.SplitGenerator(
|
51 |
+
name=datasets.Split.TRAIN,
|
52 |
+
gen_kwargs={
|
53 |
+
"prompts_path": prompts_paths["train"],
|
54 |
+
"path_to_clips": train_dir,
|
55 |
+
"audio_files": dl_manager.iter_archive(archive[0]),
|
56 |
+
},
|
57 |
+
),
|
58 |
+
datasets.SplitGenerator(
|
59 |
+
name=datasets.Split.TEST,
|
60 |
+
gen_kwargs={
|
61 |
+
"prompts_path": prompts_paths["test"],
|
62 |
+
"path_to_clips": test_dir,
|
63 |
+
"audio_files": dl_manager.iter_archive(archive[1]),
|
64 |
+
},
|
65 |
+
),
|
66 |
+
]
|
67 |
+
|
68 |
+
def _generate_examples(self, prompts_path, path_to_clips, audio_files):
|
69 |
+
examples = {}
|
70 |
+
with open(prompts_path, encoding="utf-8") as f:
|
71 |
+
for row in f:
|
72 |
+
data = row.strip().split(",")
|
73 |
+
audio_path = "/".join([data[0]])
|
74 |
+
examples[audio_path] = {
|
75 |
+
"path": audio_path,
|
76 |
+
"sentence": data[1]
|
77 |
+
}
|
78 |
+
inside_clips_dir = False
|
79 |
+
id_ = 0
|
80 |
+
for path, f in audio_files:
|
81 |
+
if path.startswith(path_to_clips):
|
82 |
+
inside_clips_dir = True
|
83 |
+
if path in examples:
|
84 |
+
audio = {"path": path, "bytes": f.read()}
|
85 |
+
yield id_, {**examples[path], "audio": audio}
|
86 |
+
id_ += 1
|
87 |
+
elif inside_clips_dir:
|
88 |
+
break
|