Commit
·
744adff
1
Parent(s):
eb2a9f7
Update README.md
Browse files
README.md
CHANGED
|
@@ -36,7 +36,7 @@ model-index:
|
|
| 36 |
|
| 37 |
type: common_voice
|
| 38 |
|
| 39 |
-
args:
|
| 40 |
|
| 41 |
metrics:
|
| 42 |
|
|
@@ -82,11 +82,11 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
| 82 |
|
| 83 |
def speech_file_to_array_fn(batch):
|
| 84 |
|
| 85 |
-
|
| 86 |
|
| 87 |
-
|
| 88 |
|
| 89 |
-
|
| 90 |
|
| 91 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
| 92 |
|
|
@@ -94,7 +94,7 @@ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tens
|
|
| 94 |
|
| 95 |
with torch.no_grad():
|
| 96 |
|
| 97 |
-
|
| 98 |
|
| 99 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 100 |
|
|
@@ -130,7 +130,7 @@ model = Wav2Vec2ForCTC.from_pretrained("DeividasM/wav2vec2-large-xlsr-53-lithuan
|
|
| 130 |
|
| 131 |
model.to("cuda")
|
| 132 |
|
| 133 |
-
chars_to_ignore_regex = '[
|
| 134 |
|
| 135 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
| 136 |
|
|
@@ -140,13 +140,13 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
| 140 |
|
| 141 |
def speech_file_to_array_fn(batch):
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
| 146 |
|
| 147 |
-
|
| 148 |
|
| 149 |
-
|
| 150 |
|
| 151 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
| 152 |
|
|
@@ -156,17 +156,17 @@ test_dataset = test_dataset.map(speech_file_to_array_fn)
|
|
| 156 |
|
| 157 |
def evaluate(batch):
|
| 158 |
|
| 159 |
-
|
| 160 |
|
| 161 |
-
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
pred_ids = torch.argmax(logits, dim=-1)
|
| 166 |
|
| 167 |
-
|
| 168 |
|
| 169 |
-
|
| 170 |
|
| 171 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
| 172 |
|
|
|
|
| 36 |
|
| 37 |
type: common_voice
|
| 38 |
|
| 39 |
+
args: lt
|
| 40 |
|
| 41 |
metrics:
|
| 42 |
|
|
|
|
| 82 |
|
| 83 |
def speech_file_to_array_fn(batch):
|
| 84 |
|
| 85 |
+
\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
| 86 |
|
| 87 |
+
\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
| 88 |
|
| 89 |
+
\\treturn batch
|
| 90 |
|
| 91 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
| 92 |
|
|
|
|
| 94 |
|
| 95 |
with torch.no_grad():
|
| 96 |
|
| 97 |
+
\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
| 98 |
|
| 99 |
predicted_ids = torch.argmax(logits, dim=-1)
|
| 100 |
|
|
|
|
| 130 |
|
| 131 |
model.to("cuda")
|
| 132 |
|
| 133 |
+
chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
|
| 134 |
|
| 135 |
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
| 136 |
|
|
|
|
| 140 |
|
| 141 |
def speech_file_to_array_fn(batch):
|
| 142 |
|
| 143 |
+
\\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
| 144 |
|
| 145 |
+
\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
| 146 |
|
| 147 |
+
\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
| 148 |
|
| 149 |
+
\\treturn batch
|
| 150 |
|
| 151 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
| 152 |
|
|
|
|
| 156 |
|
| 157 |
def evaluate(batch):
|
| 158 |
|
| 159 |
+
\\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
| 160 |
|
| 161 |
+
\\twith torch.no_grad():
|
| 162 |
|
| 163 |
+
\\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
| 164 |
|
| 165 |
pred_ids = torch.argmax(logits, dim=-1)
|
| 166 |
|
| 167 |
+
\\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
| 168 |
|
| 169 |
+
\\treturn batch
|
| 170 |
|
| 171 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
| 172 |
|