rishi70612 commited on
Commit
b2be8d9
·
verified ·
1 Parent(s): 71c0690

Update dataset_script.py

Browse files
Files changed (1) hide show
  1. dataset_script.py +154 -154
dataset_script.py CHANGED
@@ -1,154 +1,154 @@
1
- # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
- """Leading and Trailing Silences Removed Large Nepali ASR Dataset"""
15
-
16
- import os
17
- import csv
18
-
19
- import datasets
20
-
21
-
22
- _CITATION = """\
23
- @inproceedings{kjartansson-etal-sltu2018,
24
- title = {{Crowd-Sourced Speech Corpora for Javanese, Sundanese, Sinhala, Nepali, and Bangladeshi Bengali}},
25
- author = {Oddur Kjartansson and Supheakmungkol Sarin and Knot Pipatsrisawat and Martin Jansche and Linne Ha},
26
- booktitle = {Proc. The 6th Intl. Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU)},
27
- year = {2018},
28
- address = {Gurugram, India},
29
- month = aug,
30
- pages = {52--55},
31
- URL = {http://dx.doi.org/10.21437/SLTU.2018-11}
32
- }
33
- """
34
-
35
- _DESCRIPTION = """\
36
- This data set contains transcribed audio data for Nepali. The data set consists of flac files, and a TSV file. The file utt_spk_text.tsv contains a FileID, anonymized UserID and the transcription of audio in the file.
37
- The data set has been manually quality checked, but there might still be errors.
38
-
39
- The audio files are sampled at rate of 16KHz, and leading and trailing silences are trimmed using torchaudio's voice activity detection.
40
- """
41
-
42
- # Official homepage for the dataset
43
- _HOMEPAGE = "https://www.openslr.org/54/"
44
-
45
- # The licence for the dataset
46
- _LICENSE = "license:cc-by-sa-4.0"
47
-
48
- # TODO: Add link to the official dataset URLs here
49
- # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
50
- # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
51
- _URLS = {
52
- 'cleaned': {
53
- "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_clean.tsv",
54
- "zipfiles": [
55
- f"https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/asr_nepali_{k}.zip"
56
- for k in [*range(10), *'abcdef']
57
- ],
58
- },
59
- 'original': {
60
- "index_file": "https://huggingface.co/datasets/spktsagar/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_orig.tsv",
61
- "zipfiles": [
62
- f"https://www.openslr.org/resources/54/asr_nepali_{k}.zip"
63
- for k in [*range(10), *'abcdef']
64
- ],
65
- },
66
- }
67
-
68
-
69
- # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
70
- class OpenslrNepaliAsrCleaned(datasets.GeneratorBasedBuilder):
71
- """End Silences Removed Large Nepali ASR Dataset"""
72
-
73
- VERSION = datasets.Version("1.0.0")
74
-
75
- BUILDER_CONFIGS = [
76
- datasets.BuilderConfig(name="original", version=VERSION,
77
- description="All original utterances, speaker id and transcription from Openslr Large Nepali ASR Dataset"),
78
- datasets.BuilderConfig(name="cleaned", version=VERSION,
79
- description="All cleaned utterances, speaker id and transcription from Openslr Large Nepali ASR Dataset"),
80
- ]
81
-
82
- # It's not mandatory to have a default configuration. Just use one if it make sense.
83
- DEFAULT_CONFIG_NAME = "original"
84
-
85
- def _info(self):
86
- features = datasets.Features(
87
- {
88
- "utterance_id": datasets.Value("string"),
89
- "speaker_id": datasets.Value("string"),
90
- "utterance": datasets.Audio(sampling_rate=16000),
91
- "transcription": datasets.Value("string"),
92
- "num_frames": datasets.Value("int32"),
93
- }
94
- )
95
- return datasets.DatasetInfo(
96
- description=_DESCRIPTION,
97
- # Here we define them above because they are different between the two configurations
98
- features=features,
99
- # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
100
- # specify them. They'll be used if as_supervised=True in builder.as_dataset.
101
- # supervised_keys=("sentence", "label"),
102
- # Homepage of the dataset for documentation
103
- homepage=_HOMEPAGE,
104
- # License for the dataset if available
105
- license=_LICENSE,
106
- # Citation for the dataset
107
- citation=_CITATION,
108
- )
109
-
110
- def _split_generators(self, dl_manager):
111
- index_file = dl_manager.download(_URLS[self.config.name]['index_file'])
112
- zip_paths = [item for sublist in [
113
- dl_manager.download(
114
- _URLS[self.config.name]['zipfiles'][i:i+4]
115
- ) for i in range(0, len(_URLS[self.config.name]['zipfiles']), 4)
116
- ] for item in sublist]
117
- audio_paths = dict(zip([url[-5] for url in _URLS[self.config.name]["zipfiles"]],
118
- dl_manager.extract(zip_paths)))
119
- for path in zip_paths:
120
- if os.path.exists(path):
121
- os.remove(path)
122
- return [
123
- datasets.SplitGenerator(
124
- name=datasets.Split.TRAIN,
125
- gen_kwargs={
126
- "index_file": index_file,
127
- "audio_paths": audio_paths,
128
- },
129
- ),
130
- ]
131
-
132
- def _generate_examples(self, index_file, audio_paths):
133
- with open(index_file, encoding="utf-8") as f:
134
- reader = csv.DictReader(f, delimiter='\t')
135
- for key, row in enumerate(reader):
136
- if self.config.name == 'cleaned':
137
- path = os.path.join(
138
- audio_paths[row['utterance_id'][0]], 'cleaned',
139
- 'asr_nepali', 'data', row['utterance_id'][:2],
140
- f"{row['utterance_id']}.flac"
141
- )
142
- else:
143
- path = os.path.join(
144
- audio_paths[row['utterance_id'][0]],
145
- 'asr_nepali', 'data', row['utterance_id'][:2],
146
- f"{row['utterance_id']}.flac"
147
- )
148
- yield key, {
149
- "utterance_id": row['utterance_id'],
150
- "speaker_id": row['speaker_id'],
151
- "utterance": path,
152
- "transcription": row['transcription'],
153
- "num_frames": int(row['num_frames']),
154
- }
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Leading and Trailing Silences Removed Large Nepali ASR Dataset"""
15
+
16
+ import os
17
+ import csv
18
+
19
+ import datasets
20
+
21
+
22
+ _CITATION = """\
23
+ @inproceedings{kjartansson-etal-sltu2018,
24
+ title = {{Crowd-Sourced Speech Corpora for Javanese, Sundanese, Sinhala, Nepali, and Bangladeshi Bengali}},
25
+ author = {Oddur Kjartansson and Supheakmungkol Sarin and Knot Pipatsrisawat and Martin Jansche and Linne Ha},
26
+ booktitle = {Proc. The 6th Intl. Workshop on Spoken Language Technologies for Under-Resourced Languages (SLTU)},
27
+ year = {2018},
28
+ address = {Gurugram, India},
29
+ month = aug,
30
+ pages = {52--55},
31
+ URL = {http://dx.doi.org/10.21437/SLTU.2018-11}
32
+ }
33
+ """
34
+
35
+ _DESCRIPTION = """\
36
+ This data set contains transcribed audio data for Nepali. The data set consists of flac files, and a TSV file. The file utt_spk_text.tsv contains a FileID, anonymized UserID and the transcription of audio in the file.
37
+ The data set has been manually quality checked, but there might still be errors.
38
+
39
+ The audio files are sampled at rate of 16KHz, and leading and trailing silences are trimmed using torchaudio's voice activity detection.
40
+ """
41
+
42
+ # Official homepage for the dataset
43
+ _HOMEPAGE = "https://www.openslr.org/54/"
44
+
45
+ # The licence for the dataset
46
+ _LICENSE = "license:cc-by-sa-4.0"
47
+
48
+ # TODO: Add link to the official dataset URLs here
49
+ # The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
50
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
51
+ _URLS = {
52
+ 'cleaned': {
53
+ "index_file": "https://huggingface.co/datasets/rishi70612/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_clean.tsv",
54
+ "zipfiles": [
55
+ f"https://huggingface.co/datasets/rishi70612/openslr-nepali-asr-cleaned/resolve/main/data/asr_nepali_{k}.zip"
56
+ for k in [*range(10), *'abcdef']
57
+ ],
58
+ },
59
+ 'original': {
60
+ "index_file": "https://huggingface.co/datasets/rishi70612/openslr-nepali-asr-cleaned/resolve/main/data/utt_spk_text_orig.tsv",
61
+ "zipfiles": [
62
+ f"https://www.openslr.org/resources/54/asr_nepali_{k}.zip"
63
+ for k in [*range(10), *'abcdef']
64
+ ],
65
+ },
66
+ }
67
+
68
+
69
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
70
+ class OpenslrNepaliAsrCleaned(datasets.GeneratorBasedBuilder):
71
+ """End Silences Removed Large Nepali ASR Dataset"""
72
+
73
+ VERSION = datasets.Version("1.0.0")
74
+
75
+ BUILDER_CONFIGS = [
76
+ datasets.BuilderConfig(name="original", version=VERSION,
77
+ description="All original utterances, speaker id and transcription from Openslr Large Nepali ASR Dataset"),
78
+ datasets.BuilderConfig(name="cleaned", version=VERSION,
79
+ description="All cleaned utterances, speaker id and transcription from Openslr Large Nepali ASR Dataset"),
80
+ ]
81
+
82
+ # It's not mandatory to have a default configuration. Just use one if it make sense.
83
+ DEFAULT_CONFIG_NAME = "original"
84
+
85
+ def _info(self):
86
+ features = datasets.Features(
87
+ {
88
+ "utterance_id": datasets.Value("string"),
89
+ "speaker_id": datasets.Value("string"),
90
+ "utterance": datasets.Audio(sampling_rate=16000),
91
+ "transcription": datasets.Value("string"),
92
+ "num_frames": datasets.Value("int32"),
93
+ }
94
+ )
95
+ return datasets.DatasetInfo(
96
+ description=_DESCRIPTION,
97
+ # Here we define them above because they are different between the two configurations
98
+ features=features,
99
+ # If there's a common (input, target) tuple from the features, uncomment supervised_keys line below and
100
+ # specify them. They'll be used if as_supervised=True in builder.as_dataset.
101
+ # supervised_keys=("sentence", "label"),
102
+ # Homepage of the dataset for documentation
103
+ homepage=_HOMEPAGE,
104
+ # License for the dataset if available
105
+ license=_LICENSE,
106
+ # Citation for the dataset
107
+ citation=_CITATION,
108
+ )
109
+
110
+ def _split_generators(self, dl_manager):
111
+ index_file = dl_manager.download(_URLS[self.config.name]['index_file'])
112
+ zip_paths = [item for sublist in [
113
+ dl_manager.download(
114
+ _URLS[self.config.name]['zipfiles'][i:i+4]
115
+ ) for i in range(0, len(_URLS[self.config.name]['zipfiles']), 4)
116
+ ] for item in sublist]
117
+ audio_paths = dict(zip([url[-5] for url in _URLS[self.config.name]["zipfiles"]],
118
+ dl_manager.extract(zip_paths)))
119
+ for path in zip_paths:
120
+ if os.path.exists(path):
121
+ os.remove(path)
122
+ return [
123
+ datasets.SplitGenerator(
124
+ name=datasets.Split.TRAIN,
125
+ gen_kwargs={
126
+ "index_file": index_file,
127
+ "audio_paths": audio_paths,
128
+ },
129
+ ),
130
+ ]
131
+
132
+ def _generate_examples(self, index_file, audio_paths):
133
+ with open(index_file, encoding="utf-8") as f:
134
+ reader = csv.DictReader(f, delimiter='\t')
135
+ for key, row in enumerate(reader):
136
+ if self.config.name == 'cleaned':
137
+ path = os.path.join(
138
+ audio_paths[row['utterance_id'][0]], 'cleaned',
139
+ 'asr_nepali', 'data', row['utterance_id'][:2],
140
+ f"{row['utterance_id']}.flac"
141
+ )
142
+ else:
143
+ path = os.path.join(
144
+ audio_paths[row['utterance_id'][0]],
145
+ 'asr_nepali', 'data', row['utterance_id'][:2],
146
+ f"{row['utterance_id']}.flac"
147
+ )
148
+ yield key, {
149
+ "utterance_id": row['utterance_id'],
150
+ "speaker_id": row['speaker_id'],
151
+ "utterance": path,
152
+ "transcription": row['transcription'],
153
+ "num_frames": int(row['num_frames']),
154
+ }