reach-vb HF staff commited on
Commit
a8f1981
1 Parent(s): 8a2a8a3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +412 -0
README.md ADDED
@@ -0,0 +1,412 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - zh
5
+ - de
6
+ - es
7
+ - ru
8
+ - ko
9
+ - fr
10
+ - ja
11
+ - pt
12
+ - tr
13
+ - pl
14
+ - ca
15
+ - nl
16
+ - ar
17
+ - sv
18
+ - it
19
+ - id
20
+ - hi
21
+ - fi
22
+ - vi
23
+ - he
24
+ - uk
25
+ - el
26
+ - ms
27
+ - cs
28
+ - ro
29
+ - da
30
+ - hu
31
+ - ta
32
+ - no
33
+ - th
34
+ - ur
35
+ - hr
36
+ - bg
37
+ - lt
38
+ - la
39
+ - mi
40
+ - ml
41
+ - cy
42
+ - sk
43
+ - te
44
+ - fa
45
+ - lv
46
+ - bn
47
+ - sr
48
+ - az
49
+ - sl
50
+ - kn
51
+ - et
52
+ - mk
53
+ - br
54
+ - eu
55
+ - is
56
+ - hy
57
+ - ne
58
+ - mn
59
+ - bs
60
+ - kk
61
+ - sq
62
+ - sw
63
+ - gl
64
+ - mr
65
+ - pa
66
+ - si
67
+ - km
68
+ - sn
69
+ - yo
70
+ - so
71
+ - af
72
+ - oc
73
+ - ka
74
+ - be
75
+ - tg
76
+ - sd
77
+ - gu
78
+ - am
79
+ - yi
80
+ - lo
81
+ - uz
82
+ - fo
83
+ - ht
84
+ - ps
85
+ - tk
86
+ - nn
87
+ - mt
88
+ - sa
89
+ - lb
90
+ - my
91
+ - bo
92
+ - tl
93
+ - mg
94
+ - as
95
+ - tt
96
+ - haw
97
+ - ln
98
+ - ha
99
+ - ba
100
+ - jw
101
+ - su
102
+ tags:
103
+ - audio
104
+ - automatic-speech-recognition
105
+ - hf-asr-leaderboard
106
+ widget:
107
+ - example_title: Librispeech sample 1
108
+ src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
109
+ - example_title: Librispeech sample 2
110
+ src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
111
+ pipeline_tag: automatic-speech-recognition
112
+ license: apache-2.0
113
+ ---
114
+
115
+ # Whisper
116
+
117
+ Whisper is a pre-trained model for automatic speech recognition (ASR) and speech translation. Trained on 680k hours
118
+ of labelled data, Whisper models demonstrate a strong ability to generalise to many datasets and domains **without** the need
119
+ for fine-tuning.
120
+
121
+ Whisper was proposed in the paper [Robust Speech Recognition via Large-Scale Weak Supervision](https://arxiv.org/abs/2212.04356)
122
+ by Alec Radford et al. from OpenAI. The original code repository can be found [here](https://github.com/openai/whisper).
123
+
124
+ Whisper `large-v3` has the same architecture as the previous large models except the following minor differences:
125
+
126
+ 1. The input uses 128 Mel frequency bins instead of 80
127
+ 2. A new language token for Cantonese
128
+
129
+ The Whisper `large-v3` model is trained on 1 million hours of weakly labeled audio and 4 million hours of pseudolabeled audio collected using Whisper `large-v2`.
130
+ The model was trained for 2.0 epochs over this mixture dataset.
131
+
132
+ The `large-v3` model shows improved performance over a wide variety of languages, performs lower than 60% error rate on Common Voice 15 and Fleurs, shows 10% to 20% reduction of errors compared to Whisper `large-v2`.
133
+
134
+
135
+ **Disclaimer**: Content for this model card has partly been written by the Hugging Face team, and parts of it were
136
+ copied and pasted from the original model card.
137
+
138
+ ## Model details
139
+
140
+ Whisper is a Transformer based encoder-decoder model, also referred to as a _sequence-to-sequence_ model.
141
+ It was trained on 1 million hours of weakly labeled audio and 4 million hours of pseudolabeled audio collected using Whisper `large-v2`.
142
+
143
+ The models were trained on either English-only data or multilingual data. The English-only models were trained
144
+ on the task of speech recognition. The multilingual models were trained on both speech recognition and speech
145
+ translation. For speech recognition, the model predicts transcriptions in the *same* language as the audio.
146
+ For speech translation, the model predicts transcriptions to a *different* language to the audio.
147
+
148
+ Whisper checkpoints come in five configurations of varying model sizes.
149
+ The smallest four are trained on either English-only or multilingual data.
150
+ The largest checkpoints are multilingual only. All ten of the pre-trained checkpoints
151
+ are available on the [Hugging Face Hub](https://huggingface.co/models?search=openai/whisper). The
152
+ checkpoints are summarised in the following table with links to the models on the Hub:
153
+
154
+ | Size | Parameters | English-only | Multilingual |
155
+ |----------|------------|------------------------------------------------------|-----------------------------------------------------|
156
+ | tiny | 39 M | [✓](https://huggingface.co/openai/whisper-tiny.en) | [✓](https://huggingface.co/openai/whisper-tiny) |
157
+ | base | 74 M | [✓](https://huggingface.co/openai/whisper-base.en) | [✓](https://huggingface.co/openai/whisper-base) |
158
+ | small | 244 M | [✓](https://huggingface.co/openai/whisper-small.en) | [✓](https://huggingface.co/openai/whisper-small) |
159
+ | medium | 769 M | [✓](https://huggingface.co/openai/whisper-medium.en) | [✓](https://huggingface.co/openai/whisper-medium) |
160
+ | large | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large) |
161
+ | large-v2 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large-v2) |
162
+ | large-v3 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large-v3) |
163
+
164
+ ## Usage
165
+
166
+ Whisper `large-v3` is supported in Hugging Face 🤗 Transformers through the `main` branch in the Transformers repo. To run the model, first
167
+ install the Transformers library through the GitHub repo. For this example, we'll also install 🤗 Datasets to load toy
168
+ audio dataset from the Hugging Face Hub:
169
+
170
+ ```bash
171
+ pip install --upgrade pip
172
+ pip install --upgrade git+https://github.com/huggingface/transformers.git accelerate datasets[audio]
173
+ ```
174
+
175
+ ### Short-Form Transcription
176
+
177
+ The model can be used with the [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
178
+ class to transcribe short-form audio files (< 30-seconds) as follows:
179
+
180
+ ```python
181
+ import torch
182
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
183
+ from datasets import load_dataset
184
+
185
+
186
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
187
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
188
+
189
+ model_id = "openai/whisper-large-v3"
190
+
191
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
192
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
193
+ )
194
+ model.to(device)
195
+
196
+ processor = AutoProcessor.from_pretrained(model_id)
197
+
198
+ pipe = pipeline(
199
+ "automatic-speech-recognition",
200
+ model=model,
201
+ tokenizer=processor.tokenizer,
202
+ feature_extractor=processor.feature_extractor,
203
+ max_new_tokens=128,
204
+ torch_dtype=torch_dtype,
205
+ device=device,
206
+ )
207
+
208
+ dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
209
+ sample = dataset[0]["audio"]
210
+
211
+ result = pipe(sample)
212
+ print(result["text"])
213
+ ```
214
+
215
+ To transcribe a local audio file, simply pass the path to your audio file when you call the pipeline:
216
+ ```diff
217
+ - result = pipe(sample)
218
+ + result = pipe("audio.mp3")
219
+ ```
220
+
221
+ ### Long-Form Transcription
222
+
223
+ Through Transformers Whisper uses a chunked algorithm to transcribe long-form audio files (> 30-seconds). In practice, this chunked long-form algorithm
224
+ is 9x faster than the sequential algorithm proposed by OpenAI in the Whisper paper (see Table 7 of the [Distil-Whisper paper](https://arxiv.org/abs/2311.00430)).
225
+
226
+ To enable chunking, pass the `chunk_length_s` parameter to the `pipeline`. To activate batching, pass the argument `batch_size`:
227
+
228
+ ```python
229
+ import torch
230
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
231
+ from datasets import load_dataset
232
+
233
+
234
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
235
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
236
+
237
+ model_id = "openai/whisper-large-v3"
238
+
239
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
240
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
241
+ )
242
+ model.to(device)
243
+
244
+ processor = AutoProcessor.from_pretrained(model_id)
245
+
246
+ pipe = pipeline(
247
+ "automatic-speech-recognition",
248
+ model=model,
249
+ tokenizer=processor.tokenizer,
250
+ feature_extractor=processor.feature_extractor,
251
+ max_new_tokens=128,
252
+ chunk_length_s=15,
253
+ batch_size=16,
254
+ torch_dtype=torch_dtype,
255
+ device=device,
256
+ )
257
+
258
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
259
+ sample = dataset[0]["audio"]
260
+
261
+ result = pipe(sample)
262
+ print(result["text"])
263
+ ```
264
+
265
+ <!---
266
+ **Tip:** The pipeline can also be used to transcribe an audio file from a remote URL, for example:
267
+
268
+ ```python
269
+ result = pipe("https://huggingface.co/datasets/sanchit-gandhi/librispeech_long/resolve/main/audio.wav")
270
+ ```
271
+ --->
272
+
273
+ ### Speculative Decoding
274
+
275
+ Whisper `tiny` can be used as an assistant model to Whisper for speculative decoding. Speculative decoding mathematically
276
+ ensures the exact same outputs as Whisper are obtained while being 2 times faster. This makes it the perfect drop-in
277
+ replacement for existing Whisper pipelines, since the same outputs are guaranteed.
278
+
279
+ In the following code-snippet, we load the assistant Distil-Whisper model standalone to the main Whisper pipeline. We then
280
+ specify it as the "assistant model" for generation:
281
+
282
+ ```python
283
+ from transformers import pipeline, AutoModelForCausalLM, AutoModelForSpeechSeq2Seq, AutoProcessor
284
+ import torch
285
+ from datasets import load_dataset
286
+
287
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
288
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
289
+
290
+ assistant_model_id = "openai/whisper-tiny"
291
+
292
+ assistant_model = AutoModelForCausalLM.from_pretrained(
293
+ assistant_model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
294
+ )
295
+ assistant_model.to(device)
296
+
297
+ model_id = "openai/whisper-large-v3"
298
+
299
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
300
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
301
+ )
302
+ model.to(device)
303
+
304
+ processor = AutoProcessor.from_pretrained(model_id)
305
+
306
+ pipe = pipeline(
307
+ "automatic-speech-recognition",
308
+ model=model,
309
+ tokenizer=processor.tokenizer,
310
+ feature_extractor=processor.feature_extractor,
311
+ max_new_tokens=128,
312
+ generate_kwargs={"assistant_model": assistant_model},
313
+ torch_dtype=torch_dtype,
314
+ device=device,
315
+ )
316
+
317
+ dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
318
+ sample = dataset[0]["audio"]
319
+
320
+ result = pipe(sample)
321
+ print(result["text"])
322
+ ```
323
+
324
+ ## Additional Speed & Memory Improvements
325
+
326
+ You can apply additional speed and memory improvements to Whisper-large-v3 which we cover in the following.
327
+
328
+ ### Flash Attention
329
+
330
+ We recommend using [Flash-Attention 2](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#flashattention-2) if your GPU allows for it.
331
+ To do so, you first need to install [Flash Attention](https://github.com/Dao-AILab/flash-attention):
332
+
333
+ ```
334
+ pip install flash-attn --no-build-isolation
335
+ ```
336
+
337
+ and then all you have to do is to pass `use_flash_attention_2=True` to `from_pretrained`:
338
+
339
+ ```diff
340
+ - model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
341
+ + model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True, use_flash_attention_2=True)
342
+ ```
343
+
344
+ ### Torch Scale-Product-Attention (SDPA)
345
+
346
+ If your GPU does not support Flash Attention, we recommend making use of [BetterTransformers](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#bettertransformer).
347
+ To do so, you first need to install optimum:
348
+
349
+ ```
350
+ pip install --upgrade optimum
351
+ ```
352
+
353
+ And then convert your model to a "BetterTransformer" model before using it:
354
+
355
+ ```diff
356
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
357
+ + model = model.to_bettertransformer()
358
+ ```
359
+
360
+ ## Fine-Tuning
361
+
362
+ The pre-trained Whisper model demonstrates a strong ability to generalise to different datasets and domains. However,
363
+ its predictive capabilities can be improved further for certain languages and tasks through *fine-tuning*. The blog
364
+ post [Fine-Tune Whisper with 🤗 Transformers](https://huggingface.co/blog/fine-tune-whisper) provides a step-by-step
365
+ guide to fine-tuning the Whisper model with as little as 5 hours of labelled data.
366
+
367
+ ### Evaluated Use
368
+
369
+ 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.
370
+
371
+ 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.
372
+
373
+ 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.
374
+
375
+
376
+ ## Training Data
377
+
378
+ The models are trained on 1 million hours of weakly labeled audio and 4 million hours of pseudolabeled audio collected using Whisper `large-v2`.
379
+
380
+ 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.
381
+
382
+
383
+ ## Performance and Limitations
384
+
385
+ 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.
386
+
387
+ 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.
388
+
389
+ 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).
390
+
391
+ 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.
392
+
393
+
394
+ ## Broader Implications
395
+
396
+ 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.
397
+
398
+ 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.
399
+
400
+
401
+ ### BibTeX entry and citation info
402
+ ```bibtex
403
+ @misc{radford2022whisper,
404
+ doi = {10.48550/ARXIV.2212.04356},
405
+ url = {https://arxiv.org/abs/2212.04356},
406
+ author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
407
+ title = {Robust Speech Recognition via Large-Scale Weak Supervision},
408
+ publisher = {arXiv},
409
+ year = {2022},
410
+ copyright = {arXiv.org perpetual, non-exclusive license}
411
+ }
412
+ ```