ArthurZ HF staff commited on
Commit
5fc9927
1 Parent(s): eb27843

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +299 -0
README.md ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ - iw
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
+ - speech
104
+ - audio
105
+ - automatic-speech-recognition
106
+ license: apache-2.0
107
+ ---
108
+
109
+ # Whisper
110
+
111
+ [OpenAI's Whisper](https://openai.com/blog/whisper/)
112
+
113
+ The Whisper model was proposed in [Robust Speech Recognition via Large-Scale Weak Supervision](https://cdn.openai.com/papers/whisper.pdf) by Alec Radford, Jong Wook Kim, Tao Xu, Greg Brockman, Christine McLeavey, Ilya Sutskever.
114
+
115
+ **Disclaimer**: The team releasing Whisper wrote an official model card, which is available [here](https://github.com/openai/whisper/blob/main/model-card.md).
116
+ Content from **this** model card has been written by the Hugging Face team.
117
+
118
+
119
+ ## Intro
120
+
121
+ The first paragraphs of the abstract read as follows :
122
+
123
+ > We study the capabilities of speech processing systems trained simply to predict large amounts of transcripts of audio on the internet. When scaled to 680,000 hours of multilingual and multitask supervision, the resulting models generalize well to standard benchmarks and are often competitive with prior fully supervised results but in a zeroshot transfer setting without the need for any finetuning.
124
+ > When compared to humans, the models approach their accuracy and robustness. We are releasing models and inference code to serve as a foundation for further work on robust speech processing.
125
+
126
+ The original code repository can be found [here](https://github.com/openai/whisper).
127
+
128
+ ## Model description
129
+
130
+ Whisper is an auto-regressive automatic speech recognition encoder-decoder model that was trained on 680 000 hours of 16kHz sampled multilingual audio. It was fully trained in a supervised manner, with multiple tasks :
131
+
132
+ - English transcription
133
+ - Any-to-English speech translation
134
+ - Non-English transcription
135
+ - No speech prediction
136
+
137
+ To each task corresponds a sequence of tokens that are given to the decoder as *context tokens*. The beginning of a transcription always starts with `<|startoftranscript|>` which is why the `decoder_start_token` is always set to `tokenizer.encode("<|startoftranscript|>")`. The following token should be the language token, which is automatically detected in the original code. Finally, the task is define using either `<|transcribe|>` or `<|translate|>`. In addition, a `<|notimestamps|>` token is added if the task does not include timestamp prediction.
138
+
139
+
140
+ # Usage
141
+
142
+ To transcribe or translate audio files, the model has to be used along a `WhisperFeatureExtractor`.
143
+
144
+
145
+ ## Transcription
146
+ In the following example, the english only model is used. We set the `decoder_input_ids` accordingly.
147
+
148
+
149
+ ### English to english
150
+ The "<|en|>" token is used to specify that the speech is in english and should be transcribed to english
151
+
152
+ ```python
153
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
154
+ >>> from datasets import load_dataset
155
+ >>> import torch
156
+
157
+ >>> # load model and processor
158
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large")
159
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
160
+
161
+ >>> decoder_input_ids = processor.tokenizer.encode("<|startoftranscript|><|en|><|transcribe|><|notimestamps|>", return_tensors="pt")
162
+
163
+ >>> # load dummy dataset and read soundfiles
164
+ >>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
165
+
166
+ >>> # tokenize
167
+ >>> input_features = processor(ds[0]["audio"]["array"], return_tensors="pt").input_features
168
+ >>> # retrieve logits
169
+ >>> logits = model(input_features, decoder_input_ids).logits
170
+ >>> # take argmax and decode
171
+ >>> predicted_ids = torch.argmax(logits, dim=-1)
172
+ >>> transcription = processor.batch_decode(predicted_ids)
173
+ ['<|en|><|transcribe|><|notimestamps|> Mr']
174
+ ```
175
+
176
+ ### French to French
177
+ In order to obtain the full transcription, the `generate()` function is used. The following example demonstrates a french to french
178
+ transcription.
179
+
180
+ ```python
181
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
182
+ >>> from datasets import load_dataset
183
+ >>> import torch
184
+
185
+ >>> # load model and processor
186
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large")
187
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
188
+
189
+ >>> decoder_input_ids = processor.tokenizer.encode("<|startoftranscript|><|fr|><|transcribe|><|notimestamps|>", return_tensors="pt")
190
+
191
+ >>> # load dummy dataset and read soundfiles
192
+ >>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
193
+ >>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=16_000))
194
+ >>> input_speech = next(iter(ds))["audio"]["array"]
195
+ >>> # tokenize
196
+ >>> input_features = processor(input_speech, return_tensors="pt").input_features
197
+ >>> predicted_ids = model.generate(input_features, decoder_input_ids = decoder_input_ids, max_lenght = 460_000)
198
+ >>> transcription = processor.batch_decode(predicted_ids)
199
+ ['<|startoftranscript|><|fr|><|transcribe|><|notimestamps|> Un vrai travail intéressant va enfin être mené sur ce sujet.<|endoftext|>']
200
+
201
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens = True)
202
+ [' Un vrai travail intéressant va enfin être mené sur ce sujet.']
203
+ ```
204
+
205
+ ## Translation
206
+ The "<|translate|>" is used as the first decoder input token to specify the transcription task.
207
+
208
+ ### French to English
209
+
210
+ ```python
211
+ >>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
212
+ >>> from datasets import load_dataset
213
+ >>> import torch
214
+
215
+ >>> # load model and processor
216
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large")
217
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
218
+
219
+ >>> decoder_input_ids = processor.tokenizer.encode("<|startoftranscript|><|fr|><|translate|><|notimestamps|>", return_tensors="pt")
220
+
221
+ >>> # load dummy dataset and read soundfiles
222
+ >>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
223
+ >>> ds = ds.cast_column("audio", datasets.Audio(sampling_rate=16_000))
224
+ >>> input_speech = next(iter(ds))["audio"]["array"]
225
+ >>> # tokenize
226
+ >>> input_features = processor(input_speech, return_tensors="pt").input_features
227
+ >>> predicted_ids = model.generate(input_features, decoder_input_ids = decoder_input_ids, max_lenght = 460_000)
228
+ >>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens = True)
229
+ [' A real interesting work will be done on this subject.']
230
+ ```
231
+
232
+
233
+
234
+ ## Evaluation
235
+
236
+ This code snippet shows how to evaluate **openai/whisper-large** on LibriSpeech's "clean" and "other" test data.
237
+
238
+ ```python
239
+ >>> from datasets import load_dataset
240
+ >>> from transformers import WhisperForConditionalGeneration, WhisperProcessor
241
+ >>> import soundfile as sf
242
+ >>> import torch
243
+ >>> from jiwer import wer
244
+
245
+
246
+ >>> librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
247
+
248
+ >>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large").to("cuda")
249
+ >>> processor = WhisperProcessor.from_pretrained("openai/whisper-large")
250
+
251
+ >>> def map_to_pred(batch):
252
+ >>> input_features = processor(batch["audio"]["array"], return_tensors="pt").input_features
253
+
254
+ >>> with torch.no_grad():
255
+ >>> logits = model(input_features.to("cuda")).logits
256
+
257
+ >>> predicted_ids = torch.argmax(logits, dim=-1)
258
+ >>> transcription = processor.batch_decode(predicted_ids, normalize = True)
259
+ >>> batch['text'] = processor.tokenizer._normalize(batch['text'])
260
+ >>> batch["transcription"] = transcription
261
+ >>> return batch
262
+
263
+ >>> result = librispeech_eval.map(map_to_pred, batched=True, batch_size=1, remove_columns=["speech"])
264
+
265
+ >>> print("WER:", wer(result["text"], result["transcription"]))
266
+ 0.030003583080317572
267
+ ```
268
+
269
+
270
+
271
+ ## Training Data
272
+
273
+ Out of the 680 000 hours of training data, 65% are English language audio and their corresponding transcript. 18% of the remaining data is non-English audio and their corresponding translated transcript in english, while the remaining 17% are non english audio with their non english transcript. This non-English data represents 98 different languages.
274
+
275
+ 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.
276
+
277
+ ## Performance and Limitations
278
+
279
+ Whisper shows strong 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. The results are all highly correlated with the available training data in the studied language.
280
+
281
+ A common model hallucination (a predicted text that is not present in the audio) includes notably classic ending of youtube video : "Thank you for listening. Please subscribe to the channel".
282
+
283
+
284
+ The authors also mention that :
285
+
286
+ > 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.
287
+
288
+
289
+
290
+ ### BibTeX entry and citation info
291
+
292
+ ```bibtex
293
+ @misc{zhang2022opt,
294
+ title={Robust Speech Recognition via Large-Scale Weak Supervision.},
295
+ author={Alec Radford, Jong Wook Kim, Tao Xu, Greg Brockman, Christine McLeavey, Ilya Sutskever},
296
+ year={2022},
297
+ url={https://cdn.openai.com/papers/whisper.pdf},
298
+ }
299
+ ```