ylacombe HF staff commited on
Commit
7a516fa
1 Parent(s): 0631025

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +436 -103
README.md CHANGED
@@ -1,199 +1,532 @@
1
  ---
2
- library_name: transformers
3
- tags: []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
 
 
 
9
 
 
 
10
 
 
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
29
 
30
- <!-- Provide the basic links for the model. -->
 
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
 
40
- ### Direct Use
 
 
 
 
 
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
43
 
44
- [More Information Needed]
 
 
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
 
49
 
50
- [More Information Needed]
51
 
52
- ### Out-of-Scope Use
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
55
 
56
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
57
 
58
- ## Bias, Risks, and Limitations
 
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
 
61
 
62
- [More Information Needed]
 
 
63
 
64
- ### Recommendations
 
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
 
 
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
 
70
- ## How to Get Started with the Model
 
 
 
71
 
72
- Use the code below to get started with the model.
73
 
74
- [More Information Needed]
 
 
 
75
 
76
- ## Training Details
 
77
 
78
- ### Training Data
 
 
 
79
 
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
 
82
- [More Information Needed]
83
 
84
- ### Training Procedure
 
 
 
85
 
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
 
88
- #### Preprocessing [optional]
 
89
 
90
- [More Information Needed]
91
 
 
 
 
 
92
 
93
- #### Training Hyperparameters
94
 
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
 
 
96
 
97
- #### Speeds, Sizes, Times [optional]
 
 
 
 
 
 
 
 
98
 
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
 
 
 
 
 
 
 
 
100
 
101
- [More Information Needed]
 
102
 
103
- ## Evaluation
 
104
 
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
 
107
- ### Testing Data, Factors & Metrics
108
 
109
- #### Testing Data
 
110
 
111
- <!-- This should link to a Dataset Card if possible. -->
112
 
113
- [More Information Needed]
 
 
 
114
 
115
- #### Factors
 
 
116
 
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
 
118
 
119
- [More Information Needed]
 
 
120
 
121
- #### Metrics
 
 
 
122
 
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
 
125
- [More Information Needed]
 
126
 
127
- ### Results
128
 
129
- [More Information Needed]
 
 
 
130
 
131
- #### Summary
132
 
 
 
 
 
 
 
 
 
 
 
133
 
 
 
134
 
135
- ## Model Examination [optional]
 
 
136
 
137
- <!-- Relevant interpretability work for the model goes here -->
138
 
139
- [More Information Needed]
 
140
 
141
- ## Environmental Impact
142
 
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
 
 
 
 
 
144
 
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
 
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
 
153
- ## Technical Specifications [optional]
154
 
155
- ### Model Architecture and Objective
 
 
156
 
157
- [More Information Needed]
 
 
 
158
 
159
- ### Compute Infrastructure
160
 
161
- [More Information Needed]
 
 
 
 
 
 
 
162
 
163
- #### Hardware
 
164
 
165
- [More Information Needed]
 
 
 
166
 
167
- #### Software
 
 
168
 
169
- [More Information Needed]
 
170
 
171
- ## Citation [optional]
172
 
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
174
 
175
- **BibTeX:**
 
 
176
 
177
- [More Information Needed]
178
 
179
- **APA:**
 
 
180
 
181
- [More Information Needed]
182
 
183
- ## Glossary [optional]
 
 
184
 
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
186
 
187
- [More Information Needed]
 
188
 
189
- ## More Information [optional]
 
190
 
191
- [More Information Needed]
 
192
 
193
- ## Model Card Authors [optional]
 
 
194
 
195
- [More Information Needed]
196
 
197
- ## Model Card Contact
198
 
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 state-of-the-art model for automatic speech recognition (ASR) and speech translation, proposed in the paper
118
+ [Robust Speech Recognition via Large-Scale Weak Supervision](https://huggingface.co/papers/2212.04356) by Alec Radford
119
+ et al. from OpenAI. Trained on >5M hours of labeled data, Whisper demonstrates a strong ability to generalise to many
120
+ datasets and domains in a zero-shot setting.
121
 
122
+ Whisper large-v3-turbo is a distilled version of [Whisper large-v3](https://huggingface.co/openai/whisper-large-v3). In other words, it's the exact same model, except that the number of decoding layers have reduced from 32 to 4.
123
+ As a result, the model is way faster, at the expense of a minor quality degradation.
124
 
125
+ **Disclaimer**: Content for this model card has partly been written by the 🤗 Hugging Face team, and partly copied and
126
+ pasted from the original model card.
127
 
128
+ ## Usage
129
 
130
+ Whisper large-v3-turbo is supported in Hugging Face 🤗 Transformers. To run the model, first install the Transformers
131
+ library. For this example, we'll also install 🤗 Datasets to load toy audio dataset from the Hugging Face Hub, and
132
+ 🤗 Accelerate to reduce the model loading time:
133
 
134
+ ```bash
135
+ pip install --upgrade pip
136
+ pip install --upgrade transformers datasets[audio] accelerate
137
+ ```
138
 
139
+ The model can be used with the [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
140
+ class to transcribe audios of arbitrary length:
141
 
142
+ ```python
143
+ import torch
144
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
145
+ from datasets import load_dataset
 
 
 
146
 
 
147
 
148
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
149
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
150
 
151
+ model_id = "openai/whisper-large-v3-turbo"
 
 
152
 
153
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
154
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
155
+ )
156
+ model.to(device)
157
 
158
+ processor = AutoProcessor.from_pretrained(model_id)
159
 
160
+ pipe = pipeline(
161
+ "automatic-speech-recognition",
162
+ model=model,
163
+ tokenizer=processor.tokenizer,
164
+ feature_extractor=processor.feature_extractor,
165
+ torch_dtype=torch_dtype,
166
+ device=device,
167
+ )
168
 
169
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
170
+ sample = dataset[0]["audio"]
171
 
172
+ result = pipe(sample)
173
+ print(result["text"])
174
+ ```
175
 
176
+ To transcribe a local audio file, simply pass the path to your audio file when you call the pipeline:
177
 
178
+ ```python
179
+ result = pipe("audio.mp3")
180
+ ```
181
 
182
+ Multiple audio files can be transcribed in parallel by specifying them as a list and setting the `batch_size` parameter:
183
 
184
+ ```python
185
+ result = pipe(["audio_1.mp3", "audio_2.mp3"], batch_size=2)
186
+ ```
187
 
188
+ Transformers is compatible with all Whisper decoding strategies, such as temperature fallback and condition on previous
189
+ tokens. The following example demonstrates how to enable these heuristics:
190
 
191
+ ```python
192
+ generate_kwargs = {
193
+ "max_new_tokens": 448,
194
+ "num_beams": 1,
195
+ "condition_on_prev_tokens": False,
196
+ "compression_ratio_threshold": 1.35, # zlib compression ratio threshold (in token space)
197
+ "temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
198
+ "logprob_threshold": -1.0,
199
+ "no_speech_threshold": 0.6,
200
+ "return_timestamps": True,
201
+ }
202
 
203
+ result = pipe(sample, generate_kwargs=generate_kwargs)
204
+ ```
205
 
206
+ Whisper predicts the language of the source audio automatically. If the source audio language is known *a-priori*, it
207
+ can be passed as an argument to the pipeline:
208
 
209
+ ```python
210
+ result = pipe(sample, generate_kwargs={"language": "english"})
211
+ ```
212
 
213
+ By default, Whisper performs the task of *speech transcription*, where the source audio language is the same as the target
214
+ text language. To perform *speech translation*, where the target text is in English, set the task to `"translate"`:
215
 
216
+ ```python
217
+ result = pipe(sample, generate_kwargs={"task": "translate"})
218
+ ```
219
 
220
+ Finally, the model can be made to predict timestamps. For sentence-level timestamps, pass the `return_timestamps` argument:
221
 
222
+ ```python
223
+ result = pipe(sample, return_timestamps=True)
224
+ print(result["chunks"])
225
+ ```
226
 
227
+ And for word-level timestamps:
228
 
229
+ ```python
230
+ result = pipe(sample, return_timestamps="word")
231
+ print(result["chunks"])
232
+ ```
233
 
234
+ The above arguments can be used in isolation or in combination. For example, to perform the task of speech transcription
235
+ where the source audio is in French, and we want to return sentence-level timestamps, the following can be used:
236
 
237
+ ```python
238
+ result = pipe(sample, return_timestamps=True, generate_kwargs={"language": "french", "task": "translate"})
239
+ print(result["chunks"])
240
+ ```
241
 
242
+ <details>
243
 
244
+ <summary> For more control over the generation parameters, use the model + processor API directly: </summary>
245
 
246
+ ```python
247
+ import torch
248
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
249
+ from datasets import Audio, load_dataset
250
 
 
251
 
252
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
253
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
254
 
255
+ model_id = "openai/whisper-large-v3-turbo"
256
 
257
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
258
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
259
+ )
260
+ model.to(device)
261
 
262
+ processor = AutoProcessor.from_pretrained(model_id)
263
 
264
+ dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
265
+ dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
266
+ sample = dataset[0]["audio"]
267
 
268
+ inputs = processor(
269
+ sample["array"],
270
+ sampling_rate=sample["sampling_rate"],
271
+ return_tensors="pt",
272
+ truncation=False,
273
+ padding="longest",
274
+ return_attention_mask=True,
275
+ )
276
+ inputs = inputs.to(device, dtype=torch_dtype)
277
 
278
+ gen_kwargs = {
279
+ "max_new_tokens": 448,
280
+ "num_beams": 1,
281
+ "condition_on_prev_tokens": False,
282
+ "compression_ratio_threshold": 1.35, # zlib compression ratio threshold (in token space)
283
+ "temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
284
+ "logprob_threshold": -1.0,
285
+ "no_speech_threshold": 0.6,
286
+ "return_timestamps": True,
287
+ }
288
 
289
+ pred_ids = model.generate(**inputs, **gen_kwargs)
290
+ pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=False)
291
 
292
+ print(pred_text)
293
+ ```
294
 
295
+ </details>
296
 
297
+ ## Additional Speed & Memory Improvements
298
 
299
+ You can apply additional speed and memory improvements to Whisper to further reduce the inference speed and VRAM
300
+ requirements.
301
 
302
+ ### Chunked Long-Form
303
 
304
+ Whisper has a receptive field of 30-seconds. To transcribe audios longer than this, one of two long-form algorithms are
305
+ required:
306
+ 1. **Sequential:** uses a "sliding window" for buffered inference, transcribing 30-second slices one after the other
307
+ 2. **Chunked:** splits long audio files into shorter ones (with a small overlap between segments), transcribes each segment independently, and stitches the resulting transcriptions at the boundaries
308
 
309
+ The sequential long-form algorithm should be used in either of the following scenarios:
310
+ 1. Transcription accuracy is the most important factor, and speed is less of a consideration
311
+ 2. You are transcribing **batches** of long audio files, in which case the latency of sequential is comparable to chunked, while being up to 0.5% WER more accurate
312
 
313
+ Conversely, the chunked algorithm should be used when:
314
+ 1. Transcription speed is the most important factor
315
+ 2. You are transcribing a **single** long audio file
316
 
317
+ By default, Transformers uses the sequential algorithm. To enable the chunked algorithm, pass the `chunk_length_s`
318
+ parameter to the `pipeline`. For large-v3, a chunk length of 30-seconds is optimal. To activate batching over long
319
+ audio files, pass the argument `batch_size`:
320
 
321
+ ```python
322
+ import torch
323
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
324
+ from datasets import load_dataset
325
 
 
326
 
327
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
328
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
329
 
330
+ model_id = "openai/whisper-large-v3-turbo"
331
 
332
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
333
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
334
+ )
335
+ model.to(device)
336
 
337
+ processor = AutoProcessor.from_pretrained(model_id)
338
 
339
+ pipe = pipeline(
340
+ "automatic-speech-recognition",
341
+ model=model,
342
+ tokenizer=processor.tokenizer,
343
+ feature_extractor=processor.feature_extractor,
344
+ chunk_length_s=30,
345
+ batch_size=16, # batch size for inference - set based on your device
346
+ torch_dtype=torch_dtype,
347
+ device=device,
348
+ )
349
 
350
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
351
+ sample = dataset[0]["audio"]
352
 
353
+ result = pipe(sample)
354
+ print(result["text"])
355
+ ```
356
 
357
+ #### Torch compile
358
 
359
+ The Whisper forward pass is compatible with [`torch.compile`](https://pytorch.org/docs/stable/generated/torch.compile.html)
360
+ for 4.5x speed-ups.
361
 
362
+ **Note:** `torch.compile` is currently not compatible with the Chunked long-form algorithm or Flash Attention 2 ⚠️
363
 
364
+ ```python
365
+ import torch
366
+ from torch.nn.attention import SDPBackend, sdpa_kernel
367
+ from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
368
+ from datasets import load_dataset
369
+ from tqdm import tqdm
370
 
371
+ torch.set_float32_matmul_precision("high")
372
 
373
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
374
+ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
 
 
 
375
 
376
+ model_id = "openai/whisper-large-v3-turbo"
377
 
378
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(
379
+ model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
380
+ ).to(device)
381
 
382
+ # Enable static cache and compile the forward pass
383
+ model.generation_config.cache_implementation = "static"
384
+ model.generation_config.max_new_tokens = 256
385
+ model.forward = torch.compile(model.forward, mode="reduce-overhead", fullgraph=True)
386
 
387
+ processor = AutoProcessor.from_pretrained(model_id)
388
 
389
+ pipe = pipeline(
390
+ "automatic-speech-recognition",
391
+ model=model,
392
+ tokenizer=processor.tokenizer,
393
+ feature_extractor=processor.feature_extractor,
394
+ torch_dtype=torch_dtype,
395
+ device=device,
396
+ )
397
 
398
+ dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
399
+ sample = dataset[0]["audio"]
400
 
401
+ # 2 warmup steps
402
+ for _ in tqdm(range(2), desc="Warm-up step"):
403
+ with sdpa_kernel(SDPBackend.MATH):
404
+ result = pipe(sample.copy(), generate_kwargs={"min_new_tokens": 256, "max_new_tokens": 256})
405
 
406
+ # fast run
407
+ with sdpa_kernel(SDPBackend.MATH):
408
+ result = pipe(sample.copy())
409
 
410
+ print(result["text"])
411
+ ```
412
 
413
+ #### Flash Attention 2
414
 
415
+ We recommend using [Flash-Attention 2](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#flashattention-2) if your GPU supports it and you are not using [torch.compile](#torch-compile).
416
+ To do so, first install [Flash Attention](https://github.com/Dao-AILab/flash-attention):
417
 
418
+ ```
419
+ pip install flash-attn --no-build-isolation
420
+ ```
421
 
422
+ Then pass `attn_implementation="flash_attention_2"` to `from_pretrained`:
423
 
424
+ ```python
425
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, attn_implementation="flash_attention_2")
426
+ ```
427
 
428
+ #### Torch Scale-Product-Attention (SDPA)
429
 
430
+ If your GPU does not support Flash Attention, we recommend making use of PyTorch [scaled dot-product attention (SDPA)](https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html).
431
+ This attention implementation is activated **by default** for PyTorch versions 2.1.1 or greater. To check
432
+ whether you have a compatible PyTorch version, run the following Python code snippet:
433
 
434
+ ```python
435
+ from transformers.utils import is_torch_sdpa_available
436
 
437
+ print(is_torch_sdpa_available())
438
+ ```
439
 
440
+ If the above returns `True`, you have a valid version of PyTorch installed and SDPA is activated by default. If it
441
+ returns `False`, you need to upgrade your PyTorch version according to the [official instructions](https://pytorch.org/get-started/locally/)
442
 
443
+ Once a valid PyTorch version is installed, SDPA is activated by default. It can also be set explicitly by specifying
444
+ `attn_implementation="sdpa"` as follows:
445
 
446
+ ```python
447
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, attn_implementation="sdpa")
448
+ ```
449
 
450
+ For more information about how to use the SDPA refer to the [Transformers SDPA documentation](https://huggingface.co/docs/transformers/en/perf_infer_gpu_one#pytorch-scaled-dot-product-attention).
451
 
 
452
 
453
+ ## Model details
454
+
455
+ Whisper is a Transformer based encoder-decoder model, also referred to as a _sequence-to-sequence_ model. There are two
456
+ flavours of Whisper model: English-only and multilingual. The English-only models were trained on the task of English
457
+ speech recognition. The multilingual models were trained simultaneously on multilingual speech recognition and speech
458
+ translation. For speech recognition, the model predicts transcriptions in the *same* language as the audio. For speech
459
+ translation, the model predicts transcriptions to a *different* language to the audio.
460
+
461
+ Whisper checkpoints come in five configurations of varying model sizes. The smallest four are available as English-only
462
+ and multilingual. The largest checkpoints are multilingual only. All ten of the pre-trained checkpoints
463
+ are available on the [Hugging Face Hub](https://huggingface.co/models?search=openai/whisper). The
464
+ checkpoints are summarised in the following table with links to the models on the Hub:
465
+
466
+ | Size | Parameters | English-only | Multilingual |
467
+ |----------|------------|------------------------------------------------------|-----------------------------------------------------|
468
+ | tiny | 39 M | [✓](https://huggingface.co/openai/whisper-tiny.en) | [✓](https://huggingface.co/openai/whisper-tiny) |
469
+ | base | 74 M | [✓](https://huggingface.co/openai/whisper-base.en) | [✓](https://huggingface.co/openai/whisper-base) |
470
+ | small | 244 M | [✓](https://huggingface.co/openai/whisper-small.en) | [✓](https://huggingface.co/openai/whisper-small) |
471
+ | medium | 769 M | [✓](https://huggingface.co/openai/whisper-medium.en) | [✓](https://huggingface.co/openai/whisper-medium) |
472
+ | large | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large) |
473
+ | large-v2 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large-v2) |
474
+ | large-v3 | 1550 M | x | [✓](https://huggingface.co/openai/whisper-large-v3) |
475
+ | large-v3-turbo | 809 M | x | [✓](https://huggingface.co/openai/whisper-large-v3-turbo) |
476
+
477
+
478
+ ## Fine-Tuning
479
+
480
+ The pre-trained Whisper model demonstrates a strong ability to generalise to different datasets and domains. However,
481
+ its predictive capabilities can be improved further for certain languages and tasks through *fine-tuning*. The blog
482
+ post [Fine-Tune Whisper with 🤗 Transformers](https://huggingface.co/blog/fine-tune-whisper) provides a step-by-step
483
+ guide to fine-tuning the Whisper model with as little as 5 hours of labelled data.
484
+
485
+ ### Evaluated Use
486
+
487
+ 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.
488
+
489
+ 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.
490
+
491
+ 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.
492
+
493
+
494
+ ## Training Data
495
+
496
+ TODO
497
+
498
+ The large-v3 checkpoint is trained on 1 million hours of weakly labeled audio and 4 million hours of pseudo-labeled audio collected using Whisper large-v2.
499
+
500
+ 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.
501
+
502
+
503
+ ## Performance and Limitations
504
+
505
+ 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.
506
+
507
+ 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.
508
+
509
+ 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).
510
+
511
+ 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.
512
+
513
+
514
+ ## Broader Implications
515
+
516
+ 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.
517
+
518
+ 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.
519
+
520
+
521
+ ### BibTeX entry and citation info
522
+ ```bibtex
523
+ @misc{radford2022whisper,
524
+ doi = {10.48550/ARXIV.2212.04356},
525
+ url = {https://arxiv.org/abs/2212.04356},
526
+ author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
527
+ title = {Robust Speech Recognition via Large-Scale Weak Supervision},
528
+ publisher = {arXiv},
529
+ year = {2022},
530
+ copyright = {arXiv.org perpetual, non-exclusive license}
531
+ }
532
+ ```