ujs commited on
Commit
a310f45
·
1 Parent(s): 31cc390

First version of Hinglish dataset

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