模型库 / openai/whisper-small

whisper-small

openai automatic-speech-recognition transformers en zh de
openai/whisper-small
2,293,475
下载量
556
收藏数
9
浏览量
apache-2.0
许可

简介

Whisper is a pre-trained model for automatic speech recognition (ASR) and speech translation. Trained on 680k hours of labelled data, Whisper models demonstrate a strong ability to generalise to many datasets and domains **without** the need for fine-tuning.

模型卡片

许可协议 apache-2.0
语言
en zh de es ru ko fr ja pt tr pl ca nl ar sv it id hi fi vi he uk el ms cs ro da hu ta no th ur hr bg lt la mi ml cy sk te fa lv bn sr az sl kn et mk br eu is hy ne mn bs kk sq sw gl mr pa si km sn yo so af oc ka be tg sd gu am yi lo uz fo ht ps tk nn mt sa lb my bo tl mg as tt haw ln ha ba jw su
任务 automatic-speech-recognition
audio automatic-speech-recognition hf-asr-leaderboard

模型配置

模型类型 whisper
架构 WhisperForConditionalGeneration

模型详情

已翻译

Whisper

Whisper 是一个用于自动语音识别(ASR)和语音翻译的预训练模型。该模型在 68 万小时的标注数据上训练而成,展现出强大的泛化能力,能够适应多种数据集和领域,无需进行微调。

Whisper 由 OpenAI 的 Alec Radford 等人在论文 Robust Speech Recognition via Large-Scale Weak Supervision 中提出。原始代码仓库可在此处找到。

免责声明:本模型卡片的部分内容由 Hugging Face 团队撰写,部分内容复制并粘贴自原始模型卡片。

模型详情

Whisper 是一个基于 Transformer 的 encoder-decoder 模型,也被称为 sequence-to-sequence 模型。该模型在 68 万小时的标注语音数据上训练而成,这些数据通过大规模弱监督方法进行标注。

模型分为仅英语数据训练和多语言数据训练两种。仅英语模型在语音识别任务上训练。多语言模型则在语音识别和语音翻译两个任务上训练。对于语音识别,模型预测与音频相同语言的转录文本。对于语音翻译,模型预测与音频不同语言的转录文本。

Whisper checkpoints 提供五种不同模型大小的配置。最小的四种配置分别基于仅英语数据或多语言数据训练。最大的 checkpoints 仅支持多语言。所有十个预训练 checkpoints 均可在 Hugging Face Hub 上获取。以下表格总结了各 checkpoints 及其在 Hub 上的模型链接:

大小 参数量 仅英语 多语言
tiny 39 M
base 74 M
small 244 M
medium 769 M
large 1550 M x
large-v2 1550 M x

使用方法

要转录音频样本,模型需要与 WhisperProcessor 配合使用。

WhisperProcessor 用于:
1. 预处理音频输入(将其转换为模型所需的 log-Mel 频谱图)
2. 后处理模型输出(将 token 转换为文本)

通过传递相应的“上下文 tokens”,模型可以获知要执行的任务(转录或翻译)。这些上下文 tokens 是在解码过程开始时提供给 decoder 的一系列 tokens,其顺序如下:
1. 转录始终以 token 开始 2. 第二个 token 是语言 token(例如英语为
3. 第三个 token 是“任务 token”。它可以是两个值之一:表示语音识别, 表示语音翻译
4. 此外,如果模型不应包含时间戳预测,则会添加 `` token

因此,典型的上下文 tokens 序列可能如下所示:


这告诉模型以英语解码,执行语音识别任务,并且不预测时间戳。

这些 tokens 可以是强制性的或非强制性的。如果是强制性的,模型必须在每个位置预测每个 token。这允许用户控制 Whisper 模型的输出语言和任务。如果是非强制性的,Whisper 模型将自动预测输出语言和任务。

上下文 tokens 可以按如下方式设置:

model.config.forced_decoder_ids = WhisperProcessor.get_decoder_prompt_ids(language="english", task="transcribe")

这将强制模型以英语执行语音识别任务进行预测。

转录

英语到英语

在此示例中,上下文 tokens 是“非强制性的”,意味着模型自动预测输出语言(英语)和任务(转录)。

>>> from transformers import WhisperProcessor, WhisperForConditionalGeneration
>>> from datasets import load_dataset

>>> # load model and processor
>>> processor = WhisperProcessor.from_pretrained("openai/whisper-small")
>>> model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
>>> model.config.forced_decoder_ids = None

>>> # load dummy dataset and read audio files
>>> 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 

>>> # generate token ids
>>> predicted_ids = model.generate(input_features)
>>> # decode token ids to text
>>> transcription = processor.batch_decode(predicted_ids, skip_special_tokens=False)
[' Mr. Quilter is the apostle of the middle classes and we are glad to welcome his gospel.']

>>> 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.']

通过设置 skip_special_tokens=True,可以从转录开头移除上下文 tokens。

法语到法语

以下示例通过设置 decoder id 演示了法语到法语的转录。

标签

tf jax whisper audio hf-asr-leaderboard en zh de

操作


详细信息

厂商
openai
任务
automatic-speech-recognition
框架
transformers
模型类型
whisper
许可(HF)
apache-2.0
语言
en, zh, de, es, ru, ko, fr, ja, pt, tr, pl, ca, nl, ar, sv, it, id, hi, fi, vi, he, uk, el, ms, cs, ro, da, hu, ta, no, th, ur, hr, bg, lt, la, mi, ml, cy, sk, te, fa, lv, bn, sr, az, sl, kn, et, mk, br, eu, is, hy, ne, mn, bs, kk, sq, sw, gl, mr, pa, si, km, sn, yo, so, af, oc, ka, be, tg, sd, gu, am, yi, lo, uz, fo, ht, ps, tk, nn, mt, sa, lb, my, bo, tl, mg, as, tt, haw, ln, ha, ba, jw, su