ArthurZ HF staff commited on
Commit
b4ff241
1 Parent(s): eaec18a

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +206 -0
README.md ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - audio
6
+ - automatic-speech-recognition
7
+ - hf-asr-leaderboard
8
+ widget:
9
+ - example_title: Librispeech sample 1
10
+ src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
11
+ - example_title: Librispeech sample 2
12
+ src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
13
+ model-index:
14
+ - name: whisper-small.en
15
+ results:
16
+ - task:
17
+ name: Automatic Speech Recognition
18
+ type: automatic-speech-recognition
19
+ dataset:
20
+ name: LibriSpeech (clean)
21
+ type: librispeech_asr
22
+ config: clean
23
+ split: test
24
+ args:
25
+ language: en
26
+ metrics:
27
+ - name: Test WER
28
+ type: wer
29
+ value:
30
+ - task:
31
+ name: Automatic Speech Recognition
32
+ type: automatic-speech-recognition
33
+ dataset:
34
+ name: LibriSpeech (other)
35
+ type: librispeech_asr
36
+ config: other
37
+ split: test
38
+ args:
39
+ language: en
40
+ metrics:
41
+ - name: Test WER
42
+ type: wer
43
+ value:
44
+ pipeline_tag: automatic-speech-recognition
45
+ license: apache-2.0
46
+ ---
47
+
48
+ # Whisper
49
+
50
+ [OpenAI's Whisper](https://openai.com/blog/whisper/)
51
+
52
+ The Whisper model was proposed in [Robust Speech Recognition via Large-Scale Weak Supervision](https://cdn.openai.com/papers/whisper.pdf) by Alec Radford, Jong Wook Kim, Tao Xu, Greg Brockman, Christine McLeavey, Ilya Sutskever.
53
+
54
+ **Disclaimer**: Content from **this** model card has been written by the Hugging Face team, and parts of it were copy pasted from the original model card.
55
+
56
+
57
+ ## Intro
58
+
59
+ The first paragraphs of the abstract read as follows :
60
+
61
+ > We study the capabilities of speech processing systems trained simply to predict large amounts of transcripts of audio on the internet. When scaled to 680,000 hours of multilingual and multitask supervision, the resulting models generalize well to standard benchmarks and are often competitive with prior fully supervised results but in a zeroshot transfer setting without the need for any finetuning.
62
+ > When compared to humans, the models approach their accuracy and robustness. We are releasing models and inference code to serve as a foundation for further work on robust speech processing.
63
+
64
+ The original code repository can be found [here](https://github.com/openai/whisper).
65
+
66
+ ## Model details
67
+
68
+ The Whisper models are trained for speech recognition and translation tasks, capable of transcribing speech audio into the text in the language it is spoken (ASR) as well as translated into English (speech translation). Researchers at OpenAI developed the models to study the robustness of speech processing systems trained under large-scale weak supervision. There are 9 models of different sizes and capabilities, summarised in the following table.
69
+
70
+ | Size | Parameters | English-only model | Multilingual model |
71
+ |:------:|:----------:|:------------------:|:------------------:|
72
+ | tiny | 39 M | ✓ | ✓ |
73
+ | base | 74 M | ✓ | ✓ |
74
+ | small | 244 M | ✓ | ✓ |
75
+ | medium | 769 M | ✓ | ✓ |
76
+ | large | 1550 M | | ✓ |
77
+
78
+
79
+
80
+ ## Model description
81
+
82
+ Whisper is an auto-regressive automatic speech recognition encoder-decoder model that was trained on 680 000 hours of 16kHz sampled multilingual audio. It was fully trained in a supervised manner, with multiple tasks :
83
+
84
+ - English transcription
85
+ - Any-to-English speech translation
86
+ - Non-English transcription
87
+ - No speech prediction
88
+
89
+ To each task corresponds a sequence of tokens that are given to the decoder as *context tokens*. The beginning of a transcription always starts with `<|startoftranscript|>` which is why the `decoder_start_token` is always set to `tokenizer.encode("<|startoftranscript|>")`. The following token should be the language token, which is automatically detected in the original code. Finally, the task is define using either `<|transcribe|>` or `<|translate|>`. In addition, a `<|notimestamps|>` token is added if the task does not include timestamp prediction.
90
+
91
+
92
+ # Usage
93
+
94
+ To transcribe or translate audio files, the model has to be used along a `WhisperProcessor`. The `WhisperProcessor.get_decoder_prompt_ids` function is used to get a list of `( idx, token )` tuples, which can either be set in the config, or directly passed to the generate function, as `forced_decoder_ids`.
95
+
96
+
97
+ ## Transcription
98
+ In the following example, the english only model is used. We set the `decoder_input_ids` accordingly.
99
+
100
+
101
+ ### English to english
102
+ The "<|en|>" token is used to specify that the speech is in english and should be transcribed to english
103
+
104
+ ```python
105
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
106
+ >>> from datasets import load_dataset
107
+ >>> import torch
108
+
109
+ >>> # load model and processor
110
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-small.en")
111
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small.en")
112
+
113
+ >>> # load dummy dataset and read soundfiles
114
+ >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
115
+ >>> input_features = processor(ds[0]["audio"]["array"], return_tensors="pt").input_features
116
+
117
+ >>> # Generate logits
118
+ >>> logits = model(input_features, decoder_input_ids = torch.tensor([[50258]]).logits
119
+ >>> # take argmax and decode
120
+ >>> predicted_ids = torch.argmax(logits, dim=-1)
121
+ >>> transcription = processor.batch_decode(predicted_ids)
122
+ ['<|startoftranscript|>']
123
+ ```
124
+
125
+
126
+ ## Evaluation
127
+
128
+ This code snippet shows how to evaluate **openai/whisper-small.en** on LibriSpeech's "clean" and "other" test data.
129
+
130
+ ```python
131
+ >>> from datasets import load_dataset
132
+ >>> from transformers import WhisperForConditionalGeneration, WhisperProcessor
133
+ >>> import soundfile as sf
134
+ >>> import torch
135
+ >>> from evaluate import load
136
+
137
+
138
+ >>> librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
139
+
140
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small.en").to("cuda")
141
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-small.en")
142
+
143
+ >>> def map_to_pred(batch):
144
+ >>> input_features = processor(batch["audio"]["array"], return_tensors="pt").input_features
145
+
146
+ >>> with torch.no_grad():
147
+ >>> logits = model(input_features.to("cuda")).logits
148
+
149
+ >>> predicted_ids = torch.argmax(logits, dim=-1)
150
+ >>> transcription = processor.batch_decode(predicted_ids, normalize = True)
151
+ >>> batch['text'] = processor.tokenizer._normalize(batch['text'])
152
+ >>> batch["transcription"] = transcription
153
+ >>> return batch
154
+
155
+ >>> result = librispeech_eval.map(map_to_pred, batched=True, batch_size=1, remove_columns=["speech"])
156
+
157
+ >>> wer = load("wer")
158
+ >>> print(wer.compute(predictions=ds["text"], references=ds["transcription"]))
159
+ 0.07639504403417127
160
+ ```
161
+
162
+
163
+ ### Evaluated Use
164
+
165
+ The primary intended users of these models are AI researchers studying robustness, generalization, capabilities, biases, and constraints of the current model. However, Whisper is also potentially quite useful as an ASR solution for developers, especially for English speech recognition. We recognize that once models are released, it is impossible to restrict access to only “intended” uses or to draw reasonable guidelines around what is or is not research.
166
+
167
+ The models are primarily trained and evaluated on ASR and speech translation to English tasks. They show strong ASR results in ~10 languages. They may exhibit additional capabilities, particularly if fine-tuned on certain tasks like voice activity detection, speaker classification, or speaker diarization but have not been robustly evaluated in these areas. We strongly recommend that users perform robust evaluations of the models in a particular context and domain before deploying them.
168
+
169
+ In particular, we caution against using Whisper models to transcribe recordings of individuals taken without their consent or purporting to use these models for any kind of subjective classification. We recommend against use in high-risk domains like decision-making contexts, where flaws in accuracy can lead to pronounced flaws in outcomes. The models are intended to transcribe and translate speech, use of the model for classification is not only not evaluated but also not appropriate, particularly to infer human attributes.
170
+
171
+
172
+ ## Training Data
173
+
174
+ The models are trained on 680,000 hours of audio and the corresponding transcripts collected from the internet. 65% of this data (or 438,000 hours) represents English-language audio and matched English transcripts, roughly 18% (or 126,000 hours) represents non-English audio and English transcripts, while the final 17% (or 117,000 hours) represents non-English audio and the corresponding transcript. This non-English data represents 98 different languages.
175
+
176
+ As discussed in [the accompanying paper](https://cdn.openai.com/papers/whisper.pdf), we see that performance on transcription in a given language is directly correlated with the amount of training data we employ in that language.
177
+
178
+
179
+ ## Performance and Limitations
180
+
181
+ Our studies show that, over many existing ASR systems, the models exhibit improved robustness to accents, background noise, technical language, as well as zero shot translation from multiple languages into English; and that accuracy on speech recognition and translation is near the state-of-the-art level.
182
+
183
+ However, because the models are trained in a weakly supervised manner using large-scale noisy data, the predictions may include texts that are not actually spoken in the audio input (i.e. hallucination). We hypothesize that this happens because, given their general knowledge of language, the models combine trying to predict the next word in audio with trying to transcribe the audio itself.
184
+
185
+ Our models perform unevenly across languages, and we observe lower accuracy on low-resource and/or low-discoverability languages or languages where we have less training data. The models also exhibit disparate performance on different accents and dialects of particular languages, which may include higher word error rate across speakers of different genders, races, ages, or other demographic criteria. Our full evaluation results are presented in [the paper accompanying this release](https://cdn.openai.com/papers/whisper.pdf).
186
+
187
+ In addition, the sequence-to-sequence architecture of the model makes it prone to generating repetitive texts, which can be mitigated to some degree by beam search and temperature scheduling but not perfectly. Further analysis on these limitations are provided in [the paper](https://cdn.openai.com/papers/whisper.pdf). It is likely that this behavior and hallucinations may be worse on lower-resource and/or lower-discoverability languages.
188
+
189
+
190
+ ## Broader Implications
191
+
192
+ We anticipate that Whisper models’ transcription capabilities may be used for improving accessibility tools. While Whisper models cannot be used for real-time transcription out of the box – their speed and size suggest that others may be able to build applications on top of them that allow for near-real-time speech recognition and translation. The real value of beneficial applications built on top of Whisper models suggests that the disparate performance of these models may have real economic implications.
193
+
194
+ There are also potential dual use concerns that come with releasing Whisper. While we hope the technology will be used primarily for beneficial purposes, making ASR technology more accessible could enable more actors to build capable surveillance technologies or scale up existing surveillance efforts, as the speed and accuracy allow for affordable automatic transcription and translation of large volumes of audio communication. Moreover, these models may have some capabilities to recognize specific individuals out of the box, which in turn presents safety concerns related both to dual use and disparate performance. In practice, we expect that the cost of transcription is not the limiting factor of scaling up surveillance projects.
195
+
196
+
197
+ ### BibTeX entry and citation info
198
+ *Since no official citation was provided, we use the following in the mean time*
199
+ ```bibtex
200
+ @misc{radford2022whisper,
201
+ title={Robust Speech Recognition via Large-Scale Weak Supervision.},
202
+ author={Alec Radford, Jong Wook Kim, Tao Xu, Greg Brockman, Christine McLeavey, Ilya Sutskever},
203
+ year={2022},
204
+ url={https://cdn.openai.com/papers/whisper.pdf},
205
+ }
206
+ ```