whisper large v3 turbo

提供商openai
分类automatic-speech-recognition
许可证mit
下载量7.9M
星标0

简介

Whisper large-v3-turbo 是 OpenAI 推出的语音识别加速版模型。它在保持 v3 强悍的多语言识别和翻译能力的同时,通过优化解码速度,极大地降低了推理延迟。对于开发者而言,它解决了原版 large 模型部署成本高、实时性差的痛点,使其在保证极高准确率的前提下,能够更流畅地应用于实时转写、长音频处理等场景。上手难度低,且与现有 Whisper 生态完全兼容,是目前平衡性能与效率的 ASR 顶尖选择。

核心亮点

  • 继承 v3 顶尖精度,识别准确率极高
  • 推理速度大幅提升,显著降低响应延迟
  • 支持多语言转写与翻译,适用场景广泛
  • 兼容现有生态,部署门槛低且效率高

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("openai/whisper-large-v3-turbo")
tokenizer = AutoTokenizer.from_pretrained("openai/whisper-large-v3-turbo")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download openai/whisper-large-v3-turbo

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download openai/whisper-large-v3-turbo config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('openai/whisper-large-v3-turbo')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/openai/whisper-large-v3-turbo

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/openai/whisper-large-v3-turbo

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('openai/whisper-large-v3-turbo')
tokenizer = AutoTokenizer.from_pretrained('openai/whisper-large-v3-turbo')

完整文档

来源: HuggingFace

---
language:

  • en

  • zh

  • de

  • es

  • ru

  • ko

  • fr

  • ja

  • pt

  • tr

  • pl

  • ca

  • nl

  • ar

  • sv

  • it

  • id

  • hi

  • fi

  • vi

  • he

  • uk

  • el

  • ms

  • cs

  • ro

  • da

  • hu

  • ta

  • 'no'

  • th

  • ur

  • hr

  • bg

  • lt

  • la

  • mi

  • ml

  • cy

  • sk

  • te

  • fa

  • lv

  • bn

  • sr

  • az

  • sl

  • kn

  • et

  • mk

  • br

  • eu

  • is

  • hy

  • ne

  • mn

  • bs

  • kk

  • sq

  • sw

  • gl

  • mr

  • pa

  • si

  • km

  • sn

  • yo

  • so

  • af

  • oc

  • ka

  • be

  • tg

  • sd

  • gu

  • am

  • yi

  • lo

  • uz

  • fo

  • ht

  • ps

  • tk

  • nn

  • mt

  • sa

  • lb

  • my

  • bo

  • tl

  • mg

  • as

  • tt

  • haw

  • ln

  • ha

  • ba

  • jw

  • su

license: mit
tags:
  • audio

  • automatic-speech-recognition

widget:
  • example_title: Librispeech sample 1

src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
  • example_title: Librispeech sample 2

src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
pipeline_tag: automatic-speech-recognition
base_model:
  • openai/whisper-large-v3

library_name: transformers
---

Whisper

Whisper is a state-of-the-art model for automatic speech recognition (ASR) and speech translation, proposed in the paper
Robust Speech Recognition via Large-Scale Weak Supervision by Alec Radford
et al. from OpenAI. Trained on >5M hours of labeled data, Whisper demonstrates a strong ability to generalise to many
datasets and domains in a zero-shot setting.

Whisper large-v3-turbo is a finetuned version of a pruned 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.
As a result, the model is way faster, at the expense of a minor quality degradation. You can find more details about it in this GitHub discussion.

Disclaimer: Content for this model card has partly been written by the 🤗 Hugging Face team, and partly copied and
pasted from the original model card.

Usage

Whisper large-v3-turbo is supported in Hugging Face 🤗 Transformers. To run the model, first install the Transformers
library. For this example, we'll also install 🤗 Datasets to load toy audio dataset from the Hugging Face Hub, and
🤗 Accelerate to reduce the model loading time:

bash
pip install --upgrade pip
pip install --upgrade transformers datasets[audio] accelerate

The model can be used with the pipeline
class to transcribe audios of arbitrary length:

python
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
from datasets import load_dataset

device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

model_id = "openai/whisper-large-v3-turbo"

model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
)
model.to(device)

processor = AutoProcessor.from_pretrained(model_id)

pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
torch_dtype=torch_dtype,
device=device,
)

dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
sample = dataset[0]["audio"]

result = pipe(sample)
print(result["text"])

To transcribe a local audio file, simply pass the path to your audio file when you call the pipeline:

python
result = pipe("audio.mp3")

Multiple audio files can be transcribed in parallel by specifying them as a list and setting the batch_size parameter:

python
result = pipe(["audio_1.mp3", "audio_2.mp3"], batch_size=2)

Transformers is compatible with all Whisper decoding strategies, such as temperature fallback and condition on previous
tokens. The following example demonstrates how to enable these heuristics:

python
generate_kwargs = {
    "max_new_tokens": 448,
    "num_beams": 1,
    "condition_on_prev_tokens": False,
    "compression_ratio_threshold": 1.35,  # zlib compression ratio threshold (in token space)
    "temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
    "logprob_threshold": -1.0,
    "no_speech_threshold": 0.6,
    "return_timestamps": True,
}

result = pipe(sample, generate_kwargs=generate_kwargs)

Whisper predicts the language of the source audio automatically. If the source audio language is known *a-priori*, it
can be passed as an argument to the pipeline:

python
result = pipe(sample, generate_kwargs={"language": "english"})

By default, Whisper performs the task of *speech transcription*, where the source audio language is the same as the target
text language. To perform *speech translation*, where the target text is in English, set the task to "translate":

python
result = pipe(sample, generate_kwargs={"task": "translate"})

Finally, the model can be made to predict timestamps. For sentence-level timestamps, pass the return_timestamps argument:

python
result = pipe(sample, return_timestamps=True)
print(result["chunks"])

And for word-level timestamps:

python
result = pipe(sample, return_timestamps="word")
print(result["chunks"])

The above arguments can be used in isolation or in combination. For example, to perform the task of speech transcription
where the source audio is in French, and we want to return sentence-level timestamps, the following can be used:

python
result = pipe(sample, return_timestamps=True, generate_kwargs={"language": "french", "task": "translate"})
print(result["chunks"])

<details>

<summary> For more control over the generation parameters, use the model + processor API directly: </summary>

python
import torch
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
from datasets import Audio, load_dataset

device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32

model_id = "openai/whisper-large-v3-turbo"

model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True
)
model.to(device)

processor = AutoProcessor.from_pretrained(model_id)

dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
sample = dataset[0]["audio"]

inputs = processor(
sample["array"],
sampling_rate=sample["sampling_rate"],
return_tensors="pt",
truncation=False,
padding="longest",
return_attention_mask=True,
)
inputs = inputs.to(device, dtype=torch_dtype)

gen_kwargs = {
"max_new_tokens": 448,
"num_beams": 1,
"condition_on_prev_tokens": False,
"compression_ratio_threshold": 1.35, # zlib compression ratio threshold (in token space)
"temperature": (0.0, 0.2, 0.4, 0.6, 0.8, 1.0),
"logprob_threshold": -1.0,
"no_speech_threshold": 0.6,
"return_timestamps": True,
}

pred_ids = model.generate(inputs, gen_kwargs)
pred_text = processor.batch_decode(pred_ids, skip_special_tokens=True, decode_with_timestamps=False)

print(pred_text)

</details>

Additional Speed & Memory Improvements

You can apply additional speed and memory improvements to Whisper to further reduce the inference speed and VRAM
requirements.

Chunked Long-Form

Whisper has a receptive field of 30-seconds. To transcribe audios longer than this, one of two long-form algorithms are
required:
1. Sequential: uses a "sliding window" for buffered inference, transcribing 30-second slices one after the other
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

The sequential long-form algorithm should be used in either of the following scenarios:
1. Transcription accuracy is