bofenghuang
commited on
Commit
•
9ae2cb9
1
Parent(s):
d2dc4e5
init
Browse files- README.md +166 -0
- added_tokens.json +4 -0
- alphabet.json +1 -0
- config.json +107 -0
- eval.py +182 -0
- language_model/5gram.bin +3 -0
- language_model/attrs.json +1 -0
- language_model/unigrams.txt +0 -0
- preprocessor_config.json +10 -0
- pytorch_model.bin +3 -0
- results_mozilla-foundatio_common_voice_9_0/log_mozilla-foundation_common_voice_9_0_fr_test_predictions.txt +0 -0
- results_mozilla-foundatio_common_voice_9_0/log_mozilla-foundation_common_voice_9_0_fr_test_targets.txt +0 -0
- results_mozilla-foundatio_common_voice_9_0/mozilla-foundation_common_voice_9_0_fr_test_eval_results.txt +2 -0
- results_mozilla-foundatio_common_voice_9_0_with_lm/log_mozilla-foundation_common_voice_9_0_fr_test_predictions.txt +0 -0
- results_mozilla-foundatio_common_voice_9_0_with_lm/log_mozilla-foundation_common_voice_9_0_fr_test_targets.txt +0 -0
- results_mozilla-foundatio_common_voice_9_0_with_lm/mozilla-foundation_common_voice_9_0_fr_test_eval_results.txt +2 -0
- results_polinaeterna_voxpopuli/log_polinaeterna_voxpopuli_fr_test_predictions.txt +0 -0
- results_polinaeterna_voxpopuli/log_polinaeterna_voxpopuli_fr_test_targets.txt +0 -0
- results_polinaeterna_voxpopuli/polinaeterna_voxpopuli_fr_test_eval_results.txt +2 -0
- results_polinaeterna_voxpopuli_with_lm/log_polinaeterna_voxpopuli_fr_test_predictions.txt +0 -0
- results_polinaeterna_voxpopuli_with_lm/log_polinaeterna_voxpopuli_fr_test_targets.txt +0 -0
- results_polinaeterna_voxpopuli_with_lm/polinaeterna_voxpopuli_fr_test_eval_results.txt +2 -0
- results_speech-recognition-community-v2_dev_data/log_speech-recognition-community-v2_dev_data_fr_validation_predictions.txt +0 -0
- results_speech-recognition-community-v2_dev_data/log_speech-recognition-community-v2_dev_data_fr_validation_targets.txt +0 -0
- results_speech-recognition-community-v2_dev_data/speech-recognition-community-v2_dev_data_fr_validation_eval_results.txt +2 -0
- results_speech-recognition-community-v2_dev_data_with_lm/log_speech-recognition-community-v2_dev_data_fr_validation_predictions.txt +0 -0
- results_speech-recognition-community-v2_dev_data_with_lm/log_speech-recognition-community-v2_dev_data_fr_validation_targets.txt +0 -0
- results_speech-recognition-community-v2_dev_data_with_lm/speech-recognition-community-v2_dev_data_fr_validation_eval_results.txt +2 -0
- special_tokens_map.json +36 -0
- tokenizer_config.json +13 -0
- vocab.json +46 -0
README.md
ADDED
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- fr
|
4 |
+
license: apache-2.0
|
5 |
+
tags:
|
6 |
+
- automatic-speech-recognition
|
7 |
+
- polinaeterna/voxpopuli
|
8 |
+
- generated_from_trainer
|
9 |
+
- hf-asr-leaderboard
|
10 |
+
- robust-speech-event
|
11 |
+
datasets:
|
12 |
+
- polinaeterna/voxpopuli
|
13 |
+
model-index:
|
14 |
+
- name: Fine-tuned Wav2Vec2 XLS-R 1B model for ASR in French
|
15 |
+
results:
|
16 |
+
- task:
|
17 |
+
name: Automatic Speech Recognition
|
18 |
+
type: automatic-speech-recognition
|
19 |
+
dataset:
|
20 |
+
name: Voxpopuli
|
21 |
+
type: polinaeterna/voxpopuli
|
22 |
+
args: fr
|
23 |
+
metrics:
|
24 |
+
- name: Test WER
|
25 |
+
type: wer
|
26 |
+
value: 11.70
|
27 |
+
- name: Test CER
|
28 |
+
type: cer
|
29 |
+
value: 5.80
|
30 |
+
- name: Test WER (+LM)
|
31 |
+
type: wer
|
32 |
+
value: 10.01
|
33 |
+
- name: Test CER (+LM)
|
34 |
+
type: cer
|
35 |
+
value: 5.63
|
36 |
+
- task:
|
37 |
+
name: Automatic Speech Recognition
|
38 |
+
type: automatic-speech-recognition
|
39 |
+
dataset:
|
40 |
+
name: Common Voice 9
|
41 |
+
type: mozilla-foundation/common_voice_9_0
|
42 |
+
args: fr
|
43 |
+
metrics:
|
44 |
+
- name: Test WER
|
45 |
+
type: wer
|
46 |
+
value: 45.74
|
47 |
+
- name: Test CER
|
48 |
+
type: cer
|
49 |
+
value: 22.99
|
50 |
+
- name: Test WER (+LM)
|
51 |
+
type: wer
|
52 |
+
value: 38.81
|
53 |
+
- name: Test CER (+LM)
|
54 |
+
type: cer
|
55 |
+
value: 23.25
|
56 |
+
- task:
|
57 |
+
name: Automatic Speech Recognition
|
58 |
+
type: automatic-speech-recognition
|
59 |
+
dataset:
|
60 |
+
name: Robust Speech Event - Dev Data
|
61 |
+
type: speech-recognition-community-v2/dev_data
|
62 |
+
args: fr
|
63 |
+
metrics:
|
64 |
+
- name: Test WER
|
65 |
+
type: wer
|
66 |
+
value: 27.86
|
67 |
+
- name: Test CER
|
68 |
+
type: cer
|
69 |
+
value: 13.20
|
70 |
+
- name: Test WER (+LM)
|
71 |
+
type: wer
|
72 |
+
value: 22.53
|
73 |
+
- name: Test CER (+LM)
|
74 |
+
type: cer
|
75 |
+
value: 12.82
|
76 |
+
---
|
77 |
+
|
78 |
+
|
79 |
+
# Fine-tuned Wav2Vec2 XLS-R 1B model for ASR in French
|
80 |
+
|
81 |
+
This model is a fine-tuned version of [facebook/wav2vec2-xls-r-1b](https://huggingface.co/facebook/wav2vec2-xls-r-1b) on the POLINAETERNA/VOXPOPULI - FR dataset.
|
82 |
+
It achieves the following results on the evaluation set:
|
83 |
+
- Loss: 0.2906
|
84 |
+
- Wer: 0.1093
|
85 |
+
|
86 |
+
## Training procedure
|
87 |
+
|
88 |
+
### Training hyperparameters
|
89 |
+
|
90 |
+
The following hyperparameters were used during training:
|
91 |
+
- learning_rate: 0.0001
|
92 |
+
- train_batch_size: 16
|
93 |
+
- eval_batch_size: 8
|
94 |
+
- seed: 42
|
95 |
+
- gradient_accumulation_steps: 8
|
96 |
+
- total_train_batch_size: 128
|
97 |
+
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
98 |
+
- lr_scheduler_type: linear
|
99 |
+
- lr_scheduler_warmup_ratio: 0.1
|
100 |
+
- num_epochs: 12.0
|
101 |
+
- mixed_precision_training: Native AMP
|
102 |
+
|
103 |
+
### Training results
|
104 |
+
|
105 |
+
| Training Loss | Epoch | Step | Validation Loss | Wer |
|
106 |
+
|:-------------:|:-----:|:----:|:---------------:|:------:|
|
107 |
+
| 0.4628 | 0.93 | 500 | 0.3834 | 0.1625 |
|
108 |
+
| 0.3577 | 1.85 | 1000 | 0.3231 | 0.1367 |
|
109 |
+
| 0.3103 | 2.78 | 1500 | 0.2918 | 0.1287 |
|
110 |
+
| 0.2884 | 3.7 | 2000 | 0.2845 | 0.1227 |
|
111 |
+
| 0.2615 | 4.63 | 2500 | 0.2819 | 0.1189 |
|
112 |
+
| 0.242 | 5.56 | 3000 | 0.2915 | 0.1165 |
|
113 |
+
| 0.2268 | 6.48 | 3500 | 0.2768 | 0.1187 |
|
114 |
+
| 0.2188 | 7.41 | 4000 | 0.2719 | 0.1128 |
|
115 |
+
| 0.1979 | 8.33 | 4500 | 0.2741 | 0.1134 |
|
116 |
+
| 0.1834 | 9.26 | 5000 | 0.2827 | 0.1096 |
|
117 |
+
| 0.1719 | 10.19 | 5500 | 0.2906 | 0.1093 |
|
118 |
+
| 0.1723 | 11.11 | 6000 | 0.2868 | 0.1104 |
|
119 |
+
|
120 |
+
### Framework versions
|
121 |
+
|
122 |
+
- Transformers 4.23.0.dev0
|
123 |
+
- Pytorch 1.12.0+cu113
|
124 |
+
- Datasets 2.4.0
|
125 |
+
- Tokenizers 0.12.1
|
126 |
+
|
127 |
+
|
128 |
+
## Evaluation
|
129 |
+
|
130 |
+
1. To evaluate on `mozilla-foundation/common_voice_9_0`
|
131 |
+
|
132 |
+
```bash
|
133 |
+
python eval.py \
|
134 |
+
--model_id "bhuang/wav2vec2-xls-r-1b-voxpopuli-fr" \
|
135 |
+
--dataset "polinaeterna/voxpopuli" \
|
136 |
+
--config "fr" \
|
137 |
+
--split "test" \
|
138 |
+
--log_outputs \
|
139 |
+
--outdir "outputs/results_polinaeterna_voxpopuli_with_lm"
|
140 |
+
```
|
141 |
+
|
142 |
+
2. To evaluate on `mozilla-foundation/common_voice_9_0`
|
143 |
+
|
144 |
+
```bash
|
145 |
+
python eval.py \
|
146 |
+
--model_id "bhuang/wav2vec2-xls-r-1b-voxpopuli-fr" \
|
147 |
+
--dataset "mozilla-foundation/common_voice_9_0" \
|
148 |
+
--config "fr" \
|
149 |
+
--split "test" \
|
150 |
+
--log_outputs \
|
151 |
+
--outdir "outputs/results_mozilla-foundatio_common_voice_9_0_with_lm"
|
152 |
+
```
|
153 |
+
|
154 |
+
3. To evaluate on `speech-recognition-community-v2/dev_data`
|
155 |
+
|
156 |
+
```bash
|
157 |
+
python eval.py \
|
158 |
+
--model_id "bhuang/wav2vec2-xls-r-1b-voxpopuli-fr" \
|
159 |
+
--dataset "speech-recognition-community-v2/dev_data" \
|
160 |
+
--config "fr" \
|
161 |
+
--split "validation" \
|
162 |
+
--chunk_length_s 5.0 \
|
163 |
+
--stride_length_s 1.0 \
|
164 |
+
--log_outputs \
|
165 |
+
--outdir "outputs/results_speech-recognition-community-v2_dev_data_with_lm"
|
166 |
+
```
|
added_tokens.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"</s>": 45,
|
3 |
+
"<s>": 44
|
4 |
+
}
|
alphabet.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"labels": [" ", "'", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\u00e0", "\u00e2", "\u00e7", "\u00e8", "\u00e9", "\u00ea", "\u00eb", "\u00ee", "\u00ef", "\u00f4", "\u00f9", "\u00fb", "\u00fc", "\u0153", "\u2047", "", "<s>", "</s>"], "is_bpe": false}
|
config.json
ADDED
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "facebook/wav2vec2-xls-r-1b",
|
3 |
+
"activation_dropout": 0.1,
|
4 |
+
"adapter_kernel_size": 3,
|
5 |
+
"adapter_stride": 2,
|
6 |
+
"add_adapter": false,
|
7 |
+
"apply_spec_augment": true,
|
8 |
+
"architectures": [
|
9 |
+
"Wav2Vec2ForCTC"
|
10 |
+
],
|
11 |
+
"attention_dropout": 0.0,
|
12 |
+
"bos_token_id": 1,
|
13 |
+
"classifier_proj_size": 256,
|
14 |
+
"codevector_dim": 1024,
|
15 |
+
"contrastive_logits_temperature": 0.1,
|
16 |
+
"conv_bias": true,
|
17 |
+
"conv_dim": [
|
18 |
+
512,
|
19 |
+
512,
|
20 |
+
512,
|
21 |
+
512,
|
22 |
+
512,
|
23 |
+
512,
|
24 |
+
512
|
25 |
+
],
|
26 |
+
"conv_kernel": [
|
27 |
+
10,
|
28 |
+
3,
|
29 |
+
3,
|
30 |
+
3,
|
31 |
+
3,
|
32 |
+
2,
|
33 |
+
2
|
34 |
+
],
|
35 |
+
"conv_stride": [
|
36 |
+
5,
|
37 |
+
2,
|
38 |
+
2,
|
39 |
+
2,
|
40 |
+
2,
|
41 |
+
2,
|
42 |
+
2
|
43 |
+
],
|
44 |
+
"ctc_loss_reduction": "mean",
|
45 |
+
"ctc_zero_infinity": true,
|
46 |
+
"diversity_loss_weight": 0.1,
|
47 |
+
"do_stable_layer_norm": true,
|
48 |
+
"eos_token_id": 2,
|
49 |
+
"feat_extract_activation": "gelu",
|
50 |
+
"feat_extract_dropout": 0.0,
|
51 |
+
"feat_extract_norm": "layer",
|
52 |
+
"feat_proj_dropout": 0.0,
|
53 |
+
"feat_quantizer_dropout": 0.0,
|
54 |
+
"final_dropout": 0.0,
|
55 |
+
"hidden_act": "gelu",
|
56 |
+
"hidden_dropout": 0.0,
|
57 |
+
"hidden_size": 1280,
|
58 |
+
"initializer_range": 0.02,
|
59 |
+
"intermediate_size": 5120,
|
60 |
+
"layer_norm_eps": 1e-05,
|
61 |
+
"layerdrop": 0.1,
|
62 |
+
"mask_feature_length": 10,
|
63 |
+
"mask_feature_min_masks": 0,
|
64 |
+
"mask_feature_prob": 0.0,
|
65 |
+
"mask_time_length": 10,
|
66 |
+
"mask_time_min_masks": 2,
|
67 |
+
"mask_time_prob": 0.05,
|
68 |
+
"model_type": "wav2vec2",
|
69 |
+
"num_adapter_layers": 3,
|
70 |
+
"num_attention_heads": 16,
|
71 |
+
"num_codevector_groups": 2,
|
72 |
+
"num_codevectors_per_group": 320,
|
73 |
+
"num_conv_pos_embedding_groups": 16,
|
74 |
+
"num_conv_pos_embeddings": 128,
|
75 |
+
"num_feat_extract_layers": 7,
|
76 |
+
"num_hidden_layers": 48,
|
77 |
+
"num_negatives": 100,
|
78 |
+
"output_hidden_size": 1280,
|
79 |
+
"pad_token_id": 43,
|
80 |
+
"proj_codevector_dim": 1024,
|
81 |
+
"tdnn_dilation": [
|
82 |
+
1,
|
83 |
+
2,
|
84 |
+
3,
|
85 |
+
1,
|
86 |
+
1
|
87 |
+
],
|
88 |
+
"tdnn_dim": [
|
89 |
+
512,
|
90 |
+
512,
|
91 |
+
512,
|
92 |
+
512,
|
93 |
+
1500
|
94 |
+
],
|
95 |
+
"tdnn_kernel": [
|
96 |
+
5,
|
97 |
+
3,
|
98 |
+
3,
|
99 |
+
1,
|
100 |
+
1
|
101 |
+
],
|
102 |
+
"torch_dtype": "float32",
|
103 |
+
"transformers_version": "4.23.0.dev0",
|
104 |
+
"use_weighted_layer_sum": false,
|
105 |
+
"vocab_size": 46,
|
106 |
+
"xvector_output_dim": 512
|
107 |
+
}
|
eval.py
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import argparse
|
4 |
+
import re
|
5 |
+
from typing import Dict
|
6 |
+
|
7 |
+
import torch
|
8 |
+
from datasets import Audio, Dataset, load_dataset, load_metric
|
9 |
+
|
10 |
+
from transformers import (
|
11 |
+
AutoConfig,
|
12 |
+
AutoFeatureExtractor,
|
13 |
+
AutoModelForCTC,
|
14 |
+
AutoTokenizer,
|
15 |
+
Wav2Vec2Processor,
|
16 |
+
Wav2Vec2ProcessorWithLM,
|
17 |
+
pipeline,
|
18 |
+
)
|
19 |
+
|
20 |
+
|
21 |
+
def log_results(result: Dataset, args: Dict[str, str]):
|
22 |
+
""" DO NOT CHANGE. This function computes and logs the result metrics. """
|
23 |
+
|
24 |
+
log_outputs = args.log_outputs
|
25 |
+
dataset_id = "_".join(args.dataset.split("/") + [args.config, args.split])
|
26 |
+
|
27 |
+
# load metric
|
28 |
+
wer = load_metric("wer")
|
29 |
+
cer = load_metric("cer")
|
30 |
+
|
31 |
+
# compute metrics
|
32 |
+
wer_result = wer.compute(references=result["target"], predictions=result["prediction"])
|
33 |
+
cer_result = cer.compute(references=result["target"], predictions=result["prediction"])
|
34 |
+
|
35 |
+
# print & log results
|
36 |
+
result_str = f"WER: {wer_result}\n" f"CER: {cer_result}"
|
37 |
+
print(result_str)
|
38 |
+
|
39 |
+
with open(f"{dataset_id}_eval_results.txt", "w") as f:
|
40 |
+
f.write(result_str)
|
41 |
+
|
42 |
+
# log all results in text file. Possibly interesting for analysis
|
43 |
+
if log_outputs is not None:
|
44 |
+
pred_file = f"log_{dataset_id}_predictions.txt"
|
45 |
+
target_file = f"log_{dataset_id}_targets.txt"
|
46 |
+
|
47 |
+
with open(pred_file, "w") as p, open(target_file, "w") as t:
|
48 |
+
|
49 |
+
# mapping function to write output
|
50 |
+
def write_to_file(batch, i):
|
51 |
+
p.write(f"{i}" + "\n")
|
52 |
+
p.write(batch["prediction"] + "\n")
|
53 |
+
t.write(f"{i}" + "\n")
|
54 |
+
t.write(batch["target"] + "\n")
|
55 |
+
|
56 |
+
result.map(write_to_file, with_indices=True)
|
57 |
+
|
58 |
+
|
59 |
+
def normalize_text(text: str, invalid_chars_regex: str) -> str:
|
60 |
+
""" DO ADAPT FOR YOUR USE CASE. this function normalizes the target text. """
|
61 |
+
|
62 |
+
text = text.lower()
|
63 |
+
text = re.sub(r"’", "'", text)
|
64 |
+
text = re.sub(invalid_chars_regex, " ", text)
|
65 |
+
text = re.sub(r"\s+", " ", text).strip()
|
66 |
+
|
67 |
+
return text
|
68 |
+
|
69 |
+
|
70 |
+
def main(args):
|
71 |
+
# load dataset
|
72 |
+
dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
|
73 |
+
|
74 |
+
# for testing: only process the first two examples as a test
|
75 |
+
# dataset = dataset.select(range(10))
|
76 |
+
|
77 |
+
# load processor
|
78 |
+
if args.greedy:
|
79 |
+
processor = Wav2Vec2Processor.from_pretrained(args.model_id)
|
80 |
+
decoder = None
|
81 |
+
else:
|
82 |
+
processor = Wav2Vec2ProcessorWithLM.from_pretrained(args.model_id)
|
83 |
+
decoder = processor.decoder
|
84 |
+
|
85 |
+
feature_extractor = processor.feature_extractor
|
86 |
+
tokenizer = processor.tokenizer
|
87 |
+
sampling_rate = feature_extractor.sampling_rate
|
88 |
+
|
89 |
+
# resample audio
|
90 |
+
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
|
91 |
+
|
92 |
+
# load eval pipeline
|
93 |
+
if args.device is None:
|
94 |
+
args.device = 0 if torch.cuda.is_available() else -1
|
95 |
+
|
96 |
+
config = AutoConfig.from_pretrained(args.model_id)
|
97 |
+
model = AutoModelForCTC.from_pretrained(args.model_id)
|
98 |
+
|
99 |
+
# asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
|
100 |
+
asr = pipeline(
|
101 |
+
"automatic-speech-recognition",
|
102 |
+
config=config,
|
103 |
+
model=model,
|
104 |
+
tokenizer=tokenizer,
|
105 |
+
feature_extractor=feature_extractor,
|
106 |
+
decoder=decoder,
|
107 |
+
device=args.device,
|
108 |
+
)
|
109 |
+
|
110 |
+
# build normalizer config
|
111 |
+
tokenizer = AutoTokenizer.from_pretrained(args.model_id)
|
112 |
+
tokens = [x for x in tokenizer.convert_ids_to_tokens(range(0, tokenizer.vocab_size))]
|
113 |
+
special_tokens = [
|
114 |
+
tokenizer.pad_token,
|
115 |
+
tokenizer.word_delimiter_token,
|
116 |
+
tokenizer.unk_token,
|
117 |
+
tokenizer.bos_token,
|
118 |
+
tokenizer.eos_token,
|
119 |
+
]
|
120 |
+
non_special_tokens = [x for x in tokens if x not in special_tokens]
|
121 |
+
invalid_chars_regex = f"[^\s{re.escape(''.join(set(non_special_tokens)))}]"
|
122 |
+
|
123 |
+
# normalize_to_lower = False
|
124 |
+
# for token in non_special_tokens:
|
125 |
+
# if token.isalpha() and token.islower():
|
126 |
+
# normalize_to_lower = True
|
127 |
+
# break
|
128 |
+
|
129 |
+
# map function to decode audio
|
130 |
+
def map_to_pred(batch):
|
131 |
+
prediction = asr(batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s)
|
132 |
+
|
133 |
+
batch["prediction"] = prediction["text"]
|
134 |
+
batch["target"] = normalize_text(batch["sentence"], invalid_chars_regex)
|
135 |
+
return batch
|
136 |
+
|
137 |
+
# run inference on all examples
|
138 |
+
result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
|
139 |
+
|
140 |
+
# filtering out empty targets
|
141 |
+
result = result.filter(lambda example: example["target"] != "")
|
142 |
+
|
143 |
+
# compute and log_results
|
144 |
+
# do not change function below
|
145 |
+
log_results(result, args)
|
146 |
+
|
147 |
+
|
148 |
+
if __name__ == "__main__":
|
149 |
+
parser = argparse.ArgumentParser()
|
150 |
+
|
151 |
+
parser.add_argument("--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers")
|
152 |
+
parser.add_argument(
|
153 |
+
"--dataset",
|
154 |
+
type=str,
|
155 |
+
required=True,
|
156 |
+
help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
|
157 |
+
)
|
158 |
+
parser.add_argument("--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice")
|
159 |
+
parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
|
160 |
+
parser.add_argument(
|
161 |
+
"--chunk_length_s",
|
162 |
+
type=float,
|
163 |
+
default=None,
|
164 |
+
help="Chunk length in seconds. Defaults to None. For long audio files a good value would be 5.0 seconds.",
|
165 |
+
)
|
166 |
+
parser.add_argument(
|
167 |
+
"--stride_length_s",
|
168 |
+
type=float,
|
169 |
+
default=None,
|
170 |
+
help="Stride of the audio chunks. Defaults to None. For long audio files a good value would be 1.0 seconds.",
|
171 |
+
)
|
172 |
+
parser.add_argument("--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis.")
|
173 |
+
parser.add_argument("--greedy", action="store_true", help="If defined, the LM will be ignored during inference.")
|
174 |
+
parser.add_argument(
|
175 |
+
"--device",
|
176 |
+
type=int,
|
177 |
+
default=None,
|
178 |
+
help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
|
179 |
+
)
|
180 |
+
args = parser.parse_args()
|
181 |
+
|
182 |
+
main(args)
|
language_model/5gram.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9e840f5bdc9863f9a9dc589c4fbdbc4d0ceba5ec9308b51f5de8df801afdb430
|
3 |
+
size 110696534
|
language_model/attrs.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"alpha": 0.5, "beta": 1.5, "unk_score_offset": -10.0, "score_boundary": true}
|
language_model/unigrams.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
preprocessor_config.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
4 |
+
"feature_size": 1,
|
5 |
+
"padding_side": "right",
|
6 |
+
"padding_value": 0,
|
7 |
+
"processor_class": "Wav2Vec2ProcessorWithLM",
|
8 |
+
"return_attention_mask": true,
|
9 |
+
"sampling_rate": 16000
|
10 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b5c1a54580151b88335c8297a0dcc3c403aed8a91340048de1187c2fa8282464
|
3 |
+
size 3850500657
|
results_mozilla-foundatio_common_voice_9_0/log_mozilla-foundation_common_voice_9_0_fr_test_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_mozilla-foundatio_common_voice_9_0/log_mozilla-foundation_common_voice_9_0_fr_test_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_mozilla-foundatio_common_voice_9_0/mozilla-foundation_common_voice_9_0_fr_test_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.4574742025825611
|
2 |
+
CER: 0.2299324803692149
|
results_mozilla-foundatio_common_voice_9_0_with_lm/log_mozilla-foundation_common_voice_9_0_fr_test_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_mozilla-foundatio_common_voice_9_0_with_lm/log_mozilla-foundation_common_voice_9_0_fr_test_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_mozilla-foundatio_common_voice_9_0_with_lm/mozilla-foundation_common_voice_9_0_fr_test_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.38810468081373856
|
2 |
+
CER: 0.2325219729607091
|
results_polinaeterna_voxpopuli/log_polinaeterna_voxpopuli_fr_test_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_polinaeterna_voxpopuli/log_polinaeterna_voxpopuli_fr_test_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_polinaeterna_voxpopuli/polinaeterna_voxpopuli_fr_test_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.11708419585146382
|
2 |
+
CER: 0.05802534895790652
|
results_polinaeterna_voxpopuli_with_lm/log_polinaeterna_voxpopuli_fr_test_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_polinaeterna_voxpopuli_with_lm/log_polinaeterna_voxpopuli_fr_test_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_polinaeterna_voxpopuli_with_lm/polinaeterna_voxpopuli_fr_test_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.10014363567234168
|
2 |
+
CER: 0.056365920948400663
|
results_speech-recognition-community-v2_dev_data/log_speech-recognition-community-v2_dev_data_fr_validation_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_speech-recognition-community-v2_dev_data/log_speech-recognition-community-v2_dev_data_fr_validation_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_speech-recognition-community-v2_dev_data/speech-recognition-community-v2_dev_data_fr_validation_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.27865348650814853
|
2 |
+
CER: 0.13207079892578805
|
results_speech-recognition-community-v2_dev_data_with_lm/log_speech-recognition-community-v2_dev_data_fr_validation_predictions.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_speech-recognition-community-v2_dev_data_with_lm/log_speech-recognition-community-v2_dev_data_fr_validation_targets.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
results_speech-recognition-community-v2_dev_data_with_lm/speech-recognition-community-v2_dev_data_fr_validation_eval_results.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
WER: 0.22535399412236173
|
2 |
+
CER: 0.1283249878106353
|
special_tokens_map.json
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"additional_special_tokens": [
|
3 |
+
{
|
4 |
+
"content": "<s>",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": true,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false
|
9 |
+
},
|
10 |
+
{
|
11 |
+
"content": "</s>",
|
12 |
+
"lstrip": false,
|
13 |
+
"normalized": true,
|
14 |
+
"rstrip": false,
|
15 |
+
"single_word": false
|
16 |
+
},
|
17 |
+
{
|
18 |
+
"content": "<s>",
|
19 |
+
"lstrip": false,
|
20 |
+
"normalized": true,
|
21 |
+
"rstrip": false,
|
22 |
+
"single_word": false
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"content": "</s>",
|
26 |
+
"lstrip": false,
|
27 |
+
"normalized": true,
|
28 |
+
"rstrip": false,
|
29 |
+
"single_word": false
|
30 |
+
}
|
31 |
+
],
|
32 |
+
"bos_token": "<s>",
|
33 |
+
"eos_token": "</s>",
|
34 |
+
"pad_token": "[PAD]",
|
35 |
+
"unk_token": "[UNK]"
|
36 |
+
}
|
tokenizer_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<s>",
|
3 |
+
"do_lower_case": false,
|
4 |
+
"eos_token": "</s>",
|
5 |
+
"name_or_path": "outputs/voxpopuli/wav2vec2-xls-r-1b-ft",
|
6 |
+
"pad_token": "[PAD]",
|
7 |
+
"processor_class": "Wav2Vec2ProcessorWithLM",
|
8 |
+
"replace_word_delimiter_char": " ",
|
9 |
+
"special_tokens_map_file": null,
|
10 |
+
"tokenizer_class": "Wav2Vec2CTCTokenizer",
|
11 |
+
"unk_token": "[UNK]",
|
12 |
+
"word_delimiter_token": "|"
|
13 |
+
}
|
vocab.json
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"'": 1,
|
3 |
+
"[PAD]": 43,
|
4 |
+
"[UNK]": 42,
|
5 |
+
"a": 2,
|
6 |
+
"b": 3,
|
7 |
+
"c": 4,
|
8 |
+
"d": 5,
|
9 |
+
"e": 6,
|
10 |
+
"f": 7,
|
11 |
+
"g": 8,
|
12 |
+
"h": 9,
|
13 |
+
"i": 10,
|
14 |
+
"j": 11,
|
15 |
+
"k": 12,
|
16 |
+
"l": 13,
|
17 |
+
"m": 14,
|
18 |
+
"n": 15,
|
19 |
+
"o": 16,
|
20 |
+
"p": 17,
|
21 |
+
"q": 18,
|
22 |
+
"r": 19,
|
23 |
+
"s": 20,
|
24 |
+
"t": 21,
|
25 |
+
"u": 22,
|
26 |
+
"v": 23,
|
27 |
+
"w": 24,
|
28 |
+
"x": 25,
|
29 |
+
"y": 26,
|
30 |
+
"z": 27,
|
31 |
+
"|": 0,
|
32 |
+
"à": 28,
|
33 |
+
"â": 29,
|
34 |
+
"ç": 30,
|
35 |
+
"è": 31,
|
36 |
+
"é": 32,
|
37 |
+
"ê": 33,
|
38 |
+
"ë": 34,
|
39 |
+
"î": 35,
|
40 |
+
"ï": 36,
|
41 |
+
"ô": 37,
|
42 |
+
"ù": 38,
|
43 |
+
"û": 39,
|
44 |
+
"ü": 40,
|
45 |
+
"œ": 41
|
46 |
+
}
|