update evaluation result
Browse files
README.md
CHANGED
@@ -54,15 +54,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
|
54 |
# Preprocessing the datasets.
|
55 |
# We need to read the aduio files as arrays
|
56 |
def speech_file_to_array_fn(batch):
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
|
61 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
62 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
63 |
|
64 |
with torch.no_grad():
|
65 |
-
|
66 |
|
67 |
predicted_ids = torch.argmax(logits, dim=-1)
|
68 |
|
@@ -90,7 +90,7 @@ import argparse
|
|
90 |
lang_id = "zh-HK"
|
91 |
model_id = "ctl/wav2vec2-large-xlsr-cantonese"
|
92 |
|
93 |
-
chars_to_ignore_regex = '[
|
94 |
|
95 |
test_dataset = load_dataset("common_voice", f"{lang_id}", split="test")
|
96 |
cer = load_metric("./cer")
|
@@ -127,22 +127,6 @@ result = test_dataset.map(evaluate, batched=True, batch_size=16)
|
|
127 |
print("CER: {:2f}".format(100 * cer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
128 |
```
|
129 |
|
130 |
-
### Character Error Rate implementation
|
131 |
-
|
132 |
-
Adapting code from [wer](https://github.com/huggingface/datasets/blob/master/metrics/wer/wer.py)
|
133 |
-
|
134 |
-
```python
|
135 |
-
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION, _KWARGS_DESCRIPTION)
|
136 |
-
class CER(datasets.Metric):
|
137 |
-
def _info(self):
|
138 |
-
\t...
|
139 |
-
|
140 |
-
def _compute(self, predictions, references):
|
141 |
-
preds = [char for seq in predictions for char in list(seq)]
|
142 |
-
refs = [char for seq in references for char in list(seq)]
|
143 |
-
return wer(refs, preds)
|
144 |
-
```
|
145 |
-
|
146 |
|
147 |
**Test Result**: 15.51 %
|
148 |
|
|
|
54 |
# Preprocessing the datasets.
|
55 |
# We need to read the aduio files as arrays
|
56 |
def speech_file_to_array_fn(batch):
|
57 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
58 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
59 |
+
return batch
|
60 |
|
61 |
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
62 |
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
63 |
|
64 |
with torch.no_grad():
|
65 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
66 |
|
67 |
predicted_ids = torch.argmax(logits, dim=-1)
|
68 |
|
|
|
90 |
lang_id = "zh-HK"
|
91 |
model_id = "ctl/wav2vec2-large-xlsr-cantonese"
|
92 |
|
93 |
+
chars_to_ignore_regex = '[\,\?\.\!\-\;\:"\“\%\‘\”\�\.\⋯\!\-\:\–\。\》\,\)\,\?\;\~\~\…\︰\,\(\」\‧\《\﹔\、\—\/\,\「\﹖\·\']'
|
94 |
|
95 |
test_dataset = load_dataset("common_voice", f"{lang_id}", split="test")
|
96 |
cer = load_metric("./cer")
|
|
|
127 |
print("CER: {:2f}".format(100 * cer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
128 |
```
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
|
131 |
**Test Result**: 15.51 %
|
132 |
|