Update README.md
Browse files
README.md
CHANGED
|
@@ -1,566 +1,118 @@
|
|
| 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 |
-
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 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 |
-
|
| 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 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
| 153 |
|
| 154 |
-
|
| 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 |
-
##
|
| 165 |
|
| 166 |
-
|
| 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 --
|
| 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 |
-
chunk_length_s=30,
|
| 205 |
-
batch_size=16,
|
| 206 |
-
return_timestamps=True,
|
| 207 |
-
torch_dtype=torch_dtype,
|
| 208 |
-
device=device,
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
|
| 212 |
-
sample = dataset[0]["audio"]
|
| 213 |
-
|
| 214 |
-
result = pipe(sample)
|
| 215 |
-
print(result["text"])
|
| 216 |
-
```
|
| 217 |
-
|
| 218 |
-
To transcribe a local audio file, simply pass the path to your audio file when you call the pipeline:
|
| 219 |
-
```diff
|
| 220 |
-
- result = pipe(sample)
|
| 221 |
-
+ result = pipe("audio.mp3")
|
| 222 |
-
```
|
| 223 |
-
|
| 224 |
-
Whisper predicts the language of the source audio automatically. If the source audio language is known *a-priori*, it
|
| 225 |
-
can be passed as an argument to the pipeline:
|
| 226 |
-
|
| 227 |
-
```python
|
| 228 |
-
result = pipe(sample, generate_kwargs={"language": "english"})
|
| 229 |
-
```
|
| 230 |
-
|
| 231 |
-
By default, Whisper performs the task of *speech transcription*, where the source audio language is the same as the target
|
| 232 |
-
text language. To perform *speech translation*, where the target text is in English, set the task to `"translate"`:
|
| 233 |
-
|
| 234 |
-
```python
|
| 235 |
-
result = pipe(sample, generate_kwargs={"task": "translate"})
|
| 236 |
-
```
|
| 237 |
-
|
| 238 |
-
Finally, the model can be made to predict timestamps. For sentence-level timestamps, pass the `return_timestamps` argument:
|
| 239 |
-
|
| 240 |
-
```python
|
| 241 |
-
result = pipe(sample, return_timestamps=True)
|
| 242 |
-
print(result["chunks"])
|
| 243 |
-
```
|
| 244 |
-
|
| 245 |
-
And for word-level timestamps:
|
| 246 |
-
|
| 247 |
-
```python
|
| 248 |
-
result = pipe(sample, return_timestamps="word")
|
| 249 |
-
print(result["chunks"])
|
| 250 |
-
```
|
| 251 |
-
|
| 252 |
-
The above arguments can be used in isolation or in combination. For example, to perform the task of speech transcription
|
| 253 |
-
where the source audio is in French, and we want to return sentence-level timestamps, the following can be used:
|
| 254 |
-
|
| 255 |
-
```python
|
| 256 |
-
result = pipe(sample, return_timestamps=True, generate_kwargs={"language": "french", "task": "translate"})
|
| 257 |
-
print(result["chunks"])
|
| 258 |
-
```
|
| 259 |
-
|
| 260 |
-
<details>
|
| 261 |
-
|
| 262 |
-
<summary> For more control over the generation parameters, use the model + processor API directly: </summary>
|
| 263 |
-
|
| 264 |
-
Ad-hoc generation arguments can be passed to `model.generate`, including `num_beams` for beam-search, `return_timestamps`
|
| 265 |
-
for segment-level timestamps, and `prompt_ids` for prompting. See the [docstrings](https://huggingface.co/docs/transformers/en/model_doc/whisper#transformers.WhisperForConditionalGeneration.generate)
|
| 266 |
-
for more details.
|
| 267 |
-
|
| 268 |
-
```python
|
| 269 |
-
import torch
|
| 270 |
-
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
|
| 271 |
-
from datasets import Audio, load_dataset
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 275 |
-
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 276 |
-
|
| 277 |
-
model_id = "openai/whisper-large-v3"
|
| 278 |
-
|
| 279 |
-
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 280 |
-
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
| 281 |
-
)
|
| 282 |
-
model.to(device)
|
| 283 |
-
|
| 284 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 285 |
-
|
| 286 |
-
dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 287 |
-
dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
|
| 288 |
-
sample = dataset[0]["audio"]
|
| 289 |
-
|
| 290 |
-
input_features = processor(
|
| 291 |
-
sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
|
| 292 |
-
).input_features
|
| 293 |
-
|
| 294 |
-
input_features = input_features.to(device, dtype=torch_dtype)
|
| 295 |
-
|
| 296 |
-
gen_kwargs = {
|
| 297 |
-
"max_new_tokens": 128,
|
| 298 |
-
"num_beams": 1,
|
| 299 |
-
"return_timestamps": False,
|
| 300 |
-
}
|
| 301 |
-
|
| 302 |
-
pred_ids = model.generate(input_features, **gen_kwargs)
|
| 303 |
-
pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=gen_kwargs["return_timestamps"])
|
| 304 |
-
|
| 305 |
-
print(pred_text)
|
| 306 |
-
```
|
| 307 |
-
|
| 308 |
-
</details>
|
| 309 |
-
|
| 310 |
-
### Sequential Long-Form
|
| 311 |
-
|
| 312 |
-
This algorithm uses a sliding window for buffered inference of long audio files (> 30-seconds),
|
| 313 |
-
and returns more accurate transcriptions compared to the [chunked long-form algorithm](#chunked-long-form).
|
| 314 |
-
|
| 315 |
-
The sequential long-form algorithm should be used in either of the following scenarios:
|
| 316 |
-
1. Transcription accuracy is the most important factor, and latency is less of a consideration
|
| 317 |
-
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
|
| 318 |
-
|
| 319 |
-
The [`pipeline`](https://huggingface.co/docs/transformers/main_classes/pipelines#transformers.AutomaticSpeechRecognitionPipeline)
|
| 320 |
-
class can be used to transcribe long audio files with the sequential algorithm as follows:
|
| 321 |
-
|
| 322 |
-
```python
|
| 323 |
-
import torch
|
| 324 |
-
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 325 |
-
from datasets import load_dataset
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 329 |
-
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 330 |
-
|
| 331 |
-
model_id = "openai/whisper-large-v3"
|
| 332 |
-
|
| 333 |
-
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 334 |
-
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
| 335 |
-
)
|
| 336 |
-
model.to(device)
|
| 337 |
-
|
| 338 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 339 |
-
|
| 340 |
-
pipe = pipeline(
|
| 341 |
-
"automatic-speech-recognition",
|
| 342 |
-
model=model,
|
| 343 |
-
tokenizer=processor.tokenizer,
|
| 344 |
-
feature_extractor=processor.feature_extractor,
|
| 345 |
-
max_new_tokens=128,
|
| 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 |
-
<details>
|
| 358 |
-
|
| 359 |
-
<summary> For more control over the generation parameters, use the model + processor API directly: </summary>
|
| 360 |
-
|
| 361 |
-
```python
|
| 362 |
-
import torch
|
| 363 |
-
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
|
| 364 |
-
from datasets import Audio, load_dataset
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 368 |
-
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 369 |
-
|
| 370 |
-
model_id = "openai/whisper-large-v3"
|
| 371 |
-
|
| 372 |
-
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 373 |
-
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
| 374 |
-
)
|
| 375 |
-
model.to(device)
|
| 376 |
-
|
| 377 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 378 |
-
|
| 379 |
-
dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 380 |
-
dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
|
| 381 |
-
sample = dataset[0]["audio"]
|
| 382 |
-
|
| 383 |
-
inputs = processor(
|
| 384 |
-
sample["array"],
|
| 385 |
-
sampling_rate=sample["sampling_rate"],
|
| 386 |
-
return_tensors="pt",
|
| 387 |
-
truncation=False,
|
| 388 |
-
padding="longest",
|
| 389 |
-
return_attention_mask=True,
|
| 390 |
-
)
|
| 391 |
-
inputs = inputs.to(device, dtype=torch_dtype)
|
| 392 |
-
|
| 393 |
-
gen_kwargs = {
|
| 394 |
-
"max_new_tokens": 448,
|
| 395 |
-
"num_beams": 1,
|
| 396 |
-
"condition_on_prev_tokens": False,
|
| 397 |
-
"compression_ratio_threshold": 1.35, # zlib compression ratio threshold (in token space)
|
| 398 |
-
"temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
|
| 399 |
-
"logprob_threshold": -1.0,
|
| 400 |
-
"no_speech_threshold": 0.6,
|
| 401 |
-
"return_timestamps": True,
|
| 402 |
-
}
|
| 403 |
-
|
| 404 |
-
pred_ids = model.generate(**i nputs, **gen_kwargs)
|
| 405 |
-
pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=False)
|
| 406 |
-
|
| 407 |
-
print(pred_text)
|
| 408 |
```
|
| 409 |
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
### Chunked Long-Form
|
| 413 |
-
|
| 414 |
-
large-v3 remains compatible with the Transformers chunked long-form algorithm. This algorithm should be used when
|
| 415 |
-
a single large audio file is being transcribed and the fastest possible inference is required. In such circumstances,
|
| 416 |
-
the chunked algorithm is up to 9x faster than OpenAI's sequential long-form implementation (see Table 7 of the
|
| 417 |
-
[Distil-Whisper paper](https://arxiv.org/pdf/2311.00430.pdf)).
|
| 418 |
-
|
| 419 |
-
To enable chunking, pass the `chunk_length_s` parameter to the `pipeline`. For distil-large-v3, a chunk length of 25-seconds
|
| 420 |
-
is optimal. To activate batching over long audio files, pass the argument `batch_size`:
|
| 421 |
|
| 422 |
```python
|
| 423 |
-
import
|
| 424 |
-
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 425 |
-
from datasets import load_dataset
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 429 |
-
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 430 |
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
)
|
| 436 |
-
model.to(device)
|
| 437 |
-
|
| 438 |
-
processor = AutoProcessor.from_pretrained(model_id)
|
| 439 |
|
| 440 |
-
|
| 441 |
-
"
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
chunk_length_s=25,
|
| 447 |
-
batch_size=16,
|
| 448 |
-
torch_dtype=torch_dtype,
|
| 449 |
-
device=device,
|
| 450 |
)
|
| 451 |
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
result = pipe(sample)
|
| 456 |
-
print(result["text"])
|
| 457 |
-
```
|
| 458 |
-
|
| 459 |
-
### Additional Speed & Memory Improvements
|
| 460 |
-
|
| 461 |
-
You can apply additional speed and memory improvements to Distil-Whisper to further reduce the inference speed and VRAM
|
| 462 |
-
requirements. These optimisations primarily target the attention kernel, swapping it from an eager implementation to a
|
| 463 |
-
more efficient flash attention version.
|
| 464 |
-
|
| 465 |
-
#### Flash Attention 2
|
| 466 |
-
|
| 467 |
-
We recommend using [Flash-Attention 2](https://huggingface.co/docs/transformers/main/en/perf_infer_gpu_one#flashattention-2)
|
| 468 |
-
if your GPU allows for it. To do so, you first need to install [Flash Attention](https://github.com/Dao-AILab/flash-attention):
|
| 469 |
-
|
| 470 |
-
```
|
| 471 |
-
pip install flash-attn --no-build-isolation
|
| 472 |
-
```
|
| 473 |
-
|
| 474 |
-
Then pass `attn_implementation="flash_attention_2"` to `from_pretrained`:
|
| 475 |
-
|
| 476 |
-
```diff
|
| 477 |
-
- model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
|
| 478 |
-
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True, attn_implementation="flash_attention_2")
|
| 479 |
-
```
|
| 480 |
-
|
| 481 |
-
#### Torch Scale-Product-Attention (SDPA)
|
| 482 |
-
|
| 483 |
-
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).
|
| 484 |
-
This attention implementation is activated **by default** for PyTorch versions 2.1.1 or greater. To check
|
| 485 |
-
whether you have a compatible PyTorch version, run the following Python code snippet:
|
| 486 |
-
|
| 487 |
-
```python
|
| 488 |
-
from transformers.utils import is_torch_sdpa_available
|
| 489 |
-
|
| 490 |
-
print(is_torch_sdpa_available())
|
| 491 |
-
```
|
| 492 |
-
|
| 493 |
-
If the above returns `True`, you have a valid version of PyTorch installed and SDPA is activated by default. If it
|
| 494 |
-
returns `False`, you need to upgrade your PyTorch version according to the [official instructions](https://pytorch.org/get-started/locally/)
|
| 495 |
-
|
| 496 |
-
Once a valid PyTorch version is installed, SDPA is activated by default. It can also be set explicitly by specifying
|
| 497 |
-
`attn_implementation="sdpa"` as follows:
|
| 498 |
-
|
| 499 |
-
```diff
|
| 500 |
-
- model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True)
|
| 501 |
-
+ model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True, attn_implementation="sdpa")
|
| 502 |
```
|
| 503 |
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
#### Torch compile
|
| 507 |
-
|
| 508 |
-
Coming soon...
|
| 509 |
-
|
| 510 |
-
#### 4-bit and 8-bit Inference
|
| 511 |
-
|
| 512 |
-
Coming soon...
|
| 513 |
|
| 514 |
-
|
| 515 |
|
| 516 |
-
|
| 517 |
-
its predictive capabilities can be improved further for certain languages and tasks through *fine-tuning*. The blog
|
| 518 |
-
post [Fine-Tune Whisper with π€ Transformers](https://huggingface.co/blog/fine-tune-whisper) provides a step-by-step
|
| 519 |
-
guide to fine-tuning the Whisper model with as little as 5 hours of labelled data.
|
| 520 |
-
|
| 521 |
-
### Evaluated Use
|
| 522 |
-
|
| 523 |
-
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.
|
| 524 |
-
|
| 525 |
-
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.
|
| 526 |
-
|
| 527 |
-
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.
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
## Training Data
|
| 531 |
-
|
| 532 |
-
The models are trained on 1 million hours of weakly labeled audio and 4 million hours of pseudolabeled audio collected using Whisper `large-v2`.
|
| 533 |
|
| 534 |
-
|
| 535 |
|
|
|
|
| 536 |
|
| 537 |
-
##
|
| 538 |
|
| 539 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
|
| 541 |
-
|
| 542 |
|
| 543 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
|
| 545 |
-
|
| 546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 547 |
|
| 548 |
-
##
|
| 549 |
|
| 550 |
-
|
|
|
|
|
|
|
| 551 |
|
| 552 |
-
|
| 553 |
|
|
|
|
| 554 |
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
doi = {10.48550/ARXIV.2212.04356},
|
| 559 |
-
url = {https://arxiv.org/abs/2212.04356},
|
| 560 |
-
author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
|
| 561 |
-
title = {Robust Speech Recognition via Large-Scale Weak Supervision},
|
| 562 |
-
publisher = {arXiv},
|
| 563 |
-
year = {2022},
|
| 564 |
-
copyright = {arXiv.org perpetual, non-exclusive license}
|
| 565 |
-
}
|
| 566 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
license: apache-2.0
|
| 4 |
+
library_name: ctranslate2
|
| 5 |
+
pipeline_tag: automatic-speech-recognition
|
| 6 |
+
tags:
|
| 7 |
+
- whisper
|
| 8 |
+
- ctranslate2
|
| 9 |
+
- speech-recognition
|
| 10 |
+
- transcription
|
| 11 |
+
- float32
|
| 12 |
+
base_model: openai/whisper-large-v3
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# π£οΈ Whisper Large-v3 β CTranslate2 (`float32`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
This is [OpenAI's whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) converted to [CTranslate2](https://github.com/OpenNMT/CTranslate2) format with `float32` precision.
|
| 18 |
|
| 19 |
+
> [!TIP]
|
| 20 |
+
> Also available in other precisions:
|
| 21 |
+
> [`float16`](https://huggingface.co/ctranslate2-4you/whisper-large-v3-ct2-float16) Β· [`bfloat16`](https://huggingface.co/ctranslate2-4you/whisper-large-v3-ct2-bfloat16)
|
| 22 |
|
| 23 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
## π Details
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
+
| | |
|
| 28 |
+
|---|---|
|
| 29 |
+
| **Base model** | [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) |
|
| 30 |
+
| **Format** | CTranslate2 |
|
| 31 |
+
| **Precision** | `float32` |
|
| 32 |
+
| **Language** | Multilingual |
|
| 33 |
+
| **Task** | Automatic Speech Recognition |
|
| 34 |
|
| 35 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
## β‘ Quick Start
|
| 38 |
|
| 39 |
+
Install the inference library:
|
|
|
|
|
|
|
| 40 |
|
| 41 |
```bash
|
| 42 |
+
pip install whisper-s2t-reborn
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
```
|
| 44 |
|
| 45 |
+
Transcribe an audio file:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
```python
|
| 48 |
+
import whisper_s2t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
model = whisper_s2t.load_model(
|
| 51 |
+
model_identifier="large-v3",
|
| 52 |
+
compute_type="float32",
|
| 53 |
+
device="cuda",
|
| 54 |
)
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
result = model.transcribe_with_vad(
|
| 57 |
+
["audio.wav"],
|
| 58 |
+
lang_codes=["en"],
|
| 59 |
+
tasks=["transcribe"],
|
| 60 |
+
initial_prompts=[None],
|
| 61 |
+
batch_size=1, # increase this to significantly improve throughput
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
+
for segment in result[0]:
|
| 65 |
+
print(segment["text"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
```
|
| 67 |
|
| 68 |
+
> [!NOTE]
|
| 69 |
+
> Models are **auto-downloaded** from this repo the first time you run inference. No manual download required.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
+
*See the [whisper-s2t-reborn](https://github.com/BBC-Esq/WhisperS2T-reborn) repository for the full list of available parameters.*
|
| 72 |
|
| 73 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
+
## π¦ All Available CTranslate2 Whisper Models
|
| 76 |
|
| 77 |
+
Every model below is hosted at [huggingface.co/ctranslate2-4you](https://huggingface.co/ctranslate2-4you) and works with [whisper-s2t-reborn](https://github.com/BBC-Esq/WhisperS2T-reborn).
|
| 78 |
|
| 79 |
+
### π Standard Whisper (Multilingual)
|
| 80 |
|
| 81 |
+
| Model | `float32` | `float16` | `bfloat16` |
|
| 82 |
+
|---|:---:|:---:|:---:|
|
| 83 |
+
| **tiny** | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny-ct2-bfloat16) |
|
| 84 |
+
| **base** | [Link](https://huggingface.co/ctranslate2-4you/whisper-base-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-base-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-base-ct2-bfloat16) |
|
| 85 |
+
| **small** | [Link](https://huggingface.co/ctranslate2-4you/whisper-small-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-small-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-small-ct2-bfloat16) |
|
| 86 |
+
| **medium** | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium-ct2-bfloat16) |
|
| 87 |
+
| **large-v3** | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-ct2-bfloat16) |
|
| 88 |
|
| 89 |
+
### πΊπΈ Whisper English-Only
|
| 90 |
|
| 91 |
+
| Model | `float32` | `float16` | `bfloat16` |
|
| 92 |
+
|---|:---:|:---:|:---:|
|
| 93 |
+
| **tiny.en** | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-tiny.en-ct2-bfloat16) |
|
| 94 |
+
| **base.en** | [Link](https://huggingface.co/ctranslate2-4you/whisper-base.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-base.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-base.en-ct2-bfloat16) |
|
| 95 |
+
| **small.en** | [Link](https://huggingface.co/ctranslate2-4you/whisper-small.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-small.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-small.en-ct2-bfloat16) |
|
| 96 |
+
| **medium.en** | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-medium.en-ct2-bfloat16) |
|
| 97 |
|
| 98 |
+
### β‘ Distilled Whisper
|
| 99 |
|
| 100 |
+
| Model | `float32` | `float16` | `bfloat16` |
|
| 101 |
+
|---|:---:|:---:|:---:|
|
| 102 |
+
| **distil-small.en** | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-small.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-small.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-small.en-ct2-bfloat16) |
|
| 103 |
+
| **distil-medium.en** | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-medium.en-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-medium.en-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-medium.en-ct2-bfloat16) |
|
| 104 |
+
| **distil-large-v3** | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-large-v3-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-large-v3-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/distil-whisper-large-v3-ct2-bfloat16) |
|
| 105 |
|
| 106 |
+
### π Whisper Large-v3 Turbo
|
| 107 |
|
| 108 |
+
| Model | `float32` | `float16` | `bfloat16` |
|
| 109 |
+
|---|:---:|:---:|:---:|
|
| 110 |
+
| **large-v3-turbo** | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-turbo-ct2-float32) | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-turbo-ct2-float16) | [Link](https://huggingface.co/ctranslate2-4you/whisper-large-v3-turbo-ct2-bfloat16) |
|
| 111 |
|
| 112 |
+
---
|
| 113 |
|
| 114 |
+
## π Links
|
| 115 |
|
| 116 |
+
- π¦ **Inference library** β [whisper-s2t-reborn](https://github.com/BBC-Esq/WhisperS2T-reborn)
|
| 117 |
+
- ποΈ **CTranslate2** β [github.com/OpenNMT/CTranslate2](https://github.com/OpenNMT/CTranslate2)
|
| 118 |
+
- π§ **Original model** β [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|