语言:
- 英语
- 中文
- 德语
- 西班牙语
- 俄语
- 韩语
- 法语
- 日语
- 葡萄牙语
- 土耳其语
- 波兰语
- 加泰罗尼亚语
- 荷兰语
- 阿拉伯语
- 瑞典语
- 意大利语
- 印尼语
- 印地语
- 芬兰语
- 越南语
- 希伯来语
- 乌克兰语
- 希腊语
- 马来语
- 捷克语
- 罗马尼亚语
- 丹麦语
- 匈牙利语
- 泰米尔语
- 挪威语
- 泰语
- 乌尔都语
- 克罗地亚语
- 保加利亚语
- 立陶宛语
- 拉丁语
- 毛利语
- 马拉雅拉姆语
- 威尔士语
- 斯洛伐克语
- 泰卢固语
- 波斯语
- 拉脱维亚语
- 孟加拉语
- 塞尔维亚语
- 阿塞拜疆语
- 斯洛文尼亚语
- 卡纳达语
- 爱沙尼亚语
- 马其顿语
- 布列塔尼语
- 巴斯克语
- 冰岛语
- 亚美尼亚语
- 尼泊尔语
- 蒙古语
- 波斯尼亚语
- 哈萨克语
- 阿尔巴尼亚语
- 斯瓦希里语
- 加利西亚语
- 马拉地语
- 旁遮普语
- 僧伽罗语
- 高棉语
- 绍纳语
- 约鲁巴语
- 索马里语
- 南非荷兰语
- 奥克语
- 格鲁吉亚语
- 白俄罗斯语
- 塔吉克语
- 信德语
- 古吉拉特语
- 阿姆哈拉语
- 意第绪语
- 老挝语
- 乌兹别克语
- 法罗语
- 海地克里奥尔语
- 普什图语
- 土库曼语
- 新挪威语
- 马耳他语
- 梵语
- 卢森堡语
- 缅甸语
- 藏语
- 他加禄语
- 马尔加什语
- 阿萨姆语
- 鞑靼语
- 夏威夷语
- 林加拉语
- 豪萨语
- 巴什基尔语
- 爪哇语
- 巽他语
标签:
- 音频
- 自动语音识别
- hf-asr排行榜
小部件:
- 示例标题: Librispeech样本1
来源: https://cdn-media.huggingface.co/speech_samples/sample1.flac
- 示例标题: Librispeech样本2
来源: https://cdn-media.huggingface.co/speech_samples/sample2.flac
管道标签: 自动语音识别
许可证: apache-2.0
Whisper
Whisper是一个预训练的自动语音识别(ASR)和语音翻译模型。经过68万小时标注数据的训练,Whisper模型展现出强大的泛化能力,无需微调即可适应多种数据集和领域。
Whisper由OpenAI的Alec Radford等人在论文通过大规模弱监督实现鲁棒语音识别中提出。原始代码仓库可在此处找到。
与Whisper大模型相比,large-v2版本增加了2.5倍的训练周期并引入正则化以提升性能。
免责声明: 本模型卡内容部分由Hugging Face团队撰写,部分内容复制自原始模型卡。
模型详情
Whisper是基于Transformer的编码器-解码器模型,也称为序列到序列模型。它使用大规模弱监督标注的68万小时语音数据进行训练。
模型分为仅英语数据和多语言数据训练版本。仅英语模型专用于语音识别任务,多语言模型则同时训练语音识别和语音翻译能力。语音识别时,模型预测与音频相同语言的文本;语音翻译时,预测与音频不同语言的文本。
Whisper提供五种不同规模的预训练配置,其中四种小规模模型有英语专用和多语言版本,最大模型仅有多语言版本。所有预训练模型均可在Hugging Face Hub获取,具体如下:
规模 |
参数量 |
仅英语版本 |
多语言版本 |
tiny |
39 M |
✓ |
✓ |
base |
74 M |
✓ |
✓ |
small |
244 M |
✓ |
✓ |
medium |
769 M |
✓ |
✓ |
large |
1550 M |
x |
✓ |
large-v2 |
1550 M |
x |
✓ |
使用指南
进行音频转录时,需配合WhisperProcessor
使用。该处理器负责:
- 音频预处理(转换为对数梅尔频谱)
- 后处理(将标记解码为文本)
模型通过"上下文标记"识别任务类型(转录/翻译),这些标记在解码开始时输入解码器,顺序如下:
- 起始标记
<|startoftranscript|>
- 语言标记(如
<|en|>
表示英语)
- 任务标记:
<|transcribe|>
(语音识别)或<|translate|>
(语音翻译)
- 可选添加
<|notimestamps|>
标记以禁止时间戳预测
典型上下文标记序列示例:
<|startoftranscript|> <|en|> <|transcribe|> <|notimestamps|>
表示要求模型执行英语语音识别且不预测时间戳。
可通过以下代码强制指定语言和任务:
model.config.forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="english", task="transcribe")
转录示例
英语转录(自动检测)
>>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
>>> from datasets import load_dataset
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
>>> model.config.forced_decoder_ids = None
>>> ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
>>> sample = ds[0]["audio"]
>>> input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
>>> predicted_ids = model.generate(input_features)
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.']
法语转录(强制指定)
>>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="transcribe")
>>> ds = load_dataset("common_voice", "fr", split="test", streaming=True)
>>> input_speech = next(iter(ds))["audio"]
>>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' Un vrai travail intéressant va enfin être mené sur ce sujet.']
翻译示例
法语译英语
>>> forced_decoder_ids = processor.get_decoder_prompt_ids(language="french", task="translate")
>>> predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids)
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
[' A very interesting work, we will finally be given on this subject.']
评估
在LibriSpeech test-clean数据集上的评估示例:
>>> wer = load("wer")
>>> print(100 * wer.compute(references=result["reference"], predictions=result["prediction"]))
3.0003583080317572
长音频转录
通过分块处理技术(设置chunk_length_s=30
),可转录任意长度音频:
>>> pipe = pipeline("automatic-speech-recognition", model="openai/whisper-large-v2", chunk_length_s=30)
>>> prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
[{'text': ' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.',
'timestamp': (0.0, 5.44)}]
微调
虽然预训练模型已展现强大泛化能力,但通过微调可进一步提升特定语言和任务的表现。参考博客使用🤗 Transformers微调Whisper获取详细指南。
使用限制
主要用户为研究模型鲁棒性、泛化能力的AI研究人员。开发者也可将其作为英语ASR解决方案,但需注意:
- 不建议未经许可录制并转录个人语音
- 高风险决策场景慎用
- 分类任务未经评估且不适用
- 不同语言/口音表现存在差异
训练数据
68万小时互联网音频数据构成:
- 65%英语音频+英语文本
- 18%非英语音频+英语文本
- 17%非英语音频+对应语言文本(覆盖98种语言)
性能与局限
优势:
- 对口音/背景噪声/专业术语的鲁棒性
- 多语言到英语的零样本翻译
- 接近SOTA的识别准确率
局限:
- 可能产生幻听文本
- 低资源语言表现较差
- 存在人口统计学差异
- 可能生成重复文本
社会影响
积极方面:
潜在风险:
- 可能被用于监控技术
- 存在双重用途隐患
- 不同群体间的性能差异可能带来经济影响
引用信息
@misc{radford2022whisper,
doi = {10.48550/ARXIV.2212.04356},
url = {https://arxiv.org/abs/2212.04356},
author = {Radford, Alec and Kim, Jong Wook and Xu, Tao and Brockman, Greg and McLeavey, Christine and Sutskever, Ilya},
title = {Robust Speech Recognition via Large-Scale Weak Supervision},
publisher = {arXiv},
year = {2022},
copyright = {arXiv.org perpetual, non-exclusive license}
}