Emilio Marinone commited on
Commit
978d592
1 Parent(s): 893ddcf

avoid dicts in dataset

Browse files
Files changed (1) hide show
  1. nst_sv.py +56 -90
nst_sv.py CHANGED
@@ -115,45 +115,30 @@ class NstSV(datasets.GeneratorBasedBuilder):
115
 
116
  def _info(self):
117
  features_dict = {
118
- "info": {
119
- "Age": datasets.Value("string"),
120
- "Region_of_Birth": datasets.Value("string"),
121
- "Region_of_Youth": datasets.Value("string"),
122
- "Remarks": datasets.Value("string"),
123
- "Sex": datasets.Value("string"),
124
- "Speaker_ID": datasets.Value("string"),
125
- },
126
- "metadata": {
127
- "file": datasets.Value("string"),
128
- "lang": datasets.Value("string"),
129
- "path": datasets.Value("string"),
130
- "station": datasets.Value("string"),
131
- },
132
  "pid": datasets.Value("string"),
133
- "session": {
134
- "Directory": datasets.Value("string"),
135
- "Imported_sheet_file": datasets.Value("string"),
136
- "Number_of_recordings": datasets.Value("string"),
137
- "RecDate": datasets.Value("string"),
138
- "RecTime": datasets.Value("string"),
139
- "Record_duration": datasets.Value("string"),
140
- "Record_session": datasets.Value("string"),
141
- "Sheet_number": datasets.Value("string"),
142
- },
143
- "system": {
144
- "ANSI_Codepage": datasets.Value("string"),
145
- "Board": datasets.Value("string"),
146
- "ByteFormat": datasets.Value("string"),
147
- "Channels": datasets.Value("string"),
148
- "CharacterSet": datasets.Value("string"),
149
- "Coding": datasets.Value("string"),
150
- "DOS_Codepage": datasets.Value("string"),
151
- "Delimiter": datasets.Value("string"),
152
- "Frequency": datasets.Value("string"),
153
- "Memo": datasets.Value("string"),
154
- "Script": datasets.Value("string"),
155
- "Version": datasets.Value("string"),
156
- },
157
  "audio": datasets.features.Audio(sampling_rate=16000),
158
  'client_id': datasets.Value("string"),
159
  'path': datasets.Value("string"),
@@ -161,7 +146,7 @@ class NstSV(datasets.GeneratorBasedBuilder):
161
  'up_votes': datasets.Value("int32"),
162
  'down_votes': datasets.Value("int32"),
163
  'age': datasets.Value("string"),
164
- 'gender': datasets.Value("string"),
165
  'accent': datasets.Value("string"),
166
  'locale': datasets.Value("string"),
167
  'segment': datasets.Value("string"),
@@ -264,65 +249,46 @@ class NstSV(datasets.GeneratorBasedBuilder):
264
  with open(audio_filepath, "rb") as f:
265
  audio_bytes = f.read()
266
  if audio_bytes:
267
- info_dict = {
268
- "Age": annotation["info"]["Age"] or "",
269
- "Region_of_Birth": annotation["info"]["Region_of_Birth"] or "",
270
- "Region_of_Youth": annotation["info"]["Region_of_Youth"] or "",
271
- "Remarks": annotation["info"]["Remarks"] or "",
272
- "Sex": annotation["info"]["Sex"] or "",
273
- "Speaker_ID": annotation["info"]["Speaker_ID"] or "",
274
- },
275
- metadata_dict = {
276
- "file": annotation["metadata"]["file"] or "",
277
- "lang": annotation["metadata"]["lang"] or "",
278
- "path": annotation["metadata"]["path"] or "",
279
- "station": annotation["metadata"]["station"] or "",
280
- },
281
- session_dict = {
282
- "Directory": annotation["session"]["Directory"] or "",
283
- "Imported_sheet_file": annotation["session"]["Imported_sheet_file"] or "",
284
- "Number_of_recordings": annotation["session"]["Number_of_recordings"] or "",
285
- "RecDate": annotation["session"]["RecDate"] or "",
286
- "RecTime": annotation["session"]["RecTime"] or "",
287
- "Record_duration": annotation["session"]["Record_duration"] or "",
288
- "Record_session": annotation["session"]["Record_session"] or "",
289
- "Sheet_number": annotation["session"]["Sheet_number"] or "",
290
- },
291
- system_dict = {
292
- "ANSI_Codepage": annotation["system"]["ANSI_Codepage"] or "",
293
- "Board": annotation["system"]["Board"] or "",
294
- "ByteFormat": annotation["system"]["ByteFormat"] or "",
295
- "Channels": annotation["system"]["Channels"] or "",
296
- "CharacterSet": annotation["system"]["CharacterSet"] or "",
297
- "Coding": annotation["system"]["Coding"] or "",
298
- "DOS_Codepage": annotation["system"]["DOS_Codepage"] or "",
299
- "Delimiter": annotation["system"]["Delimiter"] or "",
300
- "Frequency": annotation["system"]["Frequency"] or "",
301
- "Memo": annotation["system"]["Memo"] or "",
302
- "Script": annotation["system"]["Script"] or "",
303
- "Version": annotation["system"]["Version"] or "",
304
- },
305
- result = {
306
- "info": info_dict,
307
- "metadata": metadata_dict,
308
- "pid": annotation["pid"],
309
- "session": session_dict,
310
- "system": system_dict,
311
- "client_id": annotation["info"]["Speaker_ID"] or "",
312
  'path': rel_filepath,
313
- 'audio': {"path": rel_filepath, "bytes": audio_bytes},
314
  'sentence': recording["text"],
315
- 'up_votes': 0,
316
  'down_votes': 0,
317
- 'age':annotation["info"]["Age"] or "",
318
- 'gender':annotation["info"]["Sex"] or "",
319
  'accent': "",
320
  'locale': "sv",
321
  'segment': "",
322
- 'channel': self.config.name
323
  }
324
  print(f"Yielding {rel_filepath}")
325
- yield rel_filepath, result
326
 
327
  else:
328
  files_failed_loading.append(rel_filepath)
 
115
 
116
  def _info(self):
117
  features_dict = {
118
+ "region_of_birth": datasets.Value("string"),
119
+ "region_of_youth": datasets.Value("string"),
120
+ "remarks": datasets.Value("string"),
 
 
 
 
 
 
 
 
 
 
 
121
  "pid": datasets.Value("string"),
122
+ "directory": datasets.Value("string"),
123
+ "imported_sheet_file": datasets.Value("string"),
124
+ "mumber_of_recordings": datasets.Value("string"),
125
+ "rec_date": datasets.Value("string"),
126
+ "rec_time": datasets.Value("string"),
127
+ "record_duration": datasets.Value("string"),
128
+ "record_session": datasets.Value("string"),
129
+ "sheet_number": datasets.Value("string"),
130
+ "ansi_codepage": datasets.Value("string"),
131
+ "board": datasets.Value("string"),
132
+ "byte_format": datasets.Value("string"),
133
+ "channels": datasets.Value("string"),
134
+ "character_set": datasets.Value("string"),
135
+ "coding": datasets.Value("string"),
136
+ "dos_codepage": datasets.Value("string"),
137
+ "delimiter": datasets.Value("string"),
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=16000),
143
  'client_id': datasets.Value("string"),
144
  'path': datasets.Value("string"),
 
146
  'up_votes': datasets.Value("int32"),
147
  'down_votes': datasets.Value("int32"),
148
  'age': datasets.Value("string"),
149
+ 'sex': datasets.Value("string"),
150
  'accent': datasets.Value("string"),
151
  'locale': datasets.Value("string"),
152
  'segment': datasets.Value("string"),
 
249
  with open(audio_filepath, "rb") as f:
250
  audio_bytes = f.read()
251
  if audio_bytes:
252
+ results = {
253
+ "region_of_birth": annotation["info"]["Region_of_Birth"] or "",
254
+ "region_of_youth": annotation["info"]["Region_of_Youth"] or "",
255
+ "remarks": annotation["info"]["Remarks"] or "",
256
+ "pid": annotation["pid"] or "",
257
+ "directory": annotation["session"]["Directory"] or "",
258
+ "imported_sheet_file": annotation["session"]["Imported_sheet_file"] or "",
259
+ "mumber_of_recordings": annotation["session"]["Number_of_recordings"] or "",
260
+ "rec_date": annotation["session"]["RecDate"] or "",
261
+ "rec_time": annotation["session"]["RecTime"] or "",
262
+ "record_duration": annotation["session"]["Record_duration"] or "",
263
+ "record_session": annotation["session"]["Record_session"] or "",
264
+ "sheet_number": annotation["session"]["Sheet_number"] or "",
265
+ "ansi_codepage": annotation["system"]["ANSI_Codepage"] or "",
266
+ "board": annotation["system"]["Board"] or "",
267
+ "byte_format": annotation["system"]["ByteFormat"] or "",
268
+ "channels": annotation["system"]["Channels"] or "",
269
+ "character_set": annotation["system"]["CharacterSet"] or "",
270
+ "coding": annotation["system"]["Coding"] or "",
271
+ "dos_codepage": annotation["system"]["DOS_Codepage"] or "",
272
+ "delimiter": annotation["system"]["Delimiter"] or "",
273
+ "frequency": annotation["system"]["Frequency"] or "",
274
+ "memo": annotation["system"]["Memo"] or "",
275
+ "script": annotation["system"]["Script"] or "",
276
+ "version": annotation["system"]["Version"] or "",
277
+ "audio": {"path": rel_filepath, "bytes": audio_bytes},
278
+ 'client_id': annotation["info"]["Speaker_ID"] or "",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  'path': rel_filepath,
 
280
  'sentence': recording["text"],
281
+ 'up_votes': 1,
282
  'down_votes': 0,
283
+ 'age': annotation["info"]["Age"] or "",
284
+ 'sex': annotation["info"]["Sex"] or "",
285
  'accent': "",
286
  'locale': "sv",
287
  'segment': "",
288
+ 'channel': self.config.name or ""
289
  }
290
  print(f"Yielding {rel_filepath}")
291
+ yield rel_filepath, results
292
 
293
  else:
294
  files_failed_loading.append(rel_filepath)