Marxav commited on
Commit
4b10b36
1 Parent(s): 7a70725

Initial Commit

Browse files
Files changed (1) hide show
  1. README.md +90 -0
README.md ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: br
3
+ datasets:
4
+ - common_voice
5
+ tags:
6
+ - audio
7
+ - automatic-speech-recognition
8
+ - speech
9
+ - xlsr-fine-tuning-week
10
+ license: apache-2.0
11
+ model-index:
12
+ - name: XLSR Wav2Vec2 Breton by Marxav
13
+ results:
14
+ - task:
15
+ name: Speech Recognition
16
+ type: automatic-speech-recognition
17
+ dataset:
18
+ name: Common Voice br
19
+ type: common_voice
20
+ args: br
21
+ metrics:
22
+ - name: Test WER
23
+ type: wer
24
+ value: 44.34
25
+ ---
26
+ # Wav2Vec2-Large-XLSR-53-Breton
27
+ The model can be used directly (without a language model) as follows:
28
+ ```python
29
+ TODO
30
+ ```
31
+
32
+ The model can be evaluated as follows on the {language} test data of Common Voice.
33
+ ```python
34
+ import torch
35
+ import torchaudio
36
+ from datasets import load_dataset, load_metric
37
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
38
+ import re
39
+
40
+ test_dataset = load_dataset("common_voice", "br", split="test")
41
+ wer = load_metric("wer")
42
+
43
+ processor = Wav2Vec2Processor.from_pretrained('Marxav/wav2vec2-large-xlsr-53-breton')
44
+ model = Wav2Vec2ForCTC.from_pretrained('Marxav/wav2vec2-large-xlsr-53-breton')
45
+ model.to("cuda")
46
+
47
+
48
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\'\(\)\/\«\»\½\…]'
49
+
50
+ def remove_special_characters(batch):
51
+ sentence = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower() + " "
52
+ sentence = re.sub("ʼ","'", sentence)
53
+ sentence = re.sub("’","'", sentence)
54
+ batch["sentence"] = sentence
55
+ return batch
56
+
57
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
58
+
59
+ # Preprocessing the datasets.
60
+ # We need to read the aduio files as arrays
61
+ def speech_file_to_array_fn(batch):
62
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
63
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
64
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
65
+ return batch
66
+
67
+ test_dataset = test_dataset.map(remove_special_characters)
68
+
69
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
70
+
71
+ # Preprocessing the datasets.
72
+ # We need to read the aduio files as arrays
73
+ def evaluate(batch):
74
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
75
+
76
+ with torch.no_grad():
77
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
78
+
79
+ pred_ids = torch.argmax(logits, dim=-1)
80
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
81
+ return batch
82
+
83
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
84
+
85
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
86
+ ```
87
+
88
+ **Test Result**: 44.34%
89
+ ## Training
90
+ The Common Voice `train`, `validation` datasets were used for training.