dragonSwing
commited on
Commit
•
d61fa3e
1
Parent(s):
e4f1b1a
commit from $USER
Browse files- README.md +90 -0
- config.json +75 -0
- preprocessor_config.json +9 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- vocab.json +1 -0
README.md
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: vi
|
3 |
+
datasets:
|
4 |
+
- vlsp
|
5 |
+
metrics:
|
6 |
+
- wer
|
7 |
+
tags:
|
8 |
+
- audio
|
9 |
+
- automatic-speech-recognition
|
10 |
+
- speech
|
11 |
+
license: apache-2.0
|
12 |
+
model-index:
|
13 |
+
- name: Wav2vec2 Base Vietnamese
|
14 |
+
results:
|
15 |
+
- task:
|
16 |
+
name: Speech Recognition
|
17 |
+
type: automatic-speech-recognition
|
18 |
+
dataset:
|
19 |
+
name: Common Voice vi
|
20 |
+
type: common_voice
|
21 |
+
args: vi
|
22 |
+
metrics:
|
23 |
+
- name: Test WER
|
24 |
+
type: wer
|
25 |
+
value: 31.76
|
26 |
+
---
|
27 |
+
# Wav2Vec2-Large-XLSR-53-Vietnamese
|
28 |
+
Fine-tuned [dragonSwing/wav2vec2-base-pretrain-vietnamese](https://huggingface.co/dragonSwing/wav2vec2-base-pretrain-vietnamese) on Vietnamese Speech Recognition task using 100h labelled data from [VSLP dataset](https://drive.google.com/file/d/1vUSxdORDxk-ePUt-bUVDahpoXiqKchMx/view?usp=sharing).
|
29 |
+
When using this model, make sure that your speech input is sampled at 16kHz.
|
30 |
+
## Usage
|
31 |
+
The model can be used directly (without a language model) as follows:
|
32 |
+
```python
|
33 |
+
import torch
|
34 |
+
import torchaudio
|
35 |
+
from datasets import load_dataset
|
36 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
37 |
+
test_dataset = load_dataset("common_voice", "vi", split="test")
|
38 |
+
processor = Wav2Vec2Processor.from_pretrained("dragonSwing/wav2vec2-base-vietnamese")
|
39 |
+
model = Wav2Vec2ForCTC.from_pretrained("dragonSwing/wav2vec2-base-vietnamese")
|
40 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
41 |
+
# Preprocessing the datasets.
|
42 |
+
# We need to read the aduio files as arrays
|
43 |
+
def speech_file_to_array_fn(batch):
|
44 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
45 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
46 |
+
return batch
|
47 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
48 |
+
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
49 |
+
with torch.no_grad():
|
50 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
51 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
52 |
+
print("Prediction:", processor.batch_decode(predicted_ids))
|
53 |
+
print("Reference:", test_dataset["sentence"][:2])
|
54 |
+
```
|
55 |
+
## Evaluation
|
56 |
+
The model can be evaluated as follows on the Vietnamese test data of Common Voice.
|
57 |
+
```python
|
58 |
+
import torch
|
59 |
+
import torchaudio
|
60 |
+
from datasets import load_dataset, load_metric
|
61 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
62 |
+
import re
|
63 |
+
test_dataset = load_dataset("common_voice", "vi", split="test")
|
64 |
+
wer = load_metric("wer")
|
65 |
+
processor = Wav2Vec2Processor.from_pretrained("dragonSwing/wav2vec2-base-vietnamese")
|
66 |
+
model = Wav2Vec2ForCTC.from_pretrained("dragonSwing/wav2vec2-base-vietnamese")
|
67 |
+
model.to("cuda")
|
68 |
+
chars_to_ignore_regex = r'[,?.!\-;:"“%\'�]'
|
69 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
70 |
+
# Preprocessing the datasets.
|
71 |
+
# We need to read the aduio files as arrays
|
72 |
+
def speech_file_to_array_fn(batch):
|
73 |
+
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
|
74 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
75 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
76 |
+
return batch
|
77 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
78 |
+
# Preprocessing the datasets.
|
79 |
+
# We need to read the aduio files as arrays
|
80 |
+
def evaluate(batch):
|
81 |
+
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
|
82 |
+
with torch.no_grad():
|
83 |
+
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
|
84 |
+
pred_ids = torch.argmax(logits, dim=-1)
|
85 |
+
batch["pred_strings"] = processor.batch_decode(pred_ids)
|
86 |
+
return batch
|
87 |
+
result = test_dataset.map(evaluate, batched=True, batch_size=1)
|
88 |
+
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
|
89 |
+
```
|
90 |
+
**Test Result**: 31.76%
|
config.json
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/content/drive/MyDrive/wav2vec2-base-vn/fosd/checkpoint-96000",
|
3 |
+
"activation_dropout": 0.1,
|
4 |
+
"apply_spec_augment": true,
|
5 |
+
"architectures": [
|
6 |
+
"Wav2Vec2ForCTC"
|
7 |
+
],
|
8 |
+
"attention_dropout": 0.1,
|
9 |
+
"bos_token_id": 1,
|
10 |
+
"codevector_dim": 256,
|
11 |
+
"contrastive_logits_temperature": 0.1,
|
12 |
+
"conv_bias": false,
|
13 |
+
"conv_dim": [
|
14 |
+
512,
|
15 |
+
512,
|
16 |
+
512,
|
17 |
+
512,
|
18 |
+
512,
|
19 |
+
512,
|
20 |
+
512
|
21 |
+
],
|
22 |
+
"conv_kernel": [
|
23 |
+
10,
|
24 |
+
3,
|
25 |
+
3,
|
26 |
+
3,
|
27 |
+
3,
|
28 |
+
2,
|
29 |
+
2
|
30 |
+
],
|
31 |
+
"conv_stride": [
|
32 |
+
5,
|
33 |
+
2,
|
34 |
+
2,
|
35 |
+
2,
|
36 |
+
2,
|
37 |
+
2,
|
38 |
+
2
|
39 |
+
],
|
40 |
+
"ctc_loss_reduction": "mean",
|
41 |
+
"ctc_zero_infinity": true,
|
42 |
+
"diversity_loss_weight": 0.1,
|
43 |
+
"do_stable_layer_norm": false,
|
44 |
+
"eos_token_id": 2,
|
45 |
+
"feat_extract_activation": "gelu",
|
46 |
+
"feat_extract_norm": "group",
|
47 |
+
"feat_proj_dropout": 0.0,
|
48 |
+
"feat_quantizer_dropout": 0.0,
|
49 |
+
"final_dropout": 0.1,
|
50 |
+
"gradient_checkpointing": true,
|
51 |
+
"hidden_act": "gelu",
|
52 |
+
"hidden_dropout": 0.1,
|
53 |
+
"hidden_size": 768,
|
54 |
+
"initializer_range": 0.02,
|
55 |
+
"intermediate_size": 3072,
|
56 |
+
"layer_norm_eps": 1e-05,
|
57 |
+
"layerdrop": 0.1,
|
58 |
+
"mask_feature_length": 10,
|
59 |
+
"mask_feature_prob": 0.0,
|
60 |
+
"mask_time_length": 10,
|
61 |
+
"mask_time_prob": 0.05,
|
62 |
+
"model_type": "wav2vec2",
|
63 |
+
"num_attention_heads": 12,
|
64 |
+
"num_codevector_groups": 2,
|
65 |
+
"num_codevectors_per_group": 320,
|
66 |
+
"num_conv_pos_embedding_groups": 16,
|
67 |
+
"num_conv_pos_embeddings": 128,
|
68 |
+
"num_feat_extract_layers": 7,
|
69 |
+
"num_hidden_layers": 12,
|
70 |
+
"num_negatives": 100,
|
71 |
+
"pad_token_id": 0,
|
72 |
+
"proj_codevector_dim": 256,
|
73 |
+
"transformers_version": "4.6.1",
|
74 |
+
"vocab_size": 98
|
75 |
+
}
|
preprocessor_config.json
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"do_normalize": true,
|
3 |
+
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
4 |
+
"feature_size": 1,
|
5 |
+
"padding_side": "right",
|
6 |
+
"padding_value": 0.0,
|
7 |
+
"return_attention_mask": true,
|
8 |
+
"sampling_rate": 16000
|
9 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9ec143e2442a06b362622f1c6238b3af164858f4e7dc4f4c1cda998d402c7e86
|
3 |
+
size 377873047
|
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": "|"}
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"<pad>": 0, "<s>": 1, "</s>": 2, "<unk>": 3, "|": 4, "j": 5, "ũ": 6, "f": 7, "v": 8, "ỗ": 9, "ạ": 10, "ể": 11, "é": 12, "è": 13, "ọ": 14, "s": 15, "ẻ": 16, "b": 17, "ữ": 18, "w": 19, "g": 20, "ì": 21, "k": 22, "ứ": 23, "ố": 24, "ở": 25, "e": 26, "à": 27, "â": 28, "á": 29, "ẵ": 30, "í": 31, "ử": 32, "ớ": 33, "ằ": 34, "ẩ": 35, "ẽ": 36, "ủ": 37, "ả": 38, "ệ": 39, "i": 40, "ă": 41, "ặ": 42, "d": 43, "ờ": 44, "ề": 45, "ồ": 46, "ừ": 47, "ổ": 48, "o": 49, "h": 50, "ấ": 51, "ẳ": 52, "ỳ": 53, "n": 54, "ụ": 55, "y": 56, "r": 57, "đ": 58, "ẫ": 59, "ỏ": 60, "ẹ": 61, "ễ": 62, "ĩ": 63, "ế": 64, "ỹ": 65, "p": 66, "ị": 67, "ộ": 68, "ã": 69, "ý": 70, "ắ": 71, "z": 72, "ô": 73, "ù": 74, "m": 75, "õ": 76, "c": 77, "t": 78, "ự": 79, "ợ": 80, "u": 81, "ê": 82, "ậ": 83, "ỡ": 84, "ỵ": 85, "ư": 86, "x": 87, "a": 88, "ó": 89, "ỉ": 90, "ỷ": 91, "l": 92, "ầ": 93, "q": 94, "ú": 95, "ò": 96, "ơ": 97}
|