bayartsogt commited on
Commit
b0878c8
1 Parent(s): 4139062

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -11
README.md CHANGED
@@ -51,30 +51,30 @@ processor = Wav2Vec2Processor.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mo
51
  model = Wav2Vec2ForCTC.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mongolian-v1")
52
  model.to("cuda")
53
 
54
- chars_to_ignore_regex = '[\\!\\"\\'\\,\\.\\«\\»\\?\\-]'
55
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
56
 
57
  # Preprocessing the datasets.
58
  # We need to read the aduio files as arrays
59
  def speech_file_to_array_fn(batch):
60
- \tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
61
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
62
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
63
- \treturn batch
64
 
65
  test_dataset = test_dataset.map(speech_file_to_array_fn)
66
 
67
  # Preprocessing the datasets.
68
  # We need to read the aduio files as arrays
69
  def evaluate(batch):
70
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
71
 
72
- \twith torch.no_grad():
73
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
74
 
75
- \tpred_ids = torch.argmax(logits, dim=-
76
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
77
- \treturn batch
78
 
79
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
80
 
 
51
  model = Wav2Vec2ForCTC.from_pretrained("bayartsogt/wav2vec2-large-xlsr-mongolian-v1")
52
  model.to("cuda")
53
 
54
+ chars_to_ignore_regex = '[\\\\!\\\\"\\\\'\\\\,\\\\.\\\\«\\\\»\\\\?\\\\-]'
55
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
56
 
57
  # Preprocessing the datasets.
58
  # We need to read the aduio files as arrays
59
  def speech_file_to_array_fn(batch):
60
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
61
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
62
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
63
+ return batch
64
 
65
  test_dataset = test_dataset.map(speech_file_to_array_fn)
66
 
67
  # Preprocessing the datasets.
68
  # We need to read the aduio files as arrays
69
  def evaluate(batch):
70
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
71
 
72
+ with torch.no_grad():
73
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
74
 
75
+ pred_ids = torch.argmax(logits, dim=-
76
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
77
+ return batch
78
 
79
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
80