First version
Browse files- README.md +99 -0
- config.json +76 -0
- optimizer.pt +3 -0
- preprocessor_config.json +8 -0
- pytorch_model.bin +3 -0
- scheduler.pt +3 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- trainer_state.json +100 -0
- training_args.bin +3 -0
- vocab.json +1 -0
README.md
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: sl
|
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 Slovene
|
13 |
+
results:
|
14 |
+
- task:
|
15 |
+
name: Speech Recognition
|
16 |
+
type: automatic-speech-recognition
|
17 |
+
dataset:
|
18 |
+
name: Common Voice sl
|
19 |
+
type: common_voice
|
20 |
+
args: sl
|
21 |
+
metrics:
|
22 |
+
- name: Test WER
|
23 |
+
type: wer
|
24 |
+
value: 36.97
|
25 |
+
---
|
26 |
+
# Wav2Vec2-Large-XLSR-53-Slovene
|
27 |
+
Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) in Slovene using the [Common Voice](https://huggingface.co/datasets/common_voice)
|
28 |
+
When using this model, make sure that your speech input is sampled at 16kHz.
|
29 |
+
|
30 |
+
## Usage
|
31 |
+
The model can be used directly (without a language model) as follows:
|
32 |
+
|
33 |
+
```python
|
34 |
+
import torch
|
35 |
+
import torchaudio
|
36 |
+
from datasets import load_dataset
|
37 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
38 |
+
test_dataset = load_dataset("common_voice", "sl", split="test[:2%]").
|
39 |
+
processor = Wav2Vec2Processor.from_pretrained("mrshu/wav2vec2-large-xlsr-slovene")
|
40 |
+
model = Wav2Vec2ForCTC.from_pretrained("mrshu/wav2vec2-large-xlsr-slovene")
|
41 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
42 |
+
# Preprocessing the datasets.
|
43 |
+
# We need to read the aduio files as arrays
|
44 |
+
def speech_file_to_array_fn(batch):
|
45 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
46 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
47 |
+
return batch
|
48 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
49 |
+
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
50 |
+
with torch.no_grad():
|
51 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
52 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
53 |
+
print("Prediction:", processor.batch_decode(predicted_ids))
|
54 |
+
print("Reference:", test_dataset["sentence"][:2])
|
55 |
+
```
|
56 |
+
|
57 |
+
|
58 |
+
## Evaluation
|
59 |
+
The model can be evaluated as follows on the Slovene test data of Common Voice.
|
60 |
+
```python
|
61 |
+
import torch
|
62 |
+
import torchaudio
|
63 |
+
from datasets import load_dataset, load_metric
|
64 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
65 |
+
import re
|
66 |
+
test_dataset = load_dataset("common_voice", "sl", split="test")
|
67 |
+
wer = load_metric("wer")
|
68 |
+
processor = Wav2Vec2Processor.from_pretrained("mrshu/wav2vec2-large-xlsr-slovene")
|
69 |
+
model = Wav2Vec2ForCTC.from_pretrained("mrshu/wav2vec2-large-xlsr-slovene")
|
70 |
+
model.to("cuda")
|
71 |
+
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\«\»\)\(\„\'\–\’\—]'
|
72 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
73 |
+
# Preprocessing the datasets.
|
74 |
+
# We need to read the aduio files as arrays
|
75 |
+
def speech_file_to_array_fn(batch):
|
76 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
77 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
78 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
79 |
+
return batch
|
80 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
81 |
+
# Preprocessing the datasets.
|
82 |
+
# We need to read the aduio files as arrays
|
83 |
+
def evaluate(batch):
|
84 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
85 |
+
with torch.no_grad():
|
86 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
87 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
88 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
89 |
+
return batch
|
90 |
+
result = test_dataset.map(evaluate, batched=True, batch_size=8)
|
91 |
+
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
92 |
+
```
|
93 |
+
|
94 |
+
**Test Result**: 36.97 %
|
95 |
+
|
96 |
+
## Training
|
97 |
+
The Common Voice `train`, `validation` datasets were used for training.
|
98 |
+
The script used for training can be found [here](https://colab.research.google.com/drive/14uahdilysnFsiYniHxY9fyKjFGuYQe7p)
|
99 |
+
|
config.json
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/content/drive/MyDrive/wav2vec2-large-xlsr-slovene-demo/checkpoint-2400",
|
3 |
+
"activation_dropout": 0.0,
|
4 |
+
"apply_spec_augment": true,
|
5 |
+
"architectures": [
|
6 |
+
"Wav2Vec2ForCTC"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.1,
|
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.0,
|
46 |
+
"final_dropout": 0.0,
|
47 |
+
"gradient_checkpointing": true,
|
48 |
+
"hidden_act": "gelu",
|
49 |
+
"hidden_dropout": 0.1,
|
50 |
+
"hidden_size": 1024,
|
51 |
+
"initializer_range": 0.02,
|
52 |
+
"intermediate_size": 4096,
|
53 |
+
"layer_norm_eps": 1e-05,
|
54 |
+
"layerdrop": 0.1,
|
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.05,
|
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.0",
|
75 |
+
"vocab_size": 31
|
76 |
+
}
|
optimizer.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d6412a776d986b7778ed3bc3e5aeebce7da3725634501e8152750a644f8856c5
|
3 |
+
size 2524030271
|
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:1f5876d15d270501f95c5b012a92adcc065d2e36cdcd9203dcdc815d3e22a4b6
|
3 |
+
size 1262060951
|
scheduler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d925a061b55ae2fd0dc674f239e8a7c89ec7351e753745cdfa70b1eb43df83e5
|
3 |
+
size 623
|
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,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"best_metric": null,
|
3 |
+
"best_model_checkpoint": null,
|
4 |
+
"epoch": 29.625766871165645,
|
5 |
+
"global_step": 2400,
|
6 |
+
"is_hyper_param_search": false,
|
7 |
+
"is_local_process_zero": true,
|
8 |
+
"is_world_process_zero": true,
|
9 |
+
"log_history": [
|
10 |
+
{
|
11 |
+
"epoch": 4.93,
|
12 |
+
"learning_rate": 6.400000000000001e-05,
|
13 |
+
"loss": 0.0363,
|
14 |
+
"step": 400
|
15 |
+
},
|
16 |
+
{
|
17 |
+
"epoch": 4.93,
|
18 |
+
"eval_loss": 0.6197775602340698,
|
19 |
+
"eval_runtime": 84.7989,
|
20 |
+
"eval_samples_per_second": 10.389,
|
21 |
+
"eval_wer": 0.5268051434223541,
|
22 |
+
"step": 400
|
23 |
+
},
|
24 |
+
{
|
25 |
+
"epoch": 9.87,
|
26 |
+
"learning_rate": 6.756476683937824e-05,
|
27 |
+
"loss": 0.0221,
|
28 |
+
"step": 800
|
29 |
+
},
|
30 |
+
{
|
31 |
+
"epoch": 9.87,
|
32 |
+
"eval_loss": 0.7040311694145203,
|
33 |
+
"eval_runtime": 86.0378,
|
34 |
+
"eval_samples_per_second": 10.24,
|
35 |
+
"eval_wer": 0.5272007912957468,
|
36 |
+
"step": 800
|
37 |
+
},
|
38 |
+
{
|
39 |
+
"epoch": 14.81,
|
40 |
+
"learning_rate": 5.098445595854923e-05,
|
41 |
+
"loss": 0.0174,
|
42 |
+
"step": 1200
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"epoch": 14.81,
|
46 |
+
"eval_loss": 0.7597708702087402,
|
47 |
+
"eval_runtime": 85.9482,
|
48 |
+
"eval_samples_per_second": 10.25,
|
49 |
+
"eval_wer": 0.5339268051434224,
|
50 |
+
"step": 1200
|
51 |
+
},
|
52 |
+
{
|
53 |
+
"epoch": 19.75,
|
54 |
+
"learning_rate": 3.440414507772021e-05,
|
55 |
+
"loss": 0.0126,
|
56 |
+
"step": 1600
|
57 |
+
},
|
58 |
+
{
|
59 |
+
"epoch": 19.75,
|
60 |
+
"eval_loss": 0.7824531197547913,
|
61 |
+
"eval_runtime": 85.9896,
|
62 |
+
"eval_samples_per_second": 10.245,
|
63 |
+
"eval_wer": 0.5224530168150346,
|
64 |
+
"step": 1600
|
65 |
+
},
|
66 |
+
{
|
67 |
+
"epoch": 24.69,
|
68 |
+
"learning_rate": 1.7823834196891192e-05,
|
69 |
+
"loss": 0.0125,
|
70 |
+
"step": 2000
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"epoch": 24.69,
|
74 |
+
"eval_loss": 0.769702672958374,
|
75 |
+
"eval_runtime": 86.2655,
|
76 |
+
"eval_samples_per_second": 10.213,
|
77 |
+
"eval_wer": 0.5224530168150346,
|
78 |
+
"step": 2000
|
79 |
+
},
|
80 |
+
{
|
81 |
+
"epoch": 29.63,
|
82 |
+
"learning_rate": 1.2435233160621762e-06,
|
83 |
+
"loss": 0.0167,
|
84 |
+
"step": 2400
|
85 |
+
},
|
86 |
+
{
|
87 |
+
"epoch": 29.63,
|
88 |
+
"eval_loss": 0.7395063638687134,
|
89 |
+
"eval_runtime": 83.5861,
|
90 |
+
"eval_samples_per_second": 10.54,
|
91 |
+
"eval_wer": 0.5198813056379822,
|
92 |
+
"step": 2400
|
93 |
+
}
|
94 |
+
],
|
95 |
+
"max_steps": 2430,
|
96 |
+
"num_train_epochs": 30,
|
97 |
+
"total_flos": 9.370015200295258e+18,
|
98 |
+
"trial_name": null,
|
99 |
+
"trial_params": null
|
100 |
+
}
|
training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0937970b40987b25b7283a4c90e818b7ccd2993130e0236b66f7b493b31db24f
|
3 |
+
size 2287
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"r": 0, "o": 1, "x": 2, "e": 3, "u": 4, "š": 5, "v": 6, "ž": 7, "c": 8, "h": 9, "i": 10, "p": 11, "č": 12, "w": 13, "b": 14, "y": 15, "s": 16, "d": 17, "m": 18, "z": 19, "l": 20, "f": 21, "n": 23, "j": 24, "a": 25, "k": 26, "t": 27, "g": 28, "|": 22, "[UNK]": 29, "[PAD]": 30}
|