patrickvonplaten commited on
Commit
a82e707
1 Parent(s): 1e95390

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +117 -0
README.md ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ datasets:
4
+ - librispeech_asr
5
+ tags:
6
+ - speech
7
+ - hf-asr-leaderboard
8
+
9
+ license: apache-2.0
10
+ widget:
11
+ - example_title: Librispeech sample 1
12
+ src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
13
+ - example_title: Librispeech sample 2
14
+ src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
15
+ model-index:
16
+ - name: data2vec-audio-large-960h
17
+ results:
18
+ - task:
19
+ name: Automatic Speech Recognition
20
+ type: automatic-speech-recognition
21
+ dataset:
22
+ name: Librispeech (clean)
23
+ type: librispeech_asr
24
+ args: en
25
+ metrics:
26
+ - name: Test WER
27
+ type: wer
28
+ value: 1.89
29
+ ---
30
+
31
+ # Data2Vec-Audio-Large-960h
32
+
33
+ [Facebook's Data2Vec](https://ai.facebook.com/research/data2vec-a-general-framework-for-self-supervised-learning-in-speech-vision-and-language/)
34
+
35
+ The large model pretrained and fine-tuned on 960 hours of Librispeech on 16kHz sampled speech audio. When using the model
36
+ make sure that your speech input is also sampled at 16Khz.
37
+
38
+ [Paper](https://arxiv.org/abs/2202.03555)
39
+
40
+ Authors: Alexei Baevski, Wei-Ning Hsu, Qiantong Xu, Arun Babu, Jiatao Gu, Michael Auli
41
+
42
+ **Abstract**
43
+
44
+ While the general idea of self-supervised learning is identical across modalities, the actual algorithms and objectives differ widely because they were developed with a single modality in mind. To get us closer to general self-supervised learning, we present data2vec, a framework that uses the same learning method for either speech, NLP or computer vision. The core idea is to predict latent representations of the full input data based on a masked view of the input in a self-distillation setup using a standard Transformer architecture. Instead of predicting modality-specific targets such as words, visual tokens or units of human speech which are local in nature, data2vec predicts contextualized latent representations that contain information from the entire input. Experiments on the major benchmarks of speech recognition, image classification, and natural language understanding demonstrate a new state of the art or competitive performance to predominant approaches.
45
+
46
+ The original model can be found under https://github.com/pytorch/fairseq/tree/main/examples/data2vec .
47
+
48
+ # Pre-Training method
49
+
50
+ ![model image](https://raw.githubusercontent.com/patrickvonplaten/scientific_images/master/data2vec.png)
51
+
52
+ For more information, please take a look at the [official paper](https://arxiv.org/abs/2202.03555).
53
+
54
+ # Usage
55
+
56
+ To transcribe audio files the model can be used as a standalone acoustic model as follows:
57
+
58
+ ```python
59
+ from transformers import Wav2Vec2Processor, Data2VecForCTC
60
+ from datasets import load_dataset
61
+ import torch
62
+
63
+ # load model and processor
64
+ processor = Wav2Vec2Processor.from_pretrained("facebook/data2vec-audio-large-960h")
65
+ model = Data2VecForCTC.from_pretrained("facebook/data2vec-audio-large-960h")
66
+
67
+ # load dummy dataset and read soundfiles
68
+ ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
69
+
70
+ # tokenize
71
+ input_values = processor(ds[0]["audio"]["array"],, return_tensors="pt", padding="longest").input_values # Batch size 1
72
+
73
+ # retrieve logits
74
+ logits = model(input_values).logits
75
+
76
+ # take argmax and decode
77
+ predicted_ids = torch.argmax(logits, dim=-1)
78
+ transcription = processor.batch_decode(predicted_ids)
79
+ ```
80
+
81
+ ## Evaluation
82
+
83
+ This code snippet shows how to evaluate **facebook/data2vec-audio-large-960h** on LibriSpeech's "clean" and "other" test data.
84
+
85
+ ```python
86
+ from transformers import Wav2Vec2Processor, Data2VecForCTC
87
+ from datasets import load_dataset
88
+ import torch
89
+ from jiwer import wer
90
+
91
+ # load model and processor
92
+ processor = Wav2Vec2Processor.from_pretrained("facebook/data2vec-audio-large-960h").to("cuda")
93
+ model = Data2VecForCTC.from_pretrained("facebook/data2vec-audio-large-960h")
94
+
95
+
96
+ librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
97
+
98
+ def map_to_pred(batch):
99
+ input_values = processor(batch["audio"]["array"], return_tensors="pt", padding="longest").input_values
100
+ with torch.no_grad():
101
+ logits = model(input_values.to("cuda")).logits
102
+
103
+ predicted_ids = torch.argmax(logits, dim=-1)
104
+ transcription = processor.batch_decode(predicted_ids)
105
+ batch["transcription"] = transcription
106
+ return batch
107
+
108
+ result = librispeech_eval.map(map_to_pred, batched=True, batch_size=1, remove_columns=["audio"])
109
+
110
+ print("WER:", wer(result["text"], result["transcription"]))
111
+ ```
112
+
113
+ *Result (WER)*:
114
+
115
+ | "clean" | "other" |
116
+ |---|---|
117
+ | 1.89 | 4.07 |