RuudVelo commited on
Commit
b11dd2f
2 Parent(s): 2f120f2 d7249dc

Merge branch 'main' of https://huggingface.co/RuudVelo/wav2vec2-large-xlsr-53-frisian into main

Browse files
Files changed (1) hide show
  1. README.md +76 -0
README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: fy-NL
3
+ tags:
4
+ - audio
5
+ - automatic-speech-recognition
6
+ - speech
7
+ - xlsr-fine-tuning-week
8
+ license: apache-2.0
9
+ model-index:
10
+ - name: wav2vec2-large-xlsr-53-frisian by RuudVelo
11
+ results:
12
+ - task:
13
+ name: Speech Recognition
14
+ type: automatic-speech-recognition
15
+ dataset:
16
+ name: Common Voice fy-NL
17
+ type: common_voice
18
+ args: fy-NL
19
+ metrics:
20
+ - name: Test WER
21
+ type: wer
22
+ value: 20.35
23
+ ---
24
+
25
+
26
+ ## Evaluation on Common Voice Frisian Test
27
+
28
+ ```python
29
+ import torchaudio
30
+ from datasets import load_dataset, load_metric
31
+ from transformers import (
32
+ Wav2Vec2ForCTC,
33
+ Wav2Vec2Processor,
34
+ )
35
+ import torch
36
+ import re
37
+ import sys
38
+
39
+ model_name = "RuudVelo/wav2vec2-large-xlsr-53-frisian"
40
+ device = "cuda"
41
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“\\\\%\\\\‘\\\\”\\\\�]'
42
+
43
+ model = Wav2Vec2ForCTC.from_pretrained(model_name).to(device)
44
+ processor = Wav2Vec2Processor.from_pretrained(model_name)
45
+
46
+ ds = load_dataset("common_voice", "fy-NL", split="test", data_dir="./cv-corpus-6.1-2020-12-11")
47
+
48
+ resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000)
49
+
50
+ def map_to_array(batch):
51
+ speech, _ = torchaudio.load(batch["path"])
52
+ batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
53
+ batch["sampling_rate"] = resampler.new_freq
54
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
55
+ return batch
56
+
57
+ ds = ds.map(map_to_array)
58
+
59
+ def map_to_pred(batch):
60
+ features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
61
+ input_values = features.input_values.to(device)
62
+ attention_mask = features.attention_mask.to(device)
63
+ with torch.no_grad():
64
+ logits = model(input_values, attention_mask=attention_mask).logits
65
+ pred_ids = torch.argmax(logits, dim=-1)
66
+ batch["predicted"] = processor.batch_decode(pred_ids)
67
+ batch["target"] = batch["sentence"]
68
+ return batch
69
+
70
+ result = ds.map(map_to_pred, batched=True, batch_size=16, remove_columns=list(ds.features.keys()))
71
+
72
+ wer = load_metric("wer")
73
+ print(wer.compute(predictions=result["predicted"], references=result["target"]))
74
+ ```
75
+
76
+ **Result**: 20.35 %