Vu Minh Chien
commited on
Commit
•
b176118
1
Parent(s):
0968358
update readme
Browse files
README.md
CHANGED
@@ -87,20 +87,20 @@ resampler = lambda sr, y: librosa.resample(y.numpy().squeeze(), sr, 16_000)
|
|
87 |
|
88 |
# Preprocessing the datasets.
|
89 |
def speech_file_to_array_fn(batch):
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
96 |
|
97 |
# evaluate function
|
98 |
def evaluate(batch):
|
99 |
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
100 |
with torch.no_grad():
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
return batch
|
105 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
106 |
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
|
|
87 |
|
88 |
# Preprocessing the datasets.
|
89 |
def speech_file_to_array_fn(batch):
|
90 |
+
batch["sentence"] = wakati.parse(batch["sentence"]).strip()
|
91 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex,'', batch["sentence"]).strip()
|
92 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
93 |
+
batch["speech"] = resampler(sampling_rate, speech_array).squeeze()
|
94 |
+
return batch
|
95 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
96 |
|
97 |
# evaluate function
|
98 |
def evaluate(batch):
|
99 |
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
100 |
with torch.no_grad():
|
101 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
102 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
103 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
104 |
return batch
|
105 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
106 |
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|