模型简介
模型特点
模型能力
使用案例
许可证: mit 语言: 法语 库名称: transformers 管道标签: 自动语音识别 缩略图: 无 标签:
- 自动语音识别
- hf-asr排行榜 数据集:
- mozilla-foundation/common_voice_13_0
- facebook/multilingual_librispeech
- facebook/voxpopuli
- google/fleurs
- gigant/african_accented_french 指标:
- 词错误率(WER) 模型索引:
- 名称: whisper-large-v3-french-distil-dec8
结果:
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: Common Voice 13.0
类型: mozilla-foundation/common_voice_13_0
配置: fr
拆分: test
参数:
语言: fr
指标:
- 名称: WER 类型: wer 值: 7.62
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: 多语言LibriSpeech (MLS)
类型: facebook/multilingual_librispeech
配置: french
拆分: test
参数:
语言: fr
指标:
- 名称: WER 类型: wer 值: 3.80
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: VoxPopuli
类型: facebook/voxpopuli
配置: fr
拆分: test
参数:
语言: fr
指标:
- 名称: WER 类型: wer 值: 8.85
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: Fleurs
类型: google/fleurs
配置: fr_fr
拆分: test
参数:
语言: fr
指标:
- 名称: WER 类型: wer 值: 5.40
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: 非洲口音法语
类型: gigant/african_accented_french
配置: fr
拆分: test
参数:
语言: fr
指标:
- 名称: WER 类型: wer 值: 4.18
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: Common Voice 13.0
类型: mozilla-foundation/common_voice_13_0
配置: fr
拆分: test
参数:
语言: fr
指标:
Whisper-Large-V3-法语-蒸馏-Dec8版
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流水线进行快速评估。音频文件被分割成30秒的片段并行处理。
使用方法
Hugging Face流水线
该模型可以轻松与🤗 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-dec8"
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)
# 初始化流水线
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"]
# 运行流水线
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-dec8"
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流水线进行推测性解码很简单 - 只需在生成配置中指定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)
# 初始化流水线
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"]
# 运行流水线
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-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"
现在,你可以按照仓库提供的使用说明转录音频文件:
import whisper
from datasets import load_dataset
# 加载模型
model = whisper.load_model("./models/whisper-large-v3-french-distil-dec8/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-dec8', local_dir='./models/whisper-large-v3-french-distil-dec8', allow_patterns='ctranslate2/*')"
现在,你可以按照仓库提供的使用说明转录音频文件:
from datasets import load_dataset
from faster_whisper import WhisperModel
# 加载模型
model = WhisperModel("./models/whisper-large-v3-french-distil-dec8/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-dec8', filename='ggml-model-q5_0.bin', local_dir='./models/whisper-large-v3-french-distil-dec8')"
现在,你可以使用以下命令转录音频文件:
./main -m ./models/whisper-large-v3-french-distil-dec8/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-dec8 --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-dec8 --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-dec8', filename='original_model.pt', local_dir='./models/whisper-large-v3-french-distil-dec8')"
# 转换为.npz
python convert.py --torch-name-or-path ./models/whisper-large-v3-french-distil-dec8/original_model.pt --mlx-path ./mlx_models/whisper-large-v3-french-distil-dec8
现在,你可以使用以下代码转录音频:
import whisper
result = whisper.transcribe("/path/to/audio/file", path_or_hf_repo="mlx_models/whisper-large-v3-french-distil-dec8", 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模型从有限的符号集中恢复大小写和标点。
然而,即使在



