tugstugi commited on
Commit
daa7e86
1 Parent(s): d7de8f5

initial commit

Browse files
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ cv-corpus-6.1-2020-12-11
README.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: mn
3
+ datasets:
4
+ - common_voice
5
+ tags:
6
+ - speech
7
+ - audio
8
+ - automatic-speech-recognition
9
+ license: apache-2.0
10
+ ---
11
+
12
+ ## Evaluation on Common Voice Mongolian Test
13
+ ```python
14
+ import torchaudio
15
+ from datasets import load_dataset, load_metric
16
+ from transformers import (
17
+ Wav2Vec2ForCTC,
18
+ Wav2Vec2Processor,
19
+ )
20
+ import torch
21
+ import re
22
+ import sys
23
+
24
+ model_name = "tugstugi/wav2vec2-large-xlsr-53-mongolian"
25
+ device = "cuda"
26
+
27
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"]' # noqa: W605
28
+
29
+ model = Wav2Vec2ForCTC.from_pretrained(model_name).to(device)
30
+ processor = Wav2Vec2Processor.from_pretrained(model_name)
31
+
32
+ ds = load_dataset("common_voice", "mn", split="test", data_dir="./cv-corpus-6.1-2020-12-11")
33
+
34
+ resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000)
35
+
36
+ def map_to_array(batch):
37
+ speech, _ = torchaudio.load(batch["path"])
38
+ batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
39
+ batch["sampling_rate"] = resampler.new_freq
40
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
41
+ return batch
42
+
43
+ ds = ds.map(map_to_array)
44
+
45
+ def map_to_pred(batch):
46
+ features = processor(batch["speech"], sampling_rate=batch["sampling_rate"][0], padding=True, return_tensors="pt")
47
+ input_values = features.input_values.to(device)
48
+ attention_mask = features.attention_mask.to(device)
49
+ with torch.no_grad():
50
+ logits = model(input_values, attention_mask=attention_mask).logits
51
+ pred_ids = torch.argmax(logits, dim=-1)
52
+ batch["predicted"] = processor.batch_decode(pred_ids)
53
+ batch["target"] = batch["sentence"]
54
+ return batch
55
+
56
+ result = ds.map(map_to_pred, batched=True, batch_size=16, remove_columns=list(ds.features.keys()))
57
+
58
+ wer = load_metric("wer")
59
+
60
+ print(wer.compute(predictions=result["predicted"], references=result["target"]))
61
+ ```
62
+ **Result**: 50.0 %
config.json ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "facebook/wav2vec2-large-xlsr-53",
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": 37,
74
+ "transformers_version": "4.4.0.dev0",
75
+ "vocab_size": 38
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:a47ec4a791b0fd90d62b19a0eaa3a6a8875661f796dda6b6049205c55f862869
3
+ size 1262089623
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
+ {"г": 0, "ү": 1, "ю": 2, "р": 3, "д": 4, "е": 5, "э": 6, "ъ": 7, "л": 8, "в": 9, "м": 10, "ө": 11, "т": 12, "ц": 13, "о": 14, "а": 16, "к": 17, "ф": 18, "и": 19, "ш": 20, "я": 21, "h": 22, "з": 23, "ё": 24, "с": 25, "ы": 26, "п": 27, "х": 28, "ж": 29, "ь": 30, "й": 31, "у": 32, "н": 33, "б": 34, "ч": 35, "|": 15, "[UNK]": 36, "[PAD]": 37}