ivangtorre commited on
Commit
c5fe5b7
1 Parent(s): 0b2001e

Add model files

Browse files

README.md ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: eu
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 Basque Ivan G Torre
13
+ results:
14
+ - task:
15
+ name: Speech Recognition
16
+ type: automatic-speech-recognition
17
+ dataset:
18
+ name: Common Voice eu
19
+ type: common_voice
20
+ args: eu
21
+ metrics:
22
+ - name: Test WER
23
+ type: wer
24
+ value:
25
+ ---
26
+
27
+ # Wav2Vec2-Large-XLSR-53-euskera
28
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) in Euskera using the [Common Voice](https://huggingface.co/datasets/common_voice).
29
+ When using this model, make sure that your speech input is sampled at 16kHz.
30
+
31
+ ## Usage
32
+
33
+ The model can be used directly (without a language model) as follows:
34
+
35
+ ```python
36
+ import torch
37
+ import torchaudio
38
+ from datasets import load_dataset
39
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
40
+
41
+ test_dataset = load_dataset("common_voice", "eu", split="test[:2%]").
42
+
43
+ processor = Wav2Vec2Processor.from_pretrained("ivangtorre/wav2vec2-large-xlsr-53-basque")
44
+ model = Wav2Vec2ForCTC.from_pretrained("ivangtorre/wav2vec2-large-xlsr-53-basque")
45
+
46
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
47
+
48
+ # Preprocessing the datasets.
49
+ # We need to read the aduio files as arrays
50
+ def speech_file_to_array_fn(batch):
51
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
52
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
53
+ return batch
54
+
55
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
56
+ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
57
+
58
+ with torch.no_grad():
59
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
60
+
61
+ predicted_ids = torch.argmax(logits, dim=-1)
62
+
63
+ print("Prediction:", processor.batch_decode(predicted_ids))
64
+ print("Reference:", test_dataset["sentence"][:2])
65
+ ```
66
+
67
+
68
+ ## Evaluation
69
+
70
+ The model can be evaluated as follows on the Basque test data of Common Voice.
71
+
72
+
73
+ ```python
74
+ import torch
75
+ import torchaudio
76
+ from datasets import load_dataset, load_metric
77
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
78
+ import re
79
+
80
+ test_dataset = load_dataset("common_voice", "eu", split="test")
81
+ wer = load_metric("wer")
82
+
83
+ processor = Wav2Vec2Processor.from_pretrained("ivangtorre/wav2vec2-large-xlsr-53-basque")
84
+ model = Wav2Vec2ForCTC.from_pretrained("ivangtorre/wav2vec2-large-xlsr-53-basque")
85
+ model.to("cuda")
86
+
87
+ chars_to_ignore_regex = 'default=[",", "?", ".", "!", "-", ";", ":", '""', "%", "'", '"', "�"]'
88
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
89
+
90
+ # Preprocessing the datasets.
91
+ # We need to read the aduio files as arrays
92
+ def speech_file_to_array_fn(batch):
93
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
94
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
95
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
96
+ return batch
97
+
98
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
99
+
100
+ # Preprocessing the datasets.
101
+ # We need to read the aduio files as arrays
102
+ def evaluate(batch):
103
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
104
+
105
+ with torch.no_grad():
106
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
107
+
108
+ pred_ids = torch.argmax(logits, dim=-1)
109
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
110
+ return batch
111
+
112
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
113
+
114
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
115
+ ```
116
+
117
+ **Test Result**:
118
+
119
+
120
+ ## Training
121
+
122
+ The Common Voice `train`, `validation` datasets were used for training.
123
+
124
+ The script used for training can be found ???
config.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "facebook/wav2vec2-large-xlsr-53",
3
+ "activation_dropout": 0.07,
4
+ "apply_spec_augment": true,
5
+ "architectures": [
6
+ "Wav2Vec2ForCTC"
7
+ ],
8
+ "attention_dropout": 0.2,
9
+ "bos_token_id": 1,
10
+ "conv_bias": true,
11
+ "conv_dim": [
12
+ 512,
13
+ 512,
14
+ 512,
15
+ 512,
16
+ 512,
17
+ 512,
18
+ 512
19
+ ],
20
+ "conv_kernel": [
21
+ 10,
22
+ 3,
23
+ 3,
24
+ 3,
25
+ 3,
26
+ 2,
27
+ 2
28
+ ],
29
+ "conv_stride": [
30
+ 5,
31
+ 2,
32
+ 2,
33
+ 2,
34
+ 2,
35
+ 2,
36
+ 2
37
+ ],
38
+ "ctc_loss_reduction": "mean",
39
+ "ctc_zero_infinity": false,
40
+ "do_stable_layer_norm": true,
41
+ "eos_token_id": 2,
42
+ "feat_extract_activation": "gelu",
43
+ "feat_extract_dropout": 0.0,
44
+ "feat_extract_norm": "layer",
45
+ "feat_proj_dropout": 0.2,
46
+ "final_dropout": 0.0,
47
+ "gradient_checkpointing": true,
48
+ "hidden_act": "gelu",
49
+ "hidden_dropout": 0.04,
50
+ "hidden_size": 1024,
51
+ "initializer_range": 0.02,
52
+ "intermediate_size": 4096,
53
+ "layer_norm_eps": 1e-05,
54
+ "layerdrop": 0.05,
55
+ "mask_channel_length": 10,
56
+ "mask_channel_min_space": 1,
57
+ "mask_channel_other": 0.0,
58
+ "mask_channel_prob": 0.0,
59
+ "mask_channel_selection": "static",
60
+ "mask_feature_length": 10,
61
+ "mask_feature_prob": 0.0,
62
+ "mask_time_length": 10,
63
+ "mask_time_min_space": 1,
64
+ "mask_time_other": 0.0,
65
+ "mask_time_prob": 0.1,
66
+ "mask_time_selection": "static",
67
+ "model_type": "wav2vec2",
68
+ "num_attention_heads": 16,
69
+ "num_conv_pos_embedding_groups": 16,
70
+ "num_conv_pos_embeddings": 128,
71
+ "num_feat_extract_layers": 7,
72
+ "num_hidden_layers": 24,
73
+ "pad_token_id": 30,
74
+ "transformers_version": "4.4.2",
75
+ "vocab_size": 31
76
+ }
preprocessor_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "feature_size": 1,
4
+ "padding_side": "right",
5
+ "padding_value": 0.0,
6
+ "return_attention_mask": true,
7
+ "sampling_rate": 16000
8
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ab46384537a8ea6bbfd53bb2a4715eb721a0de52c3746a25aa3d5931eae1a37
3
+ size 1262055847
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "[UNK]", "pad_token": "[PAD]"}
tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
1
+ {"unk_token": "[UNK]", "bos_token": "<s>", "eos_token": "</s>", "pad_token": "[PAD]", "do_lower_case": false, "word_delimiter_token": "|"}
trainer_state.json ADDED
@@ -0,0 +1,240 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_metric": null,
3
+ "best_model_checkpoint": null,
4
+ "epoch": 18.95583596214511,
5
+ "global_step": 8000,
6
+ "is_hyper_param_search": false,
7
+ "is_local_process_zero": true,
8
+ "is_world_process_zero": true,
9
+ "log_history": [
10
+ {
11
+ "epoch": 1.18,
12
+ "learning_rate": 0.00011848341232227489,
13
+ "loss": 5.8456,
14
+ "step": 500
15
+ },
16
+ {
17
+ "epoch": 1.18,
18
+ "eval_loss": 2.693875551223755,
19
+ "eval_runtime": 1054.431,
20
+ "eval_samples_per_second": 4.905,
21
+ "eval_wer": 1.0,
22
+ "step": 500
23
+ },
24
+ {
25
+ "epoch": 2.37,
26
+ "learning_rate": 0.00023696682464454977,
27
+ "loss": 0.5706,
28
+ "step": 1000
29
+ },
30
+ {
31
+ "epoch": 2.37,
32
+ "eval_loss": 0.19720512628555298,
33
+ "eval_runtime": 965.5246,
34
+ "eval_samples_per_second": 5.357,
35
+ "eval_wer": 0.4136704756426013,
36
+ "step": 1000
37
+ },
38
+ {
39
+ "epoch": 3.55,
40
+ "learning_rate": 0.0003554502369668247,
41
+ "loss": 0.2135,
42
+ "step": 1500
43
+ },
44
+ {
45
+ "epoch": 3.55,
46
+ "eval_loss": 0.17894236743450165,
47
+ "eval_runtime": 829.9805,
48
+ "eval_samples_per_second": 6.231,
49
+ "eval_wer": 0.3831812357817117,
50
+ "step": 1500
51
+ },
52
+ {
53
+ "epoch": 4.74,
54
+ "learning_rate": 0.00039178515007898897,
55
+ "loss": 0.1761,
56
+ "step": 2000
57
+ },
58
+ {
59
+ "epoch": 4.74,
60
+ "eval_loss": 0.1792241483926773,
61
+ "eval_runtime": 839.1507,
62
+ "eval_samples_per_second": 6.163,
63
+ "eval_wer": 0.3637789922338729,
64
+ "step": 2000
65
+ },
66
+ {
67
+ "epoch": 5.92,
68
+ "learning_rate": 0.0003786203264876251,
69
+ "loss": 0.1403,
70
+ "step": 2500
71
+ },
72
+ {
73
+ "epoch": 5.92,
74
+ "eval_loss": 0.16667363047599792,
75
+ "eval_runtime": 773.0615,
76
+ "eval_samples_per_second": 6.69,
77
+ "eval_wer": 0.3549407734748843,
78
+ "step": 2500
79
+ },
80
+ {
81
+ "epoch": 7.11,
82
+ "learning_rate": 0.00036545550289626125,
83
+ "loss": 0.1206,
84
+ "step": 3000
85
+ },
86
+ {
87
+ "epoch": 7.11,
88
+ "eval_loss": 0.16922971606254578,
89
+ "eval_runtime": 754.7522,
90
+ "eval_samples_per_second": 6.853,
91
+ "eval_wer": 0.35033862406191985,
92
+ "step": 3000
93
+ },
94
+ {
95
+ "epoch": 8.29,
96
+ "learning_rate": 0.00035229067930489733,
97
+ "loss": 0.1065,
98
+ "step": 3500
99
+ },
100
+ {
101
+ "epoch": 8.29,
102
+ "eval_loss": 0.17697516083717346,
103
+ "eval_runtime": 830.9983,
104
+ "eval_samples_per_second": 6.224,
105
+ "eval_wer": 0.34748842925502704,
106
+ "step": 3500
107
+ },
108
+ {
109
+ "epoch": 9.48,
110
+ "learning_rate": 0.00033912585571353347,
111
+ "loss": 0.0949,
112
+ "step": 4000
113
+ },
114
+ {
115
+ "epoch": 9.48,
116
+ "eval_loss": 0.17623142898082733,
117
+ "eval_runtime": 808.622,
118
+ "eval_samples_per_second": 6.396,
119
+ "eval_wer": 0.34633789190178593,
120
+ "step": 4000
121
+ },
122
+ {
123
+ "epoch": 10.66,
124
+ "learning_rate": 0.0003259610321221696,
125
+ "loss": 0.0834,
126
+ "step": 4500
127
+ },
128
+ {
129
+ "epoch": 10.66,
130
+ "eval_loss": 0.17101719975471497,
131
+ "eval_runtime": 805.7401,
132
+ "eval_samples_per_second": 6.419,
133
+ "eval_wer": 0.33004732892294014,
134
+ "step": 4500
135
+ },
136
+ {
137
+ "epoch": 11.85,
138
+ "learning_rate": 0.0003127962085308057,
139
+ "loss": 0.0781,
140
+ "step": 5000
141
+ },
142
+ {
143
+ "epoch": 11.85,
144
+ "eval_loss": 0.1730242371559143,
145
+ "eval_runtime": 801.4866,
146
+ "eval_samples_per_second": 6.453,
147
+ "eval_wer": 0.3337342781685537,
148
+ "step": 5000
149
+ },
150
+ {
151
+ "epoch": 13.03,
152
+ "learning_rate": 0.00029963138493944183,
153
+ "loss": 0.0702,
154
+ "step": 5500
155
+ },
156
+ {
157
+ "epoch": 13.03,
158
+ "eval_loss": 0.1908612698316574,
159
+ "eval_runtime": 817.2678,
160
+ "eval_samples_per_second": 6.328,
161
+ "eval_wer": 0.3248437622571451,
162
+ "step": 5500
163
+ },
164
+ {
165
+ "epoch": 14.22,
166
+ "learning_rate": 0.00028646656134807797,
167
+ "loss": 0.065,
168
+ "step": 6000
169
+ },
170
+ {
171
+ "epoch": 14.22,
172
+ "eval_loss": 0.19133996963500977,
173
+ "eval_runtime": 815.1424,
174
+ "eval_samples_per_second": 6.345,
175
+ "eval_wer": 0.3376304160238475,
176
+ "step": 6000
177
+ },
178
+ {
179
+ "epoch": 15.4,
180
+ "learning_rate": 0.00027330173775671406,
181
+ "loss": 0.0634,
182
+ "step": 6500
183
+ },
184
+ {
185
+ "epoch": 15.4,
186
+ "eval_loss": 0.17903825640678406,
187
+ "eval_runtime": 788.5559,
188
+ "eval_samples_per_second": 6.559,
189
+ "eval_wer": 0.32520984232408545,
190
+ "step": 6500
191
+ },
192
+ {
193
+ "epoch": 16.59,
194
+ "learning_rate": 0.0002601369141653502,
195
+ "loss": 0.0574,
196
+ "step": 7000
197
+ },
198
+ {
199
+ "epoch": 16.59,
200
+ "eval_loss": 0.2020258903503418,
201
+ "eval_runtime": 1572.1771,
202
+ "eval_samples_per_second": 3.29,
203
+ "eval_wer": 0.33182543210522186,
204
+ "step": 7000
205
+ },
206
+ {
207
+ "epoch": 17.77,
208
+ "learning_rate": 0.00024697209057398633,
209
+ "loss": 0.0539,
210
+ "step": 7500
211
+ },
212
+ {
213
+ "epoch": 17.77,
214
+ "eval_loss": 0.18831460177898407,
215
+ "eval_runtime": 887.0107,
216
+ "eval_samples_per_second": 5.831,
217
+ "eval_wer": 0.3172083780038177,
218
+ "step": 7500
219
+ },
220
+ {
221
+ "epoch": 18.96,
222
+ "learning_rate": 0.00023380726698262242,
223
+ "loss": 0.0518,
224
+ "step": 8000
225
+ },
226
+ {
227
+ "epoch": 18.96,
228
+ "eval_loss": 0.19699327647686005,
229
+ "eval_runtime": 927.4568,
230
+ "eval_samples_per_second": 5.577,
231
+ "eval_wer": 0.31524723478806577,
232
+ "step": 8000
233
+ }
234
+ ],
235
+ "max_steps": 16880,
236
+ "num_train_epochs": 40,
237
+ "total_flos": 3.909573475423295e+19,
238
+ "trial_name": null,
239
+ "trial_params": null
240
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3ff2eca68c59215249e3d45e21b893cb00ca2fcf912465cd2d8b55458c36c22
3
+ size 2287
vocab.json ADDED
@@ -0,0 +1 @@
 
1
+ {"q": 0, "b": 1, "r": 2, "h": 4, "j": 5, "f": 6, "a": 7, "u": 8, "x": 9, "p": 10, "w": 11, "z": 12, "k": 13, "e": 14, "l": 15, "y": 16, "t": 17, "g": 18, "c": 19, "d": 20, "o": 21, "n": 22, "ñ": 23, "v": 24, "m": 25, "s": 26, "i": 27, "|": 3, "[UNK]": 28, "[PAD]": 29}