Emilio Marinone commited on
Commit
5f17366
1 Parent(s): 72ea1a1

add loading bar with tqdm

Browse files
Files changed (1) hide show
  1. nst_sv.py +8 -15
nst_sv.py CHANGED
@@ -22,11 +22,10 @@ TODO:
22
  * add train-validation-test split option
23
  """
24
 
25
- import csv
26
  import json
27
  import os
28
- import logging
29
 
 
30
  import datasets
31
 
32
 
@@ -59,13 +58,6 @@ _URLS = {
59
 
60
  _ANNOTATIONS_URL = "https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/ADB_SWE_0467.tar.gz"
61
 
62
- # _BAD_ANNOTATIONS = [
63
- # 'se14x012-07071999-1342_r4670012.json',
64
- # 'se14x600-21022000-1038_r4670002.json',
65
- # 'se12x387-05071999-1018_r4670387.json',
66
- # 'se13x379-06081999-1429_r4670380.json',
67
- # 'se12x048-21071999-1158_r4670048.json'
68
- # ]
69
 
70
  class NstSV(datasets.GeneratorBasedBuilder):
71
  """Audio dataset for Swedish ASR provided by National Library of Norawy.
@@ -138,7 +130,11 @@ class NstSV(datasets.GeneratorBasedBuilder):
138
  "frequency": datasets.Value("string"),
139
  "memo": datasets.Value("string"),
140
  "script": datasets.Value("string"),
141
- "version": datasets.Value("string"),
 
 
 
 
142
  "audio": datasets.features.Audio(sampling_rate=48000),
143
  'client_id': datasets.Value("string"),
144
  'path': datasets.Value("string"),
@@ -177,8 +173,7 @@ class NstSV(datasets.GeneratorBasedBuilder):
177
  urls = _URLS[self.config.name]
178
  data_dir = dl_manager.download_and_extract(urls)
179
  annotations_dir = dl_manager.download_and_extract(_ANNOTATIONS_URL)
180
- # print(f"data_dir: {data_dir}")
181
- # print(f"annotations_dir: {annotations_dir}")
182
  return [
183
  datasets.SplitGenerator(
184
  name=datasets.Split.TRAIN,
@@ -217,8 +212,6 @@ class NstSV(datasets.GeneratorBasedBuilder):
217
 
218
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
219
  def _generate_examples(self, data_dir, annotations_dir):
220
- # TODO: This method handles input defined in _split_generators to yield (key, example) tuples from the dataset.
221
- # The `key` is for legacy reasons (tfds) and is not important in itself, but must be unique for each example.
222
 
223
  files_failed_loading = []
224
  if self.config.name == "close_channel":
@@ -227,7 +220,7 @@ class NstSV(datasets.GeneratorBasedBuilder):
227
  channel_ext = "-2"
228
 
229
  annotations_files = os.listdir(annotations_dir)
230
- for i, annotation_filename in enumerate(annotations_files):
231
  print(f"Loading from annotation file: {i+1}/{len(annotations_files)}")
232
  # if annotation_filename not in _BAD_ANNOTATIONS:
233
  annotations_filepath = os.path.join(annotations_dir, annotation_filename)
 
22
  * add train-validation-test split option
23
  """
24
 
 
25
  import json
26
  import os
 
27
 
28
+ from tqdm import tqdm
29
  import datasets
30
 
31
 
 
58
 
59
  _ANNOTATIONS_URL = "https://www.nb.no/sbfil/talegjenkjenning/16kHz_2020/se_2020/ADB_SWE_0467.tar.gz"
60
 
 
 
 
 
 
 
 
61
 
62
  class NstSV(datasets.GeneratorBasedBuilder):
63
  """Audio dataset for Swedish ASR provided by National Library of Norawy.
 
130
  "frequency": datasets.Value("string"),
131
  "memo": datasets.Value("string"),
132
  "script": datasets.Value("string"),
133
+ "version": datasets.Value("string"),
134
+ # real sampling rate is 16000
135
+ # it is set to 48000 to allow concatenation
136
+ # with common voice dataset using
137
+ # datasets.concatenate_datasets([dataset_a, dataset_b])
138
  "audio": datasets.features.Audio(sampling_rate=48000),
139
  'client_id': datasets.Value("string"),
140
  'path': datasets.Value("string"),
 
173
  urls = _URLS[self.config.name]
174
  data_dir = dl_manager.download_and_extract(urls)
175
  annotations_dir = dl_manager.download_and_extract(_ANNOTATIONS_URL)
176
+
 
177
  return [
178
  datasets.SplitGenerator(
179
  name=datasets.Split.TRAIN,
 
212
 
213
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
214
  def _generate_examples(self, data_dir, annotations_dir):
 
 
215
 
216
  files_failed_loading = []
217
  if self.config.name == "close_channel":
 
220
  channel_ext = "-2"
221
 
222
  annotations_files = os.listdir(annotations_dir)
223
+ for annotation_filename in tqdm(annotations_files):
224
  print(f"Loading from annotation file: {i+1}/{len(annotations_files)}")
225
  # if annotation_filename not in _BAD_ANNOTATIONS:
226
  annotations_filepath = os.path.join(annotations_dir, annotation_filename)