Yuvarraj commited on
Commit
55938e8
1 Parent(s): e594333

Upload 8 files

Browse files
README.md ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ datasets:
4
+ - librispeech_asr
5
+ tags:
6
+ - speech
7
+
8
+ license: apache-2.0
9
+ ---
10
+
11
+ # Wav2Vec2-Large-960h
12
+
13
+ [Facebook's Wav2Vec2](https://ai.facebook.com/blog/wav2vec-20-learning-the-structure-of-speech-from-raw-audio/)
14
+
15
+ The large model pretrained and fine-tuned on 960 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 torch
37
+
38
+ # load model and processor
39
+ processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h")
40
+ model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h")
41
+
42
+ # load dummy dataset and read soundfiles
43
+ ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
44
+
45
+ # tokenize
46
+ input_values = processor(ds[0]["audio"]["array"],, return_tensors="pt", padding="longest").input_values # Batch size 1
47
+
48
+ # retrieve logits
49
+ logits = model(input_values).logits
50
+
51
+ # take argmax and decode
52
+ predicted_ids = torch.argmax(logits, dim=-1)
53
+ transcription = processor.batch_decode(predicted_ids)
54
+ ```
55
+
56
+ ## Evaluation
57
+
58
+ This code snippet shows how to evaluate **facebook/wav2vec2-large-960h** on LibriSpeech's "clean" and "other" test data.
59
+
60
+ ```python
61
+ from datasets import load_dataset
62
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
63
+ import soundfile as sf
64
+ import torch
65
+ from jiwer import wer
66
+
67
+
68
+ librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
69
+
70
+ model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-large-960h").to("cuda")
71
+ processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-large-960h")
72
+
73
+ def map_to_pred(batch):
74
+ input_values = processor(batch["audio"]["array"], return_tensors="pt", padding="longest").input_values
75
+ with torch.no_grad():
76
+ logits = model(input_values.to("cuda")).logits
77
+
78
+ predicted_ids = torch.argmax(logits, dim=-1)
79
+ transcription = processor.batch_decode(predicted_ids)
80
+ batch["transcription"] = transcription
81
+ return batch
82
+
83
+ result = librispeech_eval.map(map_to_pred, batched=True, batch_size=1, remove_columns=["speech"])
84
+
85
+ print("WER:", wer(result["text"], result["transcription"]))
86
+ ```
87
+
88
+ *Result (WER)*:
89
+
90
+ | "clean" | "other" |
91
+ |---|---|
92
+ | 2.8 | 6.3 |
config.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Wav2Vec2ForCTC"
4
+ ],
5
+ "conv_bias": false,
6
+ "conv_dim": [
7
+ 512,
8
+ 512,
9
+ 512,
10
+ 512,
11
+ 512,
12
+ 512,
13
+ 512
14
+ ],
15
+ "conv_kernel": [
16
+ 10,
17
+ 3,
18
+ 3,
19
+ 3,
20
+ 3,
21
+ 2,
22
+ 2
23
+ ],
24
+ "conv_stride": [
25
+ 5,
26
+ 2,
27
+ 2,
28
+ 2,
29
+ 2,
30
+ 2,
31
+ 2
32
+ ],
33
+ "do_stable_layer_norm": false,
34
+ "feat_extract_activation": "gelu",
35
+ "feat_extract_dropout": 0.0,
36
+ "feat_extract_norm": "group",
37
+ "hidden_act": "gelu",
38
+ "hidden_dropout_prob": 0.1,
39
+ "hidden_size": 1024,
40
+ "initializer_range": 0.02,
41
+ "intermediate_size": 4096,
42
+ "layer_norm_eps": 1e-05,
43
+ "model_type": "wav2vec2",
44
+ "num_attention_heads": 16,
45
+ "num_conv_pos_embedding_groups": 16,
46
+ "num_conv_pos_embeddings": 128,
47
+ "num_feat_extract_layers": 7,
48
+ "num_hidden_layers": 24,
49
+ "transformers_version": "4.3.0.dev0",
50
+ "vocab_size": 32
51
+ }
gitattributes.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.arrow filter=lfs diff=lfs merge=lfs -text
10
+ *.ftz filter=lfs diff=lfs merge=lfs -text
11
+ *.joblib filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.pb filter=lfs diff=lfs merge=lfs -text
15
+ *.pt filter=lfs diff=lfs merge=lfs -text
16
+ *.pth filter=lfs diff=lfs merge=lfs -text
17
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
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:7aef99395c7b7ab5b78b6d00bdf71aebd93a7340b72d614303d598de8f94a10f
3
+ size 1262009187
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, "return_attention_mask": false, "do_normalize": true}
vocab.json ADDED
@@ -0,0 +1 @@
 
1
+ {"<pad>": 0, "<s>": 1, "</s>": 2, "<unk>": 3, "|": 4, "E": 5, "T": 6, "A": 7, "O": 8, "N": 9, "I": 10, "H": 11, "S": 12, "R": 13, "D": 14, "L": 15, "U": 16, "M": 17, "W": 18, "C": 19, "F": 20, "G": 21, "Y": 22, "P": 23, "B": 24, "V": 25, "K": 26, "'": 27, "X": 28, "J": 29, "Q": 30, "Z": 31}