retineo commited on
Commit
0f0dda3
·
verified ·
1 Parent(s): 92d6eb7

Split train,dev,test

Browse files
Files changed (1) hide show
  1. su_id_asr_split.py +70 -41
su_id_asr_split.py CHANGED
@@ -93,50 +93,79 @@ class SuIdASR(datasets.GeneratorBasedBuilder):
93
  )
94
 
95
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
96
- return [
97
- datasets.SplitGenerator(
98
- name=datasets.Split.TRAIN,
99
- gen_kwargs={"filepath": dl_manager.download_and_extract(_URLs["su_id_asr"].format(str(0)))},
100
- ),
101
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- def _generate_examples(self, filepath: str):
104
 
105
- if self.config.schema == "source" or self.config.schema == "seacrowd_sptext":
106
 
107
- tsv_file = os.path.join(filepath, "asr_sundanese", "utt_spk_text.tsv")
108
-
109
- with open(tsv_file, "r") as file:
110
- tsv_file = csv.reader(file, delimiter="\t")
111
-
112
- for line in tsv_file:
113
- audio_id, speaker_id, transcription_text = line[0], line[1], line[2]
114
-
115
- wav_path = os.path.join(filepath, "asr_sundanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
116
-
117
- if os.path.exists(wav_path):
118
- if self.config.schema == "source":
119
- ex = {
120
- "id": audio_id,
121
- "speaker_id": speaker_id,
122
- "path": wav_path,
123
- "audio": wav_path,
124
- "text": transcription_text,
125
- }
126
- yield audio_id, ex
127
- elif self.config.schema == "seacrowd_sptext":
128
- ex = {
129
- "id": audio_id,
130
- "speaker_id": speaker_id,
131
- "path": wav_path,
132
- "audio": wav_path,
133
- "text": transcription_text,
134
- "metadata": {
135
- "speaker_age": None,
136
- "speaker_gender": None,
137
- },
138
- }
139
- yield audio_id, ex
140
 
141
  else:
142
  raise ValueError(f"Invalid config: {self.config.name}")
 
93
  )
94
 
95
  def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
96
+ lines = []
97
+ filepath = dl_manager.download_and_extract(_URLs["su_id_asr"].format(str(0)))
98
+ tsv_file = os.path.join(filepath, "asr_sundanese", "utt_spk_text.tsv")
99
+
100
+ with open(tsv_file, "r") as file:
101
+ tsv_file = csv.reader(file, delimiter="\t")
102
+
103
+ for line in tsv_file:
104
+ lines.append(line)
105
+
106
+ rlen = len(lines)
107
+ train = lines[:8*rlen//10]
108
+ lines = lines[8*rlen//10:]
109
+ dev = lines[:rlen//10+1]
110
+ lines = lines[rlen//10+1:]
111
+ test = lines
112
+
113
+ split_generators = []
114
+ split_names = {
115
+ "train": datasets.Split.TRAIN,
116
+ "dev": datasets.Split.VALIDATION,
117
+ "test": datasets.Split.TEST,
118
+ }
119
+ split_set = {
120
+ "train": train,
121
+ "dev": dev,
122
+ "test": test,
123
+ }
124
+
125
+ for split in ("train", "dev", "test"):
126
+ split_generators.append(
127
+ datasets.SplitGenerator(
128
+ name=split_names.get(split),
129
+ gen_kwargs={
130
+ "tsv_file": split_set.get(split),
131
+ },
132
+ ),
133
+ )
134
 
135
+ return split_generators
136
 
137
+ def _generate_examples(self, tsv_file):
138
 
139
+ if self.config.schema == "source" or self.config.schema == "seacrowd_sptext":
140
+
141
+ for line in tsv_file:
142
+ audio_id, speaker_id, transcription_text = line[0], line[1], line[2]
143
+
144
+ wav_path = os.path.join(filepath, "asr_sundanese", "data", "{}".format(audio_id[:2]), "{}.flac".format(audio_id))
145
+
146
+ if os.path.exists(wav_path):
147
+ if self.config.schema == "source":
148
+ ex = {
149
+ "id": audio_id,
150
+ "speaker_id": speaker_id,
151
+ "path": wav_path,
152
+ "audio": wav_path,
153
+ "text": transcription_text,
154
+ }
155
+ yield audio_id, ex
156
+ elif self.config.schema == "seacrowd_sptext":
157
+ ex = {
158
+ "id": audio_id,
159
+ "speaker_id": speaker_id,
160
+ "path": wav_path,
161
+ "audio": wav_path,
162
+ "text": transcription_text,
163
+ "metadata": {
164
+ "speaker_age": None,
165
+ "speaker_gender": None,
166
+ },
167
+ }
168
+ yield audio_id, ex
 
 
 
169
 
170
  else:
171
  raise ValueError(f"Invalid config: {self.config.name}")