MehdiHosseiniMoghadam commited on
Commit
2832cb4
1 Parent(s): 2657eb7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -18
README.md CHANGED
@@ -82,11 +82,11 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
82
 
83
  def speech_file_to_array_fn(batch):
84
 
85
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
86
 
87
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
88
 
89
- \treturn batch
90
 
91
  test_dataset = test_dataset.map(speech_file_to_array_fn)
92
 
@@ -94,7 +94,7 @@ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tens
94
 
95
  with torch.no_grad():
96
 
97
- \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
98
 
99
  predicted_ids = torch.argmax(logits, dim=-1)
100
 
@@ -130,7 +130,7 @@ model = Wav2Vec2ForCTC.from_pretrained("MehdiHosseiniMoghadam/wav2vec2-large-xls
130
 
131
  model.to("cuda")
132
 
133
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
134
 
135
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
136
 
@@ -140,13 +140,13 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
140
 
141
  def speech_file_to_array_fn(batch):
142
 
143
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
144
-
145
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
146
-
147
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
148
-
149
- \treturn batch
150
 
151
  test_dataset = test_dataset.map(speech_file_to_array_fn)
152
 
@@ -156,17 +156,17 @@ test_dataset = test_dataset.map(speech_file_to_array_fn)
156
 
157
  def evaluate(batch):
158
 
159
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
160
 
161
- \twith torch.no_grad():
162
 
163
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
164
 
165
- pred_ids = torch.argmax(logits, dim=-1)
166
 
167
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
168
 
169
- \treturn batch
170
 
171
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
172
 
 
82
 
83
  def speech_file_to_array_fn(batch):
84
 
85
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
86
 
87
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
88
 
89
+ return batch
90
 
91
  test_dataset = test_dataset.map(speech_file_to_array_fn)
92
 
 
94
 
95
  with torch.no_grad():
96
 
97
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
98
 
99
  predicted_ids = torch.argmax(logits, dim=-1)
100
 
 
130
 
131
  model.to("cuda")
132
 
133
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
134
 
135
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
136
 
 
140
 
141
  def speech_file_to_array_fn(batch):
142
 
143
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
144
+
145
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
146
+
147
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
148
+
149
+ return batch
150
 
151
  test_dataset = test_dataset.map(speech_file_to_array_fn)
152
 
 
156
 
157
  def evaluate(batch):
158
 
159
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
160
 
161
+ with torch.no_grad():
162
 
163
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
164
 
165
+ pred_ids = torch.argmax(logits, dim=-1)
166
 
167
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
168
 
169
+ return batch
170
 
171
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
172