arampacha commited on
Commit
caad921
1 Parent(s): cadb64c

upd readme

Browse files
Files changed (1) hide show
  1. README.md +20 -20
README.md CHANGED
@@ -48,15 +48,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
48
  # Preprocessing the datasets.
49
  # We need to read the aduio files as arrays
50
  def speech_file_to_array_fn(batch):
51
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
52
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
53
- \\treturn batch
54
 
55
  test_dataset = test_dataset.map(speech_file_to_array_fn)
56
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
57
 
58
  with torch.no_grad():
59
- \\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
60
 
61
  predicted_ids = torch.argmax(logits, dim=-1)
62
 
@@ -92,30 +92,30 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
92
  # We need to read the aduio files as arrays
93
  # Note: this models is trained ignoring accents on letters as below
94
  def speech_file_to_array_fn(batch):
95
- \\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().strip()
96
- \\tbatch["sentence"] = re.sub(re.compile('[äá]'), 'a', batch['sentence'])
97
- \\tbatch["sentence"] = re.sub(re.compile('[öó]'), 'o', batch['sentence'])
98
- \\tbatch["sentence"] = re.sub(re.compile('[èé]'), 'e', batch['sentence'])
99
- \\tbatch["sentence"] = re.sub(re.compile("[ïí]"), 'i', batch['sentence'])
100
- \\tbatch["sentence"] = re.sub(re.compile("[üů]"), 'u', batch['sentence'])
101
- \\tbatch['sentence'] = re.sub(' ', ' ', batch['sentence'])
102
- \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
103
- \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
104
- \\treturn batch
105
 
106
  test_dataset = test_dataset.map(speech_file_to_array_fn)
107
 
108
  # Preprocessing the datasets.
109
  # We need to read the aduio files as arrays
110
  def evaluate(batch):
111
- \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
112
 
113
- \\twith torch.no_grad():
114
- \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
115
 
116
- \\tpred_ids = torch.argmax(logits, dim=-1)
117
- \\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
118
- \\treturn batch
119
 
120
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
121
 
 
48
  # Preprocessing the datasets.
49
  # We need to read the aduio files as arrays
50
  def speech_file_to_array_fn(batch):
51
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
52
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
53
+ return batch
54
 
55
  test_dataset = test_dataset.map(speech_file_to_array_fn)
56
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
57
 
58
  with torch.no_grad():
59
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
60
 
61
  predicted_ids = torch.argmax(logits, dim=-1)
62
 
 
92
  # We need to read the aduio files as arrays
93
  # Note: this models is trained ignoring accents on letters as below
94
  def speech_file_to_array_fn(batch):
95
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().strip()
96
+ batch["sentence"] = re.sub(re.compile('[äá]'), 'a', batch['sentence'])
97
+ batch["sentence"] = re.sub(re.compile('[öó]'), 'o', batch['sentence'])
98
+ batch["sentence"] = re.sub(re.compile('[èé]'), 'e', batch['sentence'])
99
+ batch["sentence"] = re.sub(re.compile("[ïí]"), 'i', batch['sentence'])
100
+ batch["sentence"] = re.sub(re.compile("[üů]"), 'u', batch['sentence'])
101
+ batch['sentence'] = re.sub(' ', ' ', batch['sentence'])
102
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
103
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
104
+ return batch
105
 
106
  test_dataset = test_dataset.map(speech_file_to_array_fn)
107
 
108
  # Preprocessing the datasets.
109
  # We need to read the aduio files as arrays
110
  def evaluate(batch):
111
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
112
 
113
+ with torch.no_grad():
114
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
115
 
116
+ pred_ids = torch.argmax(logits, dim=-1)
117
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
118
+ return batch
119
 
120
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
121