irebai
commited on
Commit
•
a9bcfca
1
Parent(s):
dd03b28
first commit
Browse files- README.md +123 -0
- config.json +76 -0
- preprocessor_config.json +8 -0
- pytorch_model.bin +3 -0
- refs.txt +0 -0
- special_tokens_map.json +1 -0
- trs.txt +0 -0
- vocab.json +1 -0
README.md
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: fr
|
3 |
+
datasets:
|
4 |
+
- common_voice
|
5 |
+
tags:
|
6 |
+
- audio
|
7 |
+
- automatic-speech-recognition
|
8 |
+
- speech
|
9 |
+
- xlsr-fine-tuning
|
10 |
+
license: apache-2.0
|
11 |
+
model-index:
|
12 |
+
- name: wav2vec2-large-xlsr-53-French_punctuation by Ilyes Rebai
|
13 |
+
results:
|
14 |
+
- task:
|
15 |
+
name: Speech Recognition
|
16 |
+
type: automatic-speech-recognition
|
17 |
+
dataset:
|
18 |
+
name: Common Voice
|
19 |
+
args: fr
|
20 |
+
metrics:
|
21 |
+
- name: Test WER and CER on text and puctuation prediction
|
22 |
+
types: [wer, cer]
|
23 |
+
values: [19.47%, 6.66%]
|
24 |
+
-name: Test WER and CER on text without punctuation
|
25 |
+
types: [wer, cer]
|
26 |
+
values: [17.88%, 6.37%]
|
27 |
+
|
28 |
+
---
|
29 |
+
## Evaluation on Common Voice FR Test
|
30 |
+
```python
|
31 |
+
import re
|
32 |
+
import torch
|
33 |
+
import torchaudio
|
34 |
+
from datasets import load_dataset, load_metric
|
35 |
+
from transformers import (
|
36 |
+
Wav2Vec2ForCTC,
|
37 |
+
Wav2Vec2Processor,
|
38 |
+
)
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
model_name = "Ilyes/wav2vec2-large-xlsr-53-french_punctuation"
|
43 |
+
|
44 |
+
|
45 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_name).to('cuda')
|
46 |
+
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
47 |
+
|
48 |
+
|
49 |
+
ds = load_dataset("common_voice", "fr", split="test")
|
50 |
+
|
51 |
+
|
52 |
+
chars_to_ignore_regex = '[\;\:\"\“\%\‘\”\�\‘\’\’\’\‘\…\·\ǃ\«\‹\»\›“\”\\ʿ\ʾ\„\∞\\|\;\:\*\—\–\─\―\_\/\:\ː\;\=\«\»\→]'
|
53 |
+
def normalize_text(text):
|
54 |
+
text = text.lower().strip()
|
55 |
+
text = re.sub('œ', 'oe', text)
|
56 |
+
text = re.sub('æ', 'ae', text)
|
57 |
+
text = re.sub("’|´|′|ʼ|‘|ʻ|`", "'", text)
|
58 |
+
text = re.sub("'+ ", " ", text)
|
59 |
+
text = re.sub(" '+", " ", text)
|
60 |
+
text = re.sub("'$", " ", text)
|
61 |
+
text = re.sub("' ", " ", text)
|
62 |
+
text = re.sub("−|‐", "-", text)
|
63 |
+
text = re.sub(" -", "", text)
|
64 |
+
text = re.sub("- ", "", text)
|
65 |
+
text = re.sub(chars_to_ignore_regex, '', text)
|
66 |
+
return text
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
def map_to_array(batch):
|
71 |
+
speech, _ = torchaudio.load(batch["path"])
|
72 |
+
batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
|
73 |
+
batch["sampling_rate"] = resampler.new_freq
|
74 |
+
batch["sentence"] = normalize_text(batch["sentence"])
|
75 |
+
return batch
|
76 |
+
|
77 |
+
ds = ds.map(map_to_array)
|
78 |
+
|
79 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
80 |
+
def map_to_pred(batch):
|
81 |
+
features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
|
82 |
+
input_values = features.input_values.to(device)
|
83 |
+
attention_mask = features.attention_mask.to(device)
|
84 |
+
with torch.no_grad():
|
85 |
+
logits = model(input_values, attention_mask=attention_mask).logits
|
86 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
87 |
+
batch["predicted"] = processor.batch_decode(pred_ids)
|
88 |
+
batch["target"] = batch["sentence"]
|
89 |
+
# remove duplicates
|
90 |
+
batch["target"] = re.sub('\.+', '.', batch["target"])
|
91 |
+
batch["target"] = re.sub('\?+', '?', batch["target"])
|
92 |
+
batch["target"] = re.sub('!+', '!', batch["target"])
|
93 |
+
batch["target"] = re.sub(',+', ',', batch["target"])
|
94 |
+
return batch
|
95 |
+
|
96 |
+
result = ds.map(map_to_pred, batched=True, batch_size=16, remove_columns=list(ds.features.keys()))
|
97 |
+
wer = load_metric("wer")
|
98 |
+
print(wer.compute(predictions=result["predicted"], references=result["target"]))
|
99 |
+
```
|
100 |
+
## Some results
|
101 |
+
|
102 |
+
| Reference | Prediction |
|
103 |
+
| ------------- | ------------- |
|
104 |
+
| il vécut à new york et y enseigna une grande partie de sa vie. | il a vécu à new york et y enseigna une grande partie de sa vie. |
|
105 |
+
| au classement par nations, l'allemagne est la tenante du titre. | au classement der nation l'allemagne est la tenante du titre.. |
|
106 |
+
| voici un petit calcul pour fixer les idées. | voici un petit calcul pour fixer les idées. |
|
107 |
+
| oh! tu dois être beau avec | oh! tu dois être beau avec. |
|
108 |
+
| babochet vous le voulez? | baboche, vous le voulez? |
|
109 |
+
| la commission est, par conséquent, défavorable à cet amendement. | la commission est, par conséquent, défavorable à cet amendement. |
|
110 |
+
|
111 |
+
All the references and predictions of the test corpus are already available in this repository.
|
112 |
+
|
113 |
+
## Results
|
114 |
+
|
115 |
+
text + punctuation
|
116 |
+
|
117 |
+
WER=21.47% CER=7.21%
|
118 |
+
|
119 |
+
|
120 |
+
text (without punctuation)
|
121 |
+
|
122 |
+
WER=19.71% CER=6.91%
|
123 |
+
|
config.json
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/workspace/output_models/fr/wav2vec2-large-xlsr-53/checkpoint-14700",
|
3 |
+
"activation_dropout": 0.055,
|
4 |
+
"apply_spec_augment": true,
|
5 |
+
"architectures": [
|
6 |
+
"Wav2Vec2ForCTC"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.094,
|
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.04,
|
46 |
+
"final_dropout": 0.0,
|
47 |
+
"gradient_checkpointing": true,
|
48 |
+
"hidden_act": "gelu",
|
49 |
+
"hidden_dropout": 0.047,
|
50 |
+
"hidden_size": 1024,
|
51 |
+
"initializer_range": 0.02,
|
52 |
+
"intermediate_size": 4096,
|
53 |
+
"layer_norm_eps": 1e-05,
|
54 |
+
"layerdrop": 0.041,
|
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.4,
|
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": 48,
|
74 |
+
"transformers_version": "4.5.0.dev0",
|
75 |
+
"vocab_size": 49
|
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:9f0c763c2c455ca6fa21a4644e7e37991dee8d5e436d5dcb73e21d9acd932275
|
3 |
+
size 1262134743
|
refs.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
special_tokens_map.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "pad_token": "<pad>"}
|
trs.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"a": 0, "e": 1, "i": 2, "o": 3, "u": 4, "y": 5, "b": 6, "c": 7, "d": 8, "f": 9, "g": 10, "h": 11, "j": 12, "k": 13, "l": 14, "m": 15, "n": 16, "p": 17, "q": 18, "r": 19, "s": 20, "t": 21, "v": 22, "w": 23, "x": 24, "z": 25, "à": 26, "â": 27, "ç": 28, "è": 29, "é": 30, "ê": 31, "ë": 32, "î": 33, "ï": 34, "ô": 35, "ù": 36, "û": 37, "ü": 38, "ÿ": 39, "|": 40, "'": 41, "-": 42, ".": 43, ",": 44, "!": 45, "?": 46, "<unk>": 47, "<pad>": 48}
|