jianboy commited on
Commit
5e064a2
1 Parent(s): 03d99d0

Update README.md

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