Update README.md
Browse files
README.md
CHANGED
@@ -57,15 +57,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
57 |
# Preprocessing the datasets.
|
58 |
# We need to read the aduio files as arrays
|
59 |
def speech_file_to_array_fn(batch):
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
|
64 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
65 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
66 |
|
67 |
with torch.no_grad():
|
68 |
-
|
69 |
|
70 |
predicted_ids = torch.argmax(logits, dim=-1)
|
71 |
|
@@ -93,37 +93,37 @@ processor = Wav2Vec2Processor.from_pretrained("Rubens/Wav2Vec2-Large-XLSR-53-Por
|
|
93 |
model = Wav2Vec2ForCTC.from_pretrained("Rubens/Wav2Vec2-Large-XLSR-53-Portuguese")
|
94 |
model.to("cuda")
|
95 |
|
96 |
-
chars_to_ignore_regex = '[
|
97 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
98 |
|
99 |
# Preprocessing the datasets.
|
100 |
# We need to read the aduio files as arrays
|
101 |
def speech_file_to_array_fn(batch):
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
108 |
|
109 |
# Preprocessing the datasets.
|
110 |
# We need to read the aduio files as arrays
|
111 |
def evaluate(batch):
|
112 |
-
|
113 |
|
114 |
-
|
115 |
-
|
116 |
|
117 |
pred_ids = torch.argmax(logits, dim=-1)
|
118 |
-
|
119 |
-
|
120 |
|
121 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
122 |
|
123 |
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
124 |
```
|
125 |
|
126 |
-
**Test Result**: 20.41 %
|
127 |
|
128 |
|
129 |
## Training
|
|
|
57 |
# Preprocessing the datasets.
|
58 |
# We need to read the aduio files as arrays
|
59 |
def speech_file_to_array_fn(batch):
|
60 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
61 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
62 |
+
\treturn batch
|
63 |
|
64 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
65 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
66 |
|
67 |
with torch.no_grad():
|
68 |
+
\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
69 |
|
70 |
predicted_ids = torch.argmax(logits, dim=-1)
|
71 |
|
|
|
93 |
model = Wav2Vec2ForCTC.from_pretrained("Rubens/Wav2Vec2-Large-XLSR-53-Portuguese")
|
94 |
model.to("cuda")
|
95 |
|
96 |
+
chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]' # TODO: adapt this list to include all special characters you removed from the data
|
97 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
98 |
|
99 |
# Preprocessing the datasets.
|
100 |
# We need to read the aduio files as arrays
|
101 |
def speech_file_to_array_fn(batch):
|
102 |
+
\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
103 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
104 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
105 |
+
\treturn batch
|
106 |
|
107 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
108 |
|
109 |
# Preprocessing the datasets.
|
110 |
# We need to read the aduio files as arrays
|
111 |
def evaluate(batch):
|
112 |
+
\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
113 |
|
114 |
+
\twith torch.no_grad():
|
115 |
+
\t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
116 |
|
117 |
pred_ids = torch.argmax(logits, dim=-1)
|
118 |
+
\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
119 |
+
\treturn batch
|
120 |
|
121 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
122 |
|
123 |
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
124 |
```
|
125 |
|
126 |
+
**Test Result (wer)**: 20.41 %
|
127 |
|
128 |
|
129 |
## Training
|