reach-vb HF staff commited on
Commit
654f042
1 Parent(s): ba4b144

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +404 -0
README.md ADDED
@@ -0,0 +1,404 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 `Whisper-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 680k hours of labelled speech data annotated using large-scale weak supervision.
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
+ To transcribe audio samples, the model has to be used alongside a [`WhisperProcessor`](https://huggingface.co/docs/transformers/model_doc/whisper#transformers.WhisperProcessor).
167
+
168
+ The `WhisperProcessor` is used to:
169
+ 1. Pre-process the audio inputs (converting them to log-Mel spectrograms for the model)
170
+ 2. Post-process the model outputs (converting them from tokens to text)
171
+
172
+ The model is informed of which task to perform (transcription or translation) by passing the appropriate "context tokens". These context tokens
173
+ are a sequence of tokens that are given to the decoder at the start of the decoding process, and take the following order:
174
+ 1. The transcription always starts with the `<|startoftranscript|>` token
175
+ 2. The second token is the language token (e.g. `<|en|>` for English)
176
+ 3. The third token is the "task token". It can take one of two values: `<|transcribe|>` for speech recognition or `<|translate|>` for speech translation
177
+ 4. In addition, a `<|notimestamps|>` token is added if the model should not include timestamp prediction
178
+
179
+ Thus, a typical sequence of context tokens might look as follows:
180
+ ```
181
+ <|startoftranscript|> <|en|> <|transcribe|> <|notimestamps|>
182
+ ```
183
+ Which tells the model to decode in English, under the task of speech recognition, and not to predict timestamps.
184
+
185
+ These tokens can either be forced or un-forced. If they are forced, the model is made to predict each token at
186
+ each position. This allows one to control the output language and task for the Whisper model. If they are un-forced,
187
+ the Whisper model will automatically predict the output langauge and task itself.
188
+
189
+ The context tokens can be set accordingly:
190
+
191
+ ```python
192
+ model.config.forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="english", task="transcribe")
193
+ ```
194
+
195
+ Which forces the model to predict in English under the task of speech recognition.
196
+
197
+ ## Transcription
198
+
199
+ ### English to English
200
+ In this example, the context tokens are 'unforced', meaning the model automatically predicts the output language
201
+ (English) and task (transcribe).
202
+
203
+ ```python
204
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
205
+ >>> from datasets import load_dataset
206
+
207
+ >>> # load model and processor
208
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
209
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
210
+ >>> model.config.forced_decoder_ids = None
211
+
212
+ >>> # load dummy dataset and read audio files
213
+ >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
214
+ >>> sample = ds[0]["audio"]
215
+ >>> input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
216
+
217
+ >>> # generate token ids
218
+ >>> predicted_ids = model.generate(input_features)
219
+ >>> # decode token ids to text
220
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=False)
221
+ ['<|startoftranscript|><|en|><|transcribe|><|notimestamps|> Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.<|endoftext|>']
222
+
223
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
224
+ [' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.']
225
+ ```
226
+ The context tokens can be removed from the start of the transcription by setting `skip_special_tokens=True`.
227
+
228
+ ### French to French
229
+ The following example demonstrates French to French transcription by setting the decoder ids appropriately.
230
+
231
+ ```python
232
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
233
+ >>> from datasets import Audio, load_dataset
234
+
235
+ >>> # load model and processor
236
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
237
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
238
+ >>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="transcribe")
239
+
240
+ >>> # load streaming dataset and read first audio sample
241
+ >>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
242
+ >>> ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
243
+ >>> input_speech = next(iter(ds))["audio"]
244
+ >>> input_features = processor(input_speech["array"], sampling_rate=input_speech["sampling_rate"], return_tensors="pt").input_features
245
+
246
+ >>> # generate token ids
247
+ >>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
248
+ >>> # decode token ids to text
249
+ >>> transcription = processor.batch_decode(predicted_ids)
250
+ ['<|startoftranscript|><|fr|><|transcribe|><|notimestamps|> Un vrai travail intéressant va enfin être mené sur ce sujet.<|endoftext|>']
251
+
252
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
253
+ [' Un vrai travail intéressant va enfin être mené sur ce sujet.']
254
+ ```
255
+
256
+ ## Translation
257
+ Setting the task to "translate" forces the Whisper model to perform speech translation.
258
+
259
+ ### French to English
260
+
261
+ ```python
262
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
263
+ >>> from datasets import Audio, load_dataset
264
+
265
+ >>> # load model and processor
266
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
267
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
268
+ >>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="translate")
269
+
270
+ >>> # load streaming dataset and read first audio sample
271
+ >>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
272
+ >>> ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
273
+ >>> input_speech = next(iter(ds))["audio"]
274
+ >>> input_features = processor(input_speech["array"], sampling_rate=input_speech["sampling_rate"], return_tensors="pt").input_features
275
+
276
+ >>> # generate token ids
277
+ >>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
278
+ >>> # decode token ids to text
279
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
280
+ [' A very interesting work, we will finally be given on this subject.']
281
+ ```
282
+
283
+ ## Evaluation
284
+
285
+ This code snippet shows how to evaluate Whisper Large on [LibriSpeech test-clean](https://huggingface.co/datasets/librispeech_asr):
286
+
287
+ ```python
288
+ >>> from datasets import load_dataset
289
+ >>> from transformers import WhisperForConditionalGeneration, WhisperProcessor
290
+ >>> import torch
291
+ >>> from evaluate import load
292
+
293
+ >>> librispeech_test_clean = load_dataset("librispeech_asr", "clean", split="test")
294
+
295
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
296
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2").to("cuda")
297
+
298
+ >>> def map_to_pred(batch):
299
+ >>> audio = batch["audio"]
300
+ >>> input_features = processor(audio["array"], sampling_rate=audio["sampling_rate"], return_tensors="pt").input_features
301
+ >>> batch["reference"] = processor.tokenizer._normalize(batch['text'])
302
+ >>>
303
+ >>> with torch.no_grad():
304
+ >>> predicted_ids = model.generate(input_features.to("cuda"))[0]
305
+ >>> transcription = processor.decode(predicted_ids)
306
+ >>> batch["prediction"] = processor.tokenizer._normalize(transcription)
307
+ >>> return batch
308
+
309
+ >>> result = librispeech_test_clean.map(map_to_pred)
310
+
311
+ >>> wer = load("wer")
312
+ >>> print(100 * wer.compute(references=result["reference"], predictions=result["prediction"]))
313
+ 3.0003583080317572
314
+ ```
315
+
316
+ ## Long-Form Transcription
317
+
318
+ The Whisper model is intrinsically designed to work on audio samples of up to 30s in duration. However, by using a chunking
319
+ algorithm, it can be used to transcribe audio samples of up to arbitrary length. This is possible through Transformers
320
+ [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
321
+ method. Chunking is enabled by setting `chunk_length_s=30` when instantiating the pipeline. With chunking enabled, the pipeline
322
+ can be run with batched inference. It can also be extended to predict sequence level timestamps by passing `return_timestamps=True`:
323
+
324
+ ```python
325
+ >>> import torch
326
+ >>> from transformers import pipeline
327
+ >>> from datasets import load_dataset
328
+
329
+ >>> device = "cuda:0" if torch.cuda.is_available() else "cpu"
330
+
331
+ >>> pipe = pipeline(
332
+ >>> "automatic-speech-recognition",
333
+ >>> model="openai/whisper-large-v2",
334
+ >>> chunk_length_s=30,
335
+ >>> device=device,
336
+ >>> )
337
+
338
+ >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
339
+ >>> sample = ds[0]["audio"]
340
+
341
+ >>> prediction = pipe(sample.copy(), batch_size=8)["text"]
342
+ " Mr. Quilter is the apostle of the middle classes, and we are glad to welcome his gospel."
343
+
344
+ >>> # we can also return timestamps for the predictions
345
+ >>> prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
346
+ [{'text': ' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.',
347
+ 'timestamp': (0.0, 5.44)}]
348
+ ```
349
+
350
+ Refer to the blog post [ASR Chunking](https://huggingface.co/blog/asr-chunking) for more details on the chunking algorithm.
351
+
352
+ ## Fine-Tuning
353
+
354
+ The pre-trained Whisper model demonstrates a strong ability to generalise to different datasets and domains. However,
355
+ its predictive capabilities can be improved further for certain languages and tasks through *fine-tuning*. The blog
356
+ post [Fine-Tune Whisper with 🤗 Transformers](https://huggingface.co/blog/fine-tune-whisper) provides a step-by-step
357
+ guide to fine-tuning the Whisper model with as little as 5 hours of labelled data.
358
+
359
+ ### Evaluated Use
360
+
361
+ 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.
362
+
363
+ 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.
364
+
365
+ 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.
366
+
367
+
368
+ ## Training Data
369
+
370
+ 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.
371
+
372
+ 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.
373
+
374
+
375
+ ## Performance and Limitations
376
+
377
+ 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.
378
+
379
+ 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.
380
+
381
+ 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).
382
+
383
+ 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.
384
+
385
+
386
+ ## Broader Implications
387
+
388
+ 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.
389
+
390
+ 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.
391
+
392
+
393
+ ### BibTeX entry and citation info
394
+ ```bibtex
395
+ @misc{radford2022whisper,
396
+ doi = {10.48550/ARXIV.2212.04356},
397
+ url = {https://arxiv.org/abs/2212.04356},
398
+ author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
399
+ title = {Robust Speech Recognition via Large-Scale Weak Supervision},
400
+ publisher = {arXiv},
401
+ year = {2022},
402
+ copyright = {arXiv.org perpetual, non-exclusive license}
403
+ }
404
+ ```