albertvillanova HF staff commited on
Commit
16ea653
1 Parent(s): fe4401d

Optimize duration of loading script (#6)

Browse files

- Remove glob (0635d66e5a4ffb78eac1da0867ddb6a5b6a92ca0)

Files changed (1) hide show
  1. common_language.py +3 -9
common_language.py CHANGED
@@ -14,8 +14,6 @@
14
  # limitations under the License.
15
  """ Common Language Dataset"""
16
 
17
-
18
- import glob
19
  import os
20
 
21
  import datasets
@@ -150,18 +148,14 @@ class CommonLanguage(datasets.GeneratorBasedBuilder):
150
 
151
  def _generate_examples(self, archive_path, split):
152
  """Yields examples."""
153
-
154
- csv_path_glob = os.path.join(archive_path, "**", f"{split}.csv")
155
-
156
  key = 0
157
- for csv_path in sorted(glob.glob(csv_path_glob)):
 
158
  with open(csv_path, encoding="utf-16") as fin:
159
  next(fin) # skip the header
160
  for line in fin:
161
  client_id, wav_name, sentence, age, gender = line.strip().split("\t")[1:]
162
- language = csv_path.split(os.sep)[-2]
163
- path = os.path.join(os.path.splitext(csv_path)[0], client_id, wav_name)
164
-
165
  yield key, {
166
  "client_id": client_id,
167
  "path": path,
14
  # limitations under the License.
15
  """ Common Language Dataset"""
16
 
 
 
17
  import os
18
 
19
  import datasets
148
 
149
  def _generate_examples(self, archive_path, split):
150
  """Yields examples."""
 
 
 
151
  key = 0
152
+ for language in _LANGUAGES:
153
+ csv_path = os.path.join(archive_path, language, f"{split}.csv")
154
  with open(csv_path, encoding="utf-16") as fin:
155
  next(fin) # skip the header
156
  for line in fin:
157
  client_id, wav_name, sentence, age, gender = line.strip().split("\t")[1:]
158
+ path = os.path.join(archive_path, language, split, client_id, wav_name)
 
 
159
  yield key, {
160
  "client_id": client_id,
161
  "path": path,