模型简介
模型特点
模型能力
使用案例
license: mit language: fr library_name: transformers pipeline_tag: automatic-speech-recognition thumbnail: null tags:
- 自动语音识别
- hf-asr排行榜 datasets:
- 摩斯拉基金会/common_voice_13_0
- 脸书/多语言LibriSpeech
- 脸书/voxpopuli
- 谷歌/fleurs
- 巨人/非洲口音法语 metrics:
- 词错误率 model-index:
- name: whisper-large-v3-french-distil-dec16
results:
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: Common Voice 13.0
type: mozilla-foundation/common_voice_13_0
config: fr
split: test
args:
language: fr
metrics:
- name: 词错误率 type: wer value: 7.18
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: 多语言LibriSpeech (MLS)
type: facebook/multilingual_librispeech
config: french
split: test
args:
language: fr
metrics:
- name: 词错误率 type: wer value: 3.57
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: VoxPopuli
type: facebook/voxpopuli
config: fr
split: test
args:
language: fr
metrics:
- name: 词错误率 type: wer value: 8.76
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: Fleurs
type: google/fleurs
config: fr_fr
split: test
args:
language: fr
metrics:
- name: 词错误率 type: wer value: 5.03
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: 非洲口音法语
type: gigant/african_accented_french
config: fr
split: test
args:
language: fr
metrics:
- name: 词错误率 type: wer value: 3.90
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: Common Voice 13.0
type: mozilla-foundation/common_voice_13_0
config: fr
split: test
args:
language: fr
metrics:
Whisper-Large-V3-法语蒸馏版-Dec16
Whisper-Large-V3-法语蒸馏版是通过将Whisper-Large-V3-法语的解码器层数从32层减少至16、8、4或2层,并利用大规模数据集进行蒸馏而得到的一系列模型,具体方法详见这篇论文。
蒸馏版本在保持性能(基于保留的层数)的同时,降低了内存占用和推理时间,并减少了长文本转录中出现幻觉的风险。此外,它们可以与原始Whisper-Large-V3-法语模型无缝结合进行推测解码,相比单独使用蒸馏模型,能提高推理速度并保持输出一致性。
该模型已转换为多种格式,便于在不同库中使用,包括transformers、openai-whisper、fasterwhisper、whisper.cpp、candle、mlx等。
目录
性能
我们对模型在短文本和长文本转录上进行了评估,并在分布内和分布外数据集上进行了测试,以全面分析其准确性、泛化性和鲁棒性。
请注意,报告的词错误率(WER)是将数字转换为文本、去除标点(撇号和连字符除外)并将所有字符转换为小写后的结果。
所有公共数据集的评估结果可在此处查看。
短文本转录
由于法语中缺乏现成的分布外(OOD)和长文本测试集,我们使用了Zaion Lab的内部测试集进行评估。这些测试集包含来自呼叫中心对话的人工标注音频-文本对,特点是背景噪音大且包含领域特定术语。
长文本转录
长文本转录使用🤗 Hugging Face pipeline进行快速评估。音频文件被分割为30秒的片段并并行处理。
使用方法
Hugging Face Pipeline
该模型可以轻松使用🤗 Hugging Face的pipeline
类进行音频转录。
对于长文本转录(>30秒),可以通过传递chunk_length_s
参数激活处理。这种方法将音频分割为较小的片段并行处理,然后通过寻找最长公共序列在步长处拼接。虽然这种分块长文本方法在性能上可能略逊于OpenAI的顺序算法,但提供了9倍的推理速度提升。
import torch
from datasets import load_dataset
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
# 加载模型
model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec16"
processor = AutoProcessor.from_pretrained(model_name_or_path)
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_name_or_path,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
)
model.to(device)
# 初始化pipeline
pipe = pipeline(
"automatic-speech-recognition",
model=model,
feature_extractor=processor.feature_extractor,
tokenizer=processor.tokenizer,
torch_dtype=torch_dtype,
device=device,
# chunk_length_s=30, # 用于长文本转录
max_new_tokens=128,
)
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
sample = dataset[0]["audio"]
# 运行pipeline
result = pipe(sample)
print(result["text"])
Hugging Face底层API
你也可以使用🤗 Hugging Face的底层API进行转录,提供对过程的更大控制,如下所示:
import torch
from datasets import load_dataset
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
# 加载模型
model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec16"
processor = AutoProcessor.from_pretrained(model_name_or_path)
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_name_or_path,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
)
model.to(device)
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
sample = dataset[0]["audio"]
# 提取特征
input_features = processor(
sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt"
).input_features
# 生成标记
predicted_ids = model.generate(
input_features.to(dtype=torch_dtype).to(device), max_new_tokens=128
)
# 解码为文本
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
print(transcription)
推测解码
推测解码可以使用草稿模型实现,本质上是Whisper的蒸馏版本。这种方法保证与单独使用主Whisper模型相同的输出,提供2倍的推理速度提升,并且仅带来轻微的内存开销增加。
由于蒸馏Whisper与原始模型具有相同的编码器,只需加载其解码器,并且在推理过程中主模型和草稿模型共享编码器输出。
使用Hugging Face pipeline进行推测解码很简单——只需在生成配置中指定assistant_model
。
import torch
from datasets import load_dataset
from transformers import (
AutoModelForCausalLM,
AutoModelForSpeechSeq2Seq,
AutoProcessor,
pipeline,
)
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
# 加载模型
model_name_or_path = "bofenghuang/whisper-large-v3-french"
processor = AutoProcessor.from_pretrained(model_name_or_path)
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_name_or_path,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
)
model.to(device)
# 加载草稿模型
assistant_model_name_or_path = "bofenghuang/whisper-large-v3-french-distil-dec2"
assistant_model = AutoModelForCausalLM.from_pretrained(
assistant_model_name_or_path,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
)
assistant_model.to(device)
# 初始化pipeline
pipe = pipeline(
"automatic-speech-recognition",
model=model,
feature_extractor=processor.feature_extractor,
tokenizer=processor.tokenizer,
torch_dtype=torch_dtype,
device=device,
generate_kwargs={"assistant_model": assistant_model},
max_new_tokens=128,
)
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
sample = dataset[0]["audio"]
# 运行pipeline
result = pipe(sample)
print(result["text"])
OpenAI Whisper
你也可以使用OpenAI在其原始论文中提出的滑动窗口和温度回退的顺序长文本解码算法。
首先,安装openai-whisper包:
pip install -U openai-whisper
然后,下载转换后的模型:
python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec16', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec16')"
现在,你可以按照仓库中的使用说明转录音频文件:
import whisper
from datasets import load_dataset
# 加载模型
model = whisper.load_model("./models/whisper-large-v3-french-distil-dec16/original_model.pt")
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
sample = dataset[0]["audio"]["array"].astype("float32")
# 转录
result = model.transcribe(sample, language="fr")
print(result["text"])
Faster Whisper
Faster Whisper是OpenAI Whisper模型和顺序长文本解码算法在CTranslate2格式中的重新实现。
与openai-whisper相比,它提供高达4倍的推理速度提升,同时消耗更少内存。此外,模型可以量化为int8,进一步在CPU和GPU上提高效率。
首先,安装faster-whisper包:
pip install faster-whisper
然后,下载转换为CTranslate2格式的模型:
python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec16', local_dir='./models/whisper-large-v3-french-distil-dec16', allow_patterns='ctranslate2/*')"
现在,你可以按照仓库中的使用说明转录音频文件:
from datasets import load_dataset
from faster_whisper import WhisperModel
# 加载模型
model = WhisperModel("./models/whisper-large-v3-french-distil-dec16/ctranslate2", device="cuda", compute_type="float16") # 在GPU上使用FP16运行
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "fr", split="test")
sample = dataset[0]["audio"]["array"].astype("float32")
segments, info = model.transcribe(sample, beam_size=5, language="fr")
for segment in segments:
print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
Whisper.cpp
Whisper.cpp是OpenAI Whisper模型的重新实现,采用纯C/C++编写,无任何依赖。它支持多种后端和平台。
此外,模型可以量化为4位或5位整数,进一步提高效率。
首先,克隆并构建whisper.cpp仓库:
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp
# 构建主示例
make
接下来,从Hugging Face Hub下载转换后的ggml权重:
# 下载使用Q5_0方法量化的模型
python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec16', filename='ggml-model-q5_0.bin', local_dir='./models/whisper-large-v3-french-distil-dec16')"
现在,你可以使用以下命令转录音频文件:
./main -m ./models/whisper-large-v3-french-distil-dec16/ggml-model-q5_0.bin -l fr -f /path/to/audio/file --print-colors
Candle
Candle-whisper是OpenAI Whisper模型在candle格式中的重新实现——一个用Rust构建的轻量级ML框架。
首先,克隆candle仓库:
git clone https://github.com/huggingface/candle.git
cd candle/candle-examples/examples/whisper
使用以下命令转录音频文件:
cargo run --example whisper --release -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec16 --language fr --input /path/to/audio/file
要使用CUDA,在示例命令行中添加--features cuda
:
cargo run --example whisper --release --features cuda -- --model large-v3 --model-id bofenghuang/whisper-large-v3-french-distil-dec16 --language fr --input /path/to/audio/file
MLX
MLX-Whisper是OpenAI Whisper模型在MLX格式中的重新实现——一个在Apple芯片上的ML框架。它支持惰性计算、统一内存管理等特性。
首先,克隆MLX Examples仓库:
git clone https://github.com/ml-explore/mlx-examples.git
cd mlx-examples/whisper
接下来,安装依赖:
pip install -r requirements.txt
下载原始OpenAI格式的pytorch检查点并转换为MLX格式(由于仓库已经很大且转换非常快,我们未包含转换后的版本):
# 下载
python -c "from huggingface_hub import hf_hub_download; hf_hub_download(repo_id='bofenghuang/whisper-large-v3-french-distil-dec16', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec16')"
# 转换为.npz
python convert.py --torch-name-or-path ./models/whisper-large-v3-french-distil-dec16/original_model.pt --mlx-path ./mlx_models/whisper-large-v3-french-distil-dec16
现在,你可以转录音频:
import whisper
result = whisper.transcribe("/path/to/audio/file", path_or_hf_repo="mlx_models/whisper-large-v3-french-distil-dec16", language="fr")
print(result["text"])
训练细节
我们收集了一个包含超过2,500小时法语语音识别数据的复合数据集,其中包括Common Voice 13.0、Multilingual LibriSpeech、Voxpopuli、Fleurs、Multilingual TEDx、MediaSpeech、African Accented French等数据集。
由于一些数据集(如MLS)仅提供无大小写或标点的文本,我们使用了定制版的🤗 Speechbox,通过bofenghuang/whisper-large-v2-cv11-french模型从有限的符号集中恢复大小写和标点。
然而,即使在数据集中,我们也观察到某些质量问题。这些问题包括音频和转录在语言或内容上的不匹配、分割不良的语句、脚本语音中缺失的单词等。我们构建了一个管道来过滤掉许多有问题的语句,以提高数据集质量。结果,我们排除了超过10%的数据,当我们重新训练模型时,注意到幻觉显著减少。
对于训练,我们使用了🤗 Distil-Whisper仓库中提供的脚本。模型训练在GENCI的Jean-Zay超级计算机上进行,我们感谢IDRIS团队在整个项目中的积极响应支持。
致谢
- OpenAI创建并开源了Whisper模型
- 🤗 Hugging Face集成了Whisper模型并在Transformers和Distil-Whisper仓库中提供了训练代码库
- Genci为本项目慷慨贡献了GPU小时



