Update README.md
Browse files
README.md
CHANGED
@@ -8,7 +8,7 @@ model-index:
|
|
8 |
|
9 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
10 |
should probably proofread and complete it, then remove this comment. -->
|
11 |
-
|
12 |
# wav2vec2-xls-r-300m-romanian
|
13 |
|
14 |
This model is a fine-tuned version of [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) on an unknown dataset.
|
@@ -56,3 +56,51 @@ The following hyperparameters were used during training:
|
|
56 |
- Pytorch 1.10.0+cu111
|
57 |
- Datasets 1.13.3
|
58 |
- Tokenizers 0.10.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
10 |
should probably proofread and complete it, then remove this comment. -->
|
11 |
+
## This model achieves WER on common-voice ro test split of WER: 14.602631%
|
12 |
# wav2vec2-xls-r-300m-romanian
|
13 |
|
14 |
This model is a fine-tuned version of [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) on an unknown dataset.
|
|
|
56 |
- Pytorch 1.10.0+cu111
|
57 |
- Datasets 1.13.3
|
58 |
- Tokenizers 0.10.3
|
59 |
+
|
60 |
+
|
61 |
+
Used the following code for evaluation:
|
62 |
+
```
|
63 |
+
import torch
|
64 |
+
import torchaudio
|
65 |
+
from datasets import load_dataset, load_metric
|
66 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
67 |
+
import re
|
68 |
+
|
69 |
+
test_dataset = load_dataset("common_voice", "ro", split="test")
|
70 |
+
wer = load_metric("wer")
|
71 |
+
|
72 |
+
processor = Wav2Vec2Processor.from_pretrained("Dumiiii/wav2vec2-xls-r-300m-romanian")
|
73 |
+
model = Wav2Vec2ForCTC.from_pretrained("Dumiiii/wav2vec2-xls-r-300m-romanian")
|
74 |
+
model.to("cuda")
|
75 |
+
|
76 |
+
chars_to_ignore_regex = '[\\\\\\\\,\\\\\\\\?\\\\\\\\.\\\\\\\\!\\\\\\\\-\\\\\\\\;\\\\\\\\:\\\\\\\\"\\\\\\\\“]'
|
77 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
78 |
+
|
79 |
+
# Preprocessing the datasets.
|
80 |
+
# We need to read the aduio files as arrays
|
81 |
+
def speech_file_to_array_fn(batch):
|
82 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
83 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
84 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
85 |
+
return batch
|
86 |
+
|
87 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
88 |
+
|
89 |
+
# Preprocessing the datasets.
|
90 |
+
# We need to read the aduio files as arrays
|
91 |
+
def evaluate(batch):
|
92 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
93 |
+
|
94 |
+
with torch.no_grad():
|
95 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
96 |
+
|
97 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
98 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
99 |
+
return batch
|
100 |
+
|
101 |
+
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
102 |
+
|
103 |
+
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
104 |
+
```
|
105 |
+
|
106 |
+
Credits for evaluation: https://huggingface.co/anton-l
|