模型简介
模型特点
模型能力
使用案例
许可协议: mit
语言: 意大利语
库名称: transformers
任务标签: 自动语音识别
缩略图: 无
标签:
- 自动语音识别
- hf-asr-leaderboard
数据集: - mozilla-foundation/common_voice_17_0
- facebook/multilingual_librispeech
- facebook/voxpopuli
- espnet/yodas
评估指标: - 词错误率(WER)
Whisper-Large-V3蒸馏意大利语版v0.2
专为意大利语优化的2层解码器蒸馏版Whisper语音转文本模型。
本版本扩展了30秒音频片段的训练以保持长文本转录能力。训练过程采用"耐心"教师蒸馏法——即延长训练时间并加强数据增强——从而提升整体性能。
模型以openai/whisper-large-v3作为教师模型,保持编码器架构不变。这使其适合作为推测解码的草稿模型,在仅增加2个额外解码层且编码器单次运行的情况下,可实现2倍推理速度的同时保持输出一致。也可作为独立模型在牺牲少量准确度的情况下提升效率,速度提升5.8倍且仅需49%参数量。该论文还指出,在长文本转录时蒸馏模型可能比完整模型产生更少的幻觉。
模型已转换为多种格式以确保跨库兼容性,包括transformers、openai-whisper、faster-whisper、whisper.cpp、candle、mlx。
性能表现
模型在短文本和长文本转录上均进行评估,使用分布内(ID)和分布外(OOD)数据集来衡量准确性、泛化性和鲁棒性。
注意此处展示的词错误率(WER)结果是后规范化的,包括转换为小写及移除符号和标点。
公开数据集上的所有评估结果可在此处查看。
短文本转录
斜体表示分布内(ID)评估,测试集与训练数据分布一致,通常表现优于分布外(OOD)评估。*斜体删除线*表示可能存在测试集污染——例如训练和评估使用不同版本的Common Voice时可能出现数据重叠。
长文本转录
长文本转录评估使用🤗 Hugging Face的pipeline
,包含分块(chunk_length_s=30)和原始顺序解码两种方法。
使用方式
Hugging Face Pipeline
可通过🤗 Hugging Face的pipeline
类轻松实现音频转录。长文本转录(超过30秒)将采用OpenAI论文中的顺序解码。如需更快推理,可使用chunk_length_s
参数进行分块并行解码,速度提升9倍但性能可能略逊于OpenAI的顺序算法。
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-distil-it-v0.2"
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", "it", 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-distil-it-v0.2"
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", "it", 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 = "openai/whisper-large-v3"
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-distil-it-v0.2"
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", "it", split="test")
sample = dataset[0]["audio"]
# 运行pipeline
result = pipe(sample)
print(result["text"])
OpenAI Whisper
也可采用OpenAI原始论文中的滑动窗口和温度回退顺序长文本解码算法。
首先安装openai-whisper包:
pip install -U openai-whisper
然后下载转换后的模型:
huggingface-cli download --include original_model.pt --local-dir ./models/whisper-large-v3-distil-it-v0.2 bofenghuang/whisper-large-v3-distil-it-v0.2
按仓库说明转录音频文件:
import whisper
from datasets import load_dataset
# 加载模型
model_name_or_path = "./models/whisper-large-v3-distil-it-v0.2/original_model.pt"
model = whisper.load_model(model_name_or_path)
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "it", split="test")
sample = dataset[0]["audio"]["array"].astype("float32")
# 转录
result = model.transcribe(sample, language="it")
print(result["text"])
Faster Whisper
Faster Whisper是OpenAI Whisper模型及顺序长文本解码算法在CTranslate2格式中的重新实现。
相比openai-whisper,它提供最高4倍的推理速度,同时内存占用更低。模型还可量化为int8,进一步提升CPU和GPU效率。
首先安装faster-whisper包:
pip install faster-whisper
然后下载转换为CTranslate2格式的模型:
huggingface-cli download --include ctranslate2/* --local-dir ./models/whisper-large-v3-distil-it-v0.2 bofenghuang/whisper-large-v3-distil-it-v0.2
按仓库说明转录音频文件:
from datasets import load_dataset
from faster_whisper import WhisperModel
# 加载模型
model_name_or_path = "./models/whisper-large-v3-distil-it-v0.2/ctranslate2"
model = WhisperModel(model_name_or_path", device="cuda", compute_type="float16") # 使用GPU FP16运行
# 示例音频
dataset = load_dataset("bofenghuang/asr-dummy", "it", split="test")
sample = dataset[0]["audio"]["array"].astype("float32")
segments, info = model.transcribe(sample, beam_size=5, language="it")
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方法量化的模型
huggingface-cli download --include ggml-model* --local-dir ./models/whisper-large-v3-distil-it-v0.2 bofenghuang/whisper-large-v3-distil-it-v0.2
使用以下命令转录音频文件:
./main -m ./models/whisper-large-v3-distil-it-v0.2/ggml-model-q5_0.bin -l it -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-distil-it-v0.2 --language it --input /path/to/audio/file
如需使用CUDA,在命令行添加--features cuda
:
cargo run --example whisper --release --features cuda -- --model large-v3 --model-id bofenghuang/whisper-large-v3-distil-it-v0.2 --language it --input /path/to/audio/file
MLX
MLX-Whisper是OpenAI Whisper模型在MLX格式中的实现——苹果芯片上的ML框架。支持延迟计算、统一内存管理等特性。
首先克隆MLX示例仓库:
git clone https://github.com/ml-explore/mlx-examples.git
cd mlx-examples/whisper
安装依赖:
pip install -r requirements.txt
下载原始OpenAI格式的PyTorch检查点并转换为MLX格式(因仓库体积较大且转换快速,此处未包含转换后版本):
# 下载
huggingface-cli download --include original_model.pt --local-dir ./models/whisper-large-v3-distil-it-v0.2 bofenghuang/whisper-large-v3-distil-it-v0.2
# 转换为.npz
python convert.py --torch-name-or-path ./models/whisper-large-v3-distil-it-v0.2/original_model.pt --mlx-path ./mlx_models/whisper-large-v3-distil-it-v0.2
转录音频:
import whisper
result = whisper.transcribe("/path/to/audio/file", path_or_hf_repo="mlx_models/whisper-large-v3-distil-it-v0.2", language="it")
print(result["text"])
训练详情
我们构建了超过11,000小时的意大利语标注和半标注语音识别数据集。通过Whisper-Large-V3解码并过滤掉WER高于20%的片段后,保留了约6,500小时高质量音频。
数据集 | 总时长(h) | 过滤后时长(h) WER<20% |
---|---|---|
mcv | 249.92 | 232.87 |
mls | 247.38 | 234.14 |
voxpopuli | 74.11 | 58.25 |
mtedx | 94.10 | 88.69 |
yodas-it000 | 1447.25 | 953.19 |
yodas-it100 | 4929.73 | 2665.54 |
yodas-it101 | 4192.61 | 2275.90 |
总计 | 11235.10 | 6508.58 |
多数数据首先拼接为30秒片段(主要保留同一说话人),然后统一推断。50%片段带时间戳训练以确保良好时间戳预测,仅20%片段带上下文训练(因不期望2层解码器擅长此任务)。
模型采用激进数据增强进行了100个epoch的长期训练,评估WER持续下降。部分超参数选择偏向长文本转录。详情参见Distil-Whisper仓库。
所有模型训练均在GENCI的Jean-Zay超算上完成。特别感谢IDRIS团队在项目中的卓越支持。
致谢
- OpenAI开发并开源Whisper模型
- 🤗 Hugging Face在Transformers库中实现Whisper并创建Distil-Whisper
- Genci慷慨提供本项目GPU计算资源



