shahukareem commited on
Commit
1eb35a0
·
1 Parent(s): b9faecc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -11
README.md CHANGED
@@ -69,20 +69,20 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
69
  # Preprocessing the datasets.
70
  # We need to read the aduio files as arrays
71
  def speech_file_to_array_fn(batch):
72
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
73
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
74
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
75
- \treturn batch
76
  test_dataset = test_dataset.map(speech_file_to_array_fn)
77
  # Preprocessing the datasets.
78
  # We need to read the aduio files as arrays
79
  def evaluate(batch):
80
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
81
- \twith torch.no_grad():
82
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
83
- \tpred_ids = torch.argmax(logits, dim=-1)
84
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
85
- \treturn batch
86
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
87
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
88
- ```
 
69
  # Preprocessing the datasets.
70
  # We need to read the aduio files as arrays
71
  def speech_file_to_array_fn(batch):
72
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
73
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
74
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
75
+ return batch
76
  test_dataset = test_dataset.map(speech_file_to_array_fn)
77
  # Preprocessing the datasets.
78
  # We need to read the aduio files as arrays
79
  def evaluate(batch):
80
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
81
+ with torch.no_grad():
82
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
83
+ pred_ids = torch.argmax(logits, dim=-1)
84
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
85
+ return batch
86
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
87
  print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
88
+ ```