Commit
·
c877ba5
1
Parent(s):
97139bf
Added a 4-gram language model based on a 40M token social media corpus.
Browse files- README.md +55 -0
- alphabet.json +1 -0
- config.json +83 -0
- language_model/4gram.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
- special_tokens_map.json +1 -0
- tokenizer_config.json +1 -0
- vocab.json +1 -0
README.md
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: sv
|
3 |
+
datasets:
|
4 |
+
- common_voice
|
5 |
+
- NST Swedish ASR Database
|
6 |
+
- P4
|
7 |
+
metrics:
|
8 |
+
- wer
|
9 |
+
tags:
|
10 |
+
- audio
|
11 |
+
- automatic-speech-recognition
|
12 |
+
- speech
|
13 |
+
license: cc0-1.0
|
14 |
+
model-index:
|
15 |
+
- name: Wav2vec 2.0 large VoxRex Swedish 4-gram
|
16 |
+
---
|
17 |
+
|
18 |
+
# KBLab's wav2vec 2.0 large VoxRex Swedish (C) with 4-gram model
|
19 |
+
Training of the acoustic model is the work of KBLab. See [VoxRex-C](https://huggingface.co/KBLab/wav2vec2-large-voxrex-swedish) for more details. This repo extends the acoustic model with a social media 4-gram language model for boosted performance.
|
20 |
+
|
21 |
+
## Model description
|
22 |
+
VoxRex-C is extended with a 4-gram language model estimated from a subset extracted from [The Swedish Culturomics Gigaword Corpus](https://spraakbanken.gu.se/resurser/gigaword) from Språkbanken. The subset contains 40M words from the social media genre between 2010 and 2015.
|
23 |
+
|
24 |
+
## How to use
|
25 |
+
Audio should be downsampled to 16kHz.
|
26 |
+
|
27 |
+
```python
|
28 |
+
import torch
|
29 |
+
import torchaudio
|
30 |
+
from datasets import load_dataset
|
31 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
32 |
+
test_dataset = load_dataset("common_voice", "sv-SE", split="test[:2%]").
|
33 |
+
processor = Wav2Vec2Processor.from_pretrained("KBLab/wav2vec2-large-voxrex-swedish")
|
34 |
+
model = Wav2Vec2ForCTC.from_pretrained("KBLab/wav2vec2-large-voxrex-swedish")
|
35 |
+
resampler = torchaudio.transforms.Resample(48_000, 16_000)
|
36 |
+
# Preprocessing the datasets.
|
37 |
+
# We need to read the aduio files as arrays
|
38 |
+
def speech_file_to_array_fn(batch):
|
39 |
+
speech_array, sampling_rate = torchaudio.load(batch["path"])
|
40 |
+
batch["speech"] = resampler(speech_array).squeeze().numpy()
|
41 |
+
return batch
|
42 |
+
test_dataset = test_dataset.map(speech_file_to_array_fn)
|
43 |
+
inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
|
44 |
+
with torch.no_grad():
|
45 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
46 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
47 |
+
print("Prediction:", processor.batch_decode(predicted_ids))
|
48 |
+
print("Reference:", test_dataset["sentence"][:2])
|
49 |
+
```
|
50 |
+
|
51 |
+
## Training procedure
|
52 |
+
Text data for the n-gram model is pre-processed by removing characters not part of the wav2vec 2.0 vocabulary and uppercasing all characters. After pre-processing and storing each text sample on a new line in a text file, a [KenLM](https://github.com/kpu/kenlm) model is estimated. See [this tutorial](https://huggingface.co/blog/wav2vec2-with-ngram) for more details.
|
53 |
+
|
54 |
+
## Evaluation results
|
55 |
+
The model was evaluated on the full Common Voice test set version 6.1. VoxRex-C achieved a WER of 9.03% without the language model and 6.47% with the language model.
|
alphabet.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"labels": ["", "<s>", "</s>", "\u2047", " ", "T", "E", "A", "N", "R", "S", "I", "L", "D", "O", "M", "K", "G", "U", "V", "F", "H", "\u00c4", "\u00c5", "P", "\u00d6", "B", "J", "C", "Y", "X", "W", "Z", "\u00c9", "Q", "8", "2", "5", "9", "1", "6", "7", "3", "4", "0", "'"], "is_bpe": false}
|
config.json
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"activation_dropout": 0.05,
|
3 |
+
"apply_spec_augment": true,
|
4 |
+
"architectures": [
|
5 |
+
"Wav2Vec2ForCTC"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"bos_token_id": 1,
|
9 |
+
"codevector_dim": 256,
|
10 |
+
"contrastive_logits_temperature": 0.1,
|
11 |
+
"conv_bias": true,
|
12 |
+
"conv_dim": [
|
13 |
+
512,
|
14 |
+
512,
|
15 |
+
512,
|
16 |
+
512,
|
17 |
+
512,
|
18 |
+
512,
|
19 |
+
512
|
20 |
+
],
|
21 |
+
"conv_kernel": [
|
22 |
+
10,
|
23 |
+
3,
|
24 |
+
3,
|
25 |
+
3,
|
26 |
+
3,
|
27 |
+
2,
|
28 |
+
2
|
29 |
+
],
|
30 |
+
"conv_stride": [
|
31 |
+
5,
|
32 |
+
2,
|
33 |
+
2,
|
34 |
+
2,
|
35 |
+
2,
|
36 |
+
2,
|
37 |
+
2
|
38 |
+
],
|
39 |
+
"ctc_loss_reduction": "mean",
|
40 |
+
"ctc_zero_infinity": true,
|
41 |
+
"diversity_loss_weight": 0.1,
|
42 |
+
"do_stable_layer_norm": true,
|
43 |
+
"eos_token_id": 2,
|
44 |
+
"feat_extract_activation": "gelu",
|
45 |
+
"feat_extract_dropout": 0.0,
|
46 |
+
"feat_extract_norm": "layer",
|
47 |
+
"feat_proj_dropout": 0.05,
|
48 |
+
"feat_quantizer_dropout": 0.0,
|
49 |
+
"final_dropout": 0.0,
|
50 |
+
"gradient_checkpointing": true,
|
51 |
+
"hidden_act": "gelu",
|
52 |
+
"hidden_dropout": 0.05,
|
53 |
+
"hidden_size": 1024,
|
54 |
+
"initializer_range": 0.02,
|
55 |
+
"intermediate_size": 4096,
|
56 |
+
"layer_norm_eps": 1e-05,
|
57 |
+
"layerdrop": 0.05,
|
58 |
+
"mask_channel_length": 10,
|
59 |
+
"mask_channel_min_space": 1,
|
60 |
+
"mask_channel_other": 0.0,
|
61 |
+
"mask_channel_prob": 0.0,
|
62 |
+
"mask_channel_selection": "static",
|
63 |
+
"mask_feature_length": 10,
|
64 |
+
"mask_feature_prob": 0.0,
|
65 |
+
"mask_time_length": 10,
|
66 |
+
"mask_time_min_space": 1,
|
67 |
+
"mask_time_other": 0.0,
|
68 |
+
"mask_time_prob": 0.05,
|
69 |
+
"mask_time_selection": "static",
|
70 |
+
"model_type": "wav2vec2",
|
71 |
+
"num_attention_heads": 16,
|
72 |
+
"num_codevector_groups": 2,
|
73 |
+
"num_codevectors_per_group": 320,
|
74 |
+
"num_conv_pos_embedding_groups": 16,
|
75 |
+
"num_conv_pos_embeddings": 128,
|
76 |
+
"num_feat_extract_layers": 7,
|
77 |
+
"num_hidden_layers": 24,
|
78 |
+
"num_negatives": 100,
|
79 |
+
"pad_token_id": 0,
|
80 |
+
"proj_codevector_dim": 256,
|
81 |
+
"transformers_version": "4.8.2",
|
82 |
+
"vocab_size": 46
|
83 |
+
}
|
language_model/4gram.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:60c6f63f684d7bdffd77c0d0c5419745af253620ead85b842d45f60d2e9c8434
|
3 |
+
size 1151612569
|
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:7138b3f9c5700388ddbd8b08a194290529778aba95327e7445a621cbe24ef508
|
3 |
+
size 1262106353
|
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": true, "word_delimiter_token": "|", "special_tokens_map_file": "/home/viktor.enzell/.cache/huggingface/transformers/0b261be51f4e64178898783357df2bcf65f8812f0093cae011abf9c9e2219a9c.9d6cd81ef646692fb1c169a880161ea1cb95f49694f220aced9b704b457e51dd", "tokenizer_file": null, "name_or_path": "KBLab/wav2vec2-large-voxrex-swedish", "tokenizer_class": "Wav2Vec2CTCTokenizer", "processor_class": "Wav2Vec2ProcessorWithLM"}
|
vocab.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"<pad>": 0, "<s>": 1, "</s>": 2, "<unk>": 3, "|": 4, "T": 5, "E": 6, "A": 7, "N": 8, "R": 9, "S": 10, "I": 11, "L": 12, "D": 13, "O": 14, "M": 15, "K": 16, "G": 17, "U": 18, "V": 19, "F": 20, "H": 21, "Ä": 22, "Å": 23, "P": 24, "Ö": 25, "B": 26, "J": 27, "C": 28, "Y": 29, "X": 30, "W": 31, "Z": 32, "É": 33, "Q": 34, "8": 35, "2": 36, "5": 37, "9": 38, "1": 39, "6": 40, "7": 41, "3": 42, "4": 43, "0": 44, "'": 45}
|