saahith commited on
Commit
e15913a
1 Parent(s): 140222a

add base model

Browse files
README.md ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ datasets:
4
+ - librispeech_asr
5
+ tags:
6
+ - audio
7
+ - automatic-speech-recognition
8
+ license: apache-2.0
9
+ ---
10
+
11
+ # Wav2Vec2-Base-100h
12
+
13
+ [Facebook's Wav2Vec2](https://ai.facebook.com/blog/wav2vec-20-learning-the-structure-of-speech-from-raw-audio/)
14
+
15
+ The base model pretrained and fine-tuned on 100 hours of Librispeech on 16kHz sampled speech audio. When using the model
16
+ make sure that your speech input is also sampled at 16Khz.
17
+
18
+ [Paper](https://arxiv.org/abs/2006.11477)
19
+
20
+ Authors: Alexei Baevski, Henry Zhou, Abdelrahman Mohamed, Michael Auli
21
+
22
+ **Abstract**
23
+
24
+ We show for the first time that learning powerful representations from speech audio alone followed by fine-tuning on transcribed speech can outperform the best semi-supervised methods while being conceptually simpler. wav2vec 2.0 masks the speech input in the latent space and solves a contrastive task defined over a quantization of the latent representations which are jointly learned. Experiments using all labeled data of Librispeech achieve 1.8/3.3 WER on the clean/other test sets. When lowering the amount of labeled data to one hour, wav2vec 2.0 outperforms the previous state of the art on the 100 hour subset while using 100 times less labeled data. Using just ten minutes of labeled data and pre-training on 53k hours of unlabeled data still achieves 4.8/8.2 WER. This demonstrates the feasibility of speech recognition with limited amounts of labeled data.
25
+
26
+ The original model can be found under https://github.com/pytorch/fairseq/tree/master/examples/wav2vec#wav2vec-20.
27
+
28
+
29
+ # Usage
30
+
31
+ To transcribe audio files the model can be used as a standalone acoustic model as follows:
32
+
33
+ ```python
34
+ from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
35
+ from datasets import load_dataset
36
+ import soundfile as sf
37
+ import torch
38
+
39
+ # load model and processor
40
+ processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-100h")
41
+ model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-100h")
42
+
43
+ # define function to read in sound file
44
+ def map_to_array(batch):
45
+ speech, _ = sf.read(batch["file"])
46
+ batch["speech"] = speech
47
+ return batch
48
+
49
+ # load dummy dataset and read soundfiles
50
+ ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
51
+ ds = ds.map(map_to_array)
52
+
53
+ # tokenize
54
+ input_values = processor(ds[0]["audio"]["array"], return_tensors="pt", padding="longest").input_values # Batch size 1
55
+
56
+ # retrieve logits
57
+ logits = model(input_values).logits
58
+
59
+ # take argmax and decode
60
+ predicted_ids = torch.argmax(logits, dim=-1)
61
+ transcription = processor.batch_decode(predicted_ids)
62
+ ```
63
+
64
+ ## Evaluation
65
+
66
+ This code snippet shows how to evaluate **facebook/wav2vec2-base-100h** on LibriSpeech's "clean" and "other" test data.
67
+
68
+ ```python
69
+ from datasets import load_dataset
70
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
71
+ import soundfile as sf
72
+ import torch
73
+ from jiwer import wer
74
+
75
+
76
+ librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
77
+
78
+ model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-100h").to("cuda")
79
+ processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-100h")
80
+
81
+ def map_to_pred(batch):
82
+ input_values = processor(batch["audio"]["array"], return_tensors="pt", padding="longest").input_values
83
+ with torch.no_grad():
84
+ logits = model(input_values.to("cuda")).logits
85
+
86
+ predicted_ids = torch.argmax(logits, dim=-1)
87
+ transcription = processor.batch_decode(predicted_ids)
88
+ batch["transcription"] = transcription
89
+ return batch
90
+
91
+ result = librispeech_eval.map(map_to_pred, batched=True, batch_size=1, remove_columns=["speech"])
92
+
93
+ print("WER:", wer(result["text"], result["transcription"]))
94
+ ```
95
+
96
+ *Result (WER)*:
97
+
98
+ | "clean" | "other" |
99
+ |---|---|
100
+ | 6.1 | 13.5 |
config.json ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation_dropout": 0.1,
3
+ "apply_spec_augment": true,
4
+ "architectures": [
5
+ "Wav2Vec2ForCTC"
6
+ ],
7
+ "attention_dropout": 0.1,
8
+ "bos_token_id": 1,
9
+ "conv_bias": false,
10
+ "conv_dim": [
11
+ 512,
12
+ 512,
13
+ 512,
14
+ 512,
15
+ 512,
16
+ 512,
17
+ 512
18
+ ],
19
+ "conv_kernel": [
20
+ 10,
21
+ 3,
22
+ 3,
23
+ 3,
24
+ 3,
25
+ 2,
26
+ 2
27
+ ],
28
+ "conv_stride": [
29
+ 5,
30
+ 2,
31
+ 2,
32
+ 2,
33
+ 2,
34
+ 2,
35
+ 2
36
+ ],
37
+ "do_stable_layer_norm": false,
38
+ "eos_token_id": 2,
39
+ "feat_extract_activation": "gelu",
40
+ "feat_extract_norm": "group",
41
+ "feat_proj_dropout": 0.1,
42
+ "final_dropout": 0.1,
43
+ "freeze_feat_extract_train": true,
44
+ "hidden_act": "gelu",
45
+ "hidden_dropout": 0.1,
46
+ "hidden_size": 768,
47
+ "initializer_range": 0.02,
48
+ "intermediate_size": 3072,
49
+ "layer_norm_eps": 1e-05,
50
+ "layerdrop": 0.1,
51
+ "mask_channel_length": 10,
52
+ "mask_channel_min_space": 1,
53
+ "mask_channel_other": 0.0,
54
+ "mask_channel_prob": 0.008,
55
+ "mask_channel_selection": "static",
56
+ "mask_time_length": 10,
57
+ "mask_time_min_space": 1,
58
+ "mask_time_other": 0.0,
59
+ "mask_time_prob": 0.05,
60
+ "mask_time_selection": "static",
61
+ "model_type": "wav2vec2",
62
+ "no_mask_channel_overlap": false,
63
+ "no_mask_time_overlap": false,
64
+ "num_attention_heads": 12,
65
+ "num_conv_pos_embedding_groups": 16,
66
+ "num_conv_pos_embeddings": 128,
67
+ "num_feat_extract_layers": 7,
68
+ "num_hidden_layers": 12,
69
+ "pad_token_id": 0,
70
+ "transformers_version": "4.4.0.dev0",
71
+ "vocab_size": 32
72
+ }
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": false,
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:0a445d205b6dc42bca27c0c52b7bb3607fd58a720f0d02a757893cff37ee3ab7
3
+ size 377671532
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "pad_token": "<pad>",
5
+ "unk_token": "<unk>"
6
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "do_lower_case": false,
4
+ "do_normalize": true,
5
+ "eos_token": "</s>",
6
+ "name_or_path": "./",
7
+ "pad_token": "<pad>",
8
+ "replace_word_delimiter_char": " ",
9
+ "return_attention_mask": false,
10
+ "special_tokens_map_file": "./special_tokens_map.json",
11
+ "tokenizer_class": "Wav2Vec2CTCTokenizer",
12
+ "unk_token": "<unk>",
13
+ "word_delimiter_token": "|"
14
+ }
vocab.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "'": 27,
3
+ "</s>": 2,
4
+ "<pad>": 0,
5
+ "<s>": 1,
6
+ "<unk>": 3,
7
+ "A": 7,
8
+ "B": 24,
9
+ "C": 19,
10
+ "D": 14,
11
+ "E": 5,
12
+ "F": 20,
13
+ "G": 21,
14
+ "H": 11,
15
+ "I": 10,
16
+ "J": 29,
17
+ "K": 26,
18
+ "L": 15,
19
+ "M": 17,
20
+ "N": 9,
21
+ "O": 8,
22
+ "P": 23,
23
+ "Q": 30,
24
+ "R": 13,
25
+ "S": 12,
26
+ "T": 6,
27
+ "U": 16,
28
+ "V": 25,
29
+ "W": 18,
30
+ "X": 28,
31
+ "Y": 22,
32
+ "Z": 31,
33
+ "|": 4
34
+ }