语言:
- 中文
- 粤语
许可证: Apache-2.0
标签:
- whisper-event
- 基于训练器生成
基础模型: openai/whisper-small
数据集:
- mozilla-foundation/common_voice_16_0
- mozilla-foundation/common_voice_17_0
模型索引:
- 名称: Whisper Small 粤语版 - Alvin
结果:
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: mozilla-foundation/common_voice_16_0 粤语
类型: mozilla-foundation/common_voice_16_0
配置: yue
拆分: test
参数: yue
指标:
- 名称: 标准化字符错误率
类型: cer
值: 7.93
Whisper Small 粤语版 - Alvin
该模型是基于openai/whisper-small在粤语上微调的版本。在Common Voice 16.0测试集上,其标准化字符错误率(不含标点)为7.93,含标点为9.72。
训练与评估数据
训练数据来源:
- CantoMap: Winterstein, Grégoire, Tang, Carmen和Lai, Regine (2020) "CantoMap: 香港粤语地图任务语料库",发表于《第12届语言资源与评估会议论文集》
- Cantonese-ASR: Yu, Tiezheng等学者(2022) "粤语自动语音识别数据集综述与新数据集",论文链接:https://arxiv.org/pdf/2201.02419.pdf
数据名称 |
时长(小时) |
Common Voice 16.0 粤语训练集 |
138 |
Common Voice 16.0 粤语训练集 |
85 |
Common Voice 17.0 粤语训练集 |
178 |
Cantonese-ASR |
72 |
CantoMap |
23 |
伪标注YouTube数据 |
438 |
评估使用Common Voice 16.0粤语测试集。
性能表现
- 字符错误率(CER,越低越好): 0.0972
- 去除标点的CER: 0.0793
- GPU推理速度(使用快速注意力机制): 0.055秒/样本
- 常规GPU推理: 0.308秒/样本
- CPU推理: 2.57秒/样本
- GPU显存占用: ~1.5GB
使用指南
import librosa
import torch
from transformers import WhisperForConditionalGeneration, WhisperProcessor
y, sr = librosa.load('audio.mp3', sr=16000)
MODEL_NAME = "alvanlii/whisper-small-cantonese"
processor = WhisperProcessor.from_pretrained(MODEL_NAME)
model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME)
processed_in = processor(y, sampling_rate=sr, return_tensors="pt")
gout = model.generate(
input_features=processed_in.input_features,
output_scores=True, return_dict_in_generate=True
)
transcription = processor.batch_decode(gout.sequences, skip_special_tokens=True)[0]
print(transcription)
或使用HuggingFace管道:
from transformers import pipeline
MODEL_NAME = "alvanlii/whisper-small-cantonese"
pipe = pipeline(
task="automatic-speech-recognition",
model=MODEL_NAME,
chunk_length_s=30,
device=device,
)
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language="zh", task="transcribe")
text = pipe(audio_file)["text"]
模型加速
添加attn_implementation="sdpa"参数启用Flash Attention:
model = AutoModelForSpeechSeq2Seq.from_pretrained(
"alvanlii/whisper-small-cantonese",
attn_implementation="sdpa",
)
使用Flash Attention后,单样本处理时间从0.308秒降至0.055秒。
推测性解码
可结合大模型进行加速推理:
model = AutoModelForSpeechSeq2Seq.from_pretrained(
"simonl0909/whisper-large-v2-cantonese",
attn_implementation="sdpa",
)
assistant_model = AutoModelForSpeechSeq2Seq.from_pretrained(
"alvanlii/whisper-small-cantonese",
attn_implementation="sdpa",
)
model.generate(..., assistant_model=assistant_model)
原大模型推理速度为0.714秒/样本(CER 7.65),使用推测性解码后降至0.137秒/样本(CER 7.67)。
Whisper.cpp支持
已提供GGML格式模型文件(2024年6月更新),可从此处下载。
CT2格式转换
如需在WhisperX或FasterWhisper中使用,转换后的模型文件存放于此处。
训练超参数
- 学习率: 5e-5
- 训练批次大小: 25(单张3090显卡)
- 梯度累积步数: 4
- 实际总批次大小: 100
- 优化器: Adam (beta1=0.9, beta2=0.999, epsilon=1e-08)
- 学习率调度: 线性预热(500步)
- 总训练步数: 15000
- 数据增强: 未使用