Commit
·
053169a
1
Parent(s):
1eb35a0
Update README.md
Browse files
README.md
CHANGED
@@ -22,7 +22,6 @@ model-index:
|
|
22 |
metrics:
|
23 |
- name: Test WER
|
24 |
type: wer
|
25 |
-
value: 3.67
|
26 |
---
|
27 |
# Wav2Vec2-Large-XLSR-53-Dhivehi
|
28 |
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Dhivehi using the [Common Voice](https://huggingface.co/datasets/common_voice).
|
@@ -40,13 +39,13 @@ model = Wav2Vec2ForCTC.from_pretrained("shahukareem/wav2vec2-large-xlsr-53-dhive
|
|
40 |
# Preprocessing the datasets.
|
41 |
# We need to read the aduio files as arrays
|
42 |
def speech_file_to_array_fn(batch):
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
47 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
48 |
with torch.no_grad():
|
49 |
-
|
50 |
predicted_ids = torch.argmax(logits, dim=-1)
|
51 |
print("Prediction:", processor.batch_decode(predicted_ids))
|
52 |
print("Reference:", test_dataset["sentence"][:2])
|
@@ -69,20 +68,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 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
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 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
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 |
```
|
|
|
22 |
metrics:
|
23 |
- name: Test WER
|
24 |
type: wer
|
|
|
25 |
---
|
26 |
# Wav2Vec2-Large-XLSR-53-Dhivehi
|
27 |
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Dhivehi using the [Common Voice](https://huggingface.co/datasets/common_voice).
|
|
|
39 |
# Preprocessing the datasets.
|
40 |
# We need to read the aduio files as arrays
|
41 |
def speech_file_to_array_fn(batch):
|
42 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
43 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
44 |
+
\treturn batch
|
45 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
46 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
47 |
with torch.no_grad():
|
48 |
+
\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
49 |
predicted_ids = torch.argmax(logits, dim=-1)
|
50 |
print("Prediction:", processor.batch_decode(predicted_ids))
|
51 |
print("Reference:", test_dataset["sentence"][:2])
|
|
|
68 |
# Preprocessing the datasets.
|
69 |
# We need to read the aduio files as arrays
|
70 |
def speech_file_to_array_fn(batch):
|
71 |
+
\tbatch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
72 |
+
\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
|
73 |
+
\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
|
74 |
+
\treturn batch
|
75 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
76 |
# Preprocessing the datasets.
|
77 |
# We need to read the aduio files as arrays
|
78 |
def evaluate(batch):
|
79 |
+
\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
80 |
+
\twith torch.no_grad():
|
81 |
+
\t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
82 |
+
\tpred_ids = torch.argmax(logits, dim=-1)
|
83 |
+
\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
|
84 |
+
\treturn batch
|
85 |
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
86 |
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
87 |
```
|