Update README.md
Browse files
README.md
CHANGED
@@ -1,63 +1 @@
|
|
1 |
-
|
2 |
-
language: nl
|
3 |
-
datasets:
|
4 |
-
- common_voice
|
5 |
-
tags:
|
6 |
-
- speech
|
7 |
-
- audio
|
8 |
-
- automatic-speech-recognition
|
9 |
-
license: apache-2.0
|
10 |
-
---
|
11 |
-
|
12 |
-
## Evaluation on Common Voice NL Test
|
13 |
-
|
14 |
-
```python
|
15 |
-
import torchaudio
|
16 |
-
from datasets import load_dataset, load_metric
|
17 |
-
from transformers import (
|
18 |
-
Wav2Vec2ForCTC,
|
19 |
-
Wav2Vec2Processor,
|
20 |
-
)
|
21 |
-
import torch
|
22 |
-
import re
|
23 |
-
import sys
|
24 |
-
|
25 |
-
model_name = "facebook/wav2vec2-large-xlsr-53-dutch"
|
26 |
-
device = "cuda"
|
27 |
-
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"]' # noqa: W605
|
28 |
-
|
29 |
-
model = Wav2Vec2ForCTC.from_pretrained(model_name).to(device)
|
30 |
-
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
31 |
-
|
32 |
-
ds = load_dataset("common_voice", "nl", split="test", data_dir="./cv-corpus-6.1-2020-12-11")
|
33 |
-
|
34 |
-
resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000)
|
35 |
-
|
36 |
-
def map_to_array(batch):
|
37 |
-
speech, _ = torchaudio.load(batch["path"])
|
38 |
-
batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
|
39 |
-
batch["sampling_rate"] = resampler.new_freq
|
40 |
-
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
|
41 |
-
return batch
|
42 |
-
|
43 |
-
ds = ds.map(map_to_array)
|
44 |
-
|
45 |
-
|
46 |
-
def map_to_pred(batch):
|
47 |
-
features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
|
48 |
-
input_values = features.input_values.to(device)
|
49 |
-
attention_mask = features.attention_mask.to(device)
|
50 |
-
with torch.no_grad():
|
51 |
-
logits = model(input_values, attention_mask=attention_mask).logits
|
52 |
-
pred_ids = torch.argmax(logits, dim=-1)
|
53 |
-
batch["predicted"] = processor.batch_decode(pred_ids)
|
54 |
-
batch["target"] = batch["sentence"]
|
55 |
-
return batch
|
56 |
-
|
57 |
-
result = ds.map(map_to_pred, batched=True, batch_size=16, remove_columns=list(ds.features.keys()))
|
58 |
-
|
59 |
-
wer = load_metric("wer")
|
60 |
-
print(wer.compute(predictions=result["predicted"], references=result["target"]))
|
61 |
-
```
|
62 |
-
|
63 |
-
**Result**: 21.1 %
|
|
|
1 |
+
Copy of "facebook/wav2vec2-large-xlsr-53-dutch"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|