IBM Granite Speech 5.0 2B

Reddit r/LocalLLaMA 模型

摘要

IBM 发布了 Granite Speech 5.0 2B,这是一款紧凑的多语言语音语言模型,支持六种语言的语音识别(ASR)和语音翻译,相比前代产品提升了噪声鲁棒性、语言识别提示(language-ID prompting)能力,并支持多达 2000 个关键词的偏置引导。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/10/21 16:26

ibm-granite/granite-speech-5.0-2b · Hugging Face

来源:https://huggingface.co/ibm-granite/granite-speech-5.0-2b

模型概述: Granite Speech 5.0 2B 是一款紧凑且高效的语音-语言模型,专为多语言自动语音识别(ASR)以及英语、法语、德语、西班牙语、葡萄牙语和日语的双向自动语音翻译(AST)而设计。该模型在 39 万小时的音频上训练,数据来自用于 ASR 和 AST 的公开语料库,以及为日语 ASR、关键词偏置 ASR 和语音翻译量身定制的合成数据集。Granite Speech 5.0 2B 通过模态对齐训练而成,以 granite-4.0-1b-base 的中间检查点为起点,在包含音频输入与文本目标的公开开源语料上对齐到语音。

与前代模型 granite-speech-4.1-2b 相比,该模型参数量相同,但提供了额外能力和改进:

  • 英语短音频 ASR 的转写准确率更高,对噪声、混响和远场麦克风语音的鲁棒性更强
  • 支持输入语言 ID 提示,实现多语言 ASR
  • 改进了长音频与对话式语音翻译
  • 多语言关键词偏置 ASR 和 AST 的关键词列表容量提升(最多 2000 条)

评测: 我们在 Open ASR leaderboard 上的标准英语 ASR 基准测试中评测了 granite-speech-5.0-2b(截至 2026 年 10 月 20 日的官方结果): granite-5.0-2b-vs-open-english

在 FFASR leaderboard 上的噪声与混响语音性能评测(截至 2026 年 10 月 18 日的官方结果): granite-speech-5.0-2b-ffasr-wer

我们还将该模型与其他语音-语言模型以及专用 ASR、AST 系统在 CommonVoice 上进行了多语言 ASR 评测,并评测了 X→En(CoVoST)和 En→X(FLEURS)自动语音翻译: granite-speech-5.0-2b-wer-cv granite-speech-5.0-2b-bleu-x-en granite-speech-5.0-2b-bleu-en-x

我们通过对比推理阶段应用与不应用关键词列表偏置(KWB)时的性能,评测了模型的关键词列表偏置(KWB)能力。我们报告 ASR 任务中所转写关键词的 F1 分数,评测时排除常见词。 granite-speech-5.0-2b-kwb-f1

我们还在多种语料上评测了模型的标点与大小写能力。指标采用 LibriSpeech-PC 中的定义。PER(标点错误率)衡量标点符号(句号、逗号和问号)在插入、删除或替换上的错误。Cap-F1(大小写 F1)衡量模型在输出中对相关单词进行正确大写的准确程度。请注意,我们的 Cap-F1 是基于 Levenshtein 对齐的匹配词对计算的,而非完全匹配的句子,因此即使存在 ASR 错误也能进行评测。

测试集PER 4.1-2b (↓)PER 5.0-2b (↓)Cap-F1 4.1-2b (↑)Cap-F1 5.0-2b (↑)
LScln25.7023.2089.7190.16
LSoth22.2721.2291.2691.65
VoxPopuli24.8623.7095.3595.07
Earnings-2222.8721.6495.1994.98
CV-EN9.139.1896.7596.96
CV-DE†3.663.6599.5099.51
CV-ES11.6111.4695.6895.62
CV-FR11.0011.4397.2597.20
CV-PT7.867.5398.5198.48

†我们在德语上报告了 99.51 的 Cap-F1,德语中名词需要大写。

发布日期:2026 年 10 月 20 日

许可证: Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0)

支持语言: 英语、法语、德语、西班牙语、葡萄牙语、日语

预期用途: 该模型旨在用于涉及语音输入处理的企业级应用。特别地,它非常适合英语、法语、德语、西班牙语、葡萄牙语和日语的语音转文本,以及这些语言与英语之间的语音翻译,另外还支持英语→意大利语和英语→普通话的翻译。

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#usage

用法:Granite Speech 模型在 transformers>=4.52.1 中获得原生支持。为获得最佳效果,请将音频按每段最多约 2 分钟的片段进行转写;在解码前先拆分更长的录音(例如使用 VAD)。

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#usage-with-transformers

配合 transformers 使用

首先确保安装了较新版本的 transformers:

pip install transformers torchaudio soundfile

然后运行以下代码:

import torch
import torchaudio
from huggingface_hub import hf_hub_download
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor

device = "cuda" if torch.cuda.is_available() else "cpu"
model_name = "ibm-granite/granite-speech-5.0-2b"

processor = AutoProcessor.from_pretrained(model_name)
tokenizer = processor.tokenizer
model = AutoModelForSpeechSeq2Seq.from_pretrained(
    model_name,
    device_map=device,
    torch_dtype=torch.bfloat16
)

# 加载音频
audio_path = hf_hub_download(repo_id=model_name, filename="multilingual_sample.wav")
wav, sr = torchaudio.load(audio_path, normalize=True)
assert wav.shape[0] == 1 and sr == 16000  # 单声道,16kHz

# 创建文本提示
user_prompt = "<|audio|>transcribe the speech with proper punctuation and capitalization."

chat = [
    {"role": "user", "content": user_prompt},
]
prompt = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)

# 运行 processor + 模型
model_inputs = processor(prompt, wav, device=device, return_tensors="pt").to(device)
model_outputs = model.generate(
    **model_inputs,
    max_new_tokens=200,
    do_sample=False,
    num_beams=1
)

# Transformers 会在响应中包含输入 ID
num_input_tokens = model_inputs["input_ids"].shape[-1]
new_tokens = model_outputs[0, num_input_tokens:].unsqueeze(0)

output_text = tokenizer.batch_decode(
    new_tokens,
    add_special_tokens=False,
    skip_special_tokens=True
)

print(f"STT output = {output_text[0]}")

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#usage-with-vllm

配合 vLLM 使用

首先确保安装了 vLLM:

pip install vllm
  • 离线模式代码:
from transformers import AutoTokenizer
from vllm import LLM, SamplingParams
from vllm.assets.audio import AudioAsset

model_id = "ibm-granite/granite-speech-5.0-2b"
tokenizer = AutoTokenizer.from_pretrained(model_id)

def get_prompt(question: str, has_audio: bool):
    """构建发送给 vLLM 的输入提示。"""
    if has_audio:
        question = f"<|audio|>{question}"

    chat = [
        {
            "role": "user",
            "content": question
        }
    ]
    return tokenizer.apply_chat_template(chat, tokenize=False)

model = LLM(
    model=model_id,
    max_model_len=2048,  # 对于资源较低的设备可能需要此项。
    limit_mm_per_prompt={"audio": 1},
)

question = "can you transcribe the speech into a written format?"
prompt_with_audio = get_prompt(
    question=question,
    has_audio=True,
)
audio = AudioAsset("mary_had_lamb").audio_and_sample_rate

inputs = {
    "prompt": prompt_with_audio,
    "multi_modal_data": {
        "audio": audio,
    }
}
outputs = model.generate(
    inputs,
    sampling_params=SamplingParams(
        temperature=0.0,
        max_tokens=64,
    ),
)

print(f"Audio Example - Question: {question}")
print(f"Generated text: {outputs[0].outputs[0].text}")
  • 在线模式代码:
"""
使用以下命令启动 vLLM 服务器:
vllm serve ibm-granite/granite-speech-5.0-2b \
    --api-key token-abc123 \
    --max-model-len 2048
"""

import base64
import requests
from openai import OpenAI
from vllm.assets.audio import AudioAsset

# 修改 OpenAI 的 API key 和 API base 以使用 vLLM 的 API 服务器。
openai_api_key = "token-abc123"
openai_api_base = "http://localhost:8000/v1"

client = OpenAI(
    # 默认为 os.environ.get("OPENAI_API_KEY")
    api_key=openai_api_key,
    base_url=openai_api_base,
)

model_name = "ibm-granite/granite-speech-5.0-2b"
# librosa 支持的任何格式均可使用
audio_url = AudioAsset("mary_had_lamb").url

# 在请求体中使用 base64 编码的音频
def encode_audio_base64_from_url(audio_url: str) -> str:
    """将从远程 URL 获取的音频编码为 base64 格式。"""
    with requests.get(audio_url) as response:
        response.raise_for_status()
        result = base64.b64encode(response.content).decode("utf-8")
    return result

audio_base64 = encode_audio_base64_from_url(audio_url=audio_url)

question = "can you transcribe the speech into a written format?"

chat_completion_with_audio = client.chat.completions.create(
    messages=[{
        "role": "user",
        "content": [
            {
                "type": "text",
                "text": question
            },
            {
                "type": "audio_url",
                "audio_url": {
                    # librosa 支持的任何格式均可使用
                    "url": f"data:audio/ogg;base64,{audio_base64}"
                },
            },
        ],
    }],
    temperature=0.0,
    max_tokens=64,
    model=model_name,
)

print(f"Audio Example - Question: {question}")
print(f"Generated text: {chat_completion_with_audio.choices[0].message.content}")

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#usage-with-llamacpp

配合 llama.cpp 使用

在 macOS 上使用 homebrew 的安装说明:

brew install llama.cpp
  • 离线模式:
llama-cli -st -hf ibm-granite/granite-speech-5.0-2b-GGUF:Q8_0 --audio "audio.wav" -p "transcribe the speech with proper punctuation and capitalization."
  • 在线模式:
llama-server -hf ibm-granite/granite-speech-5.0-2b-GGUF:Q8_0 --port 9797

然后发起请求:

curl http://localhost:9797/v1/audio/transcriptions -F "model=ibm-granite/granite-speech-5.0-2b-GGUF:Q8_0" -F "[email protected]" -F "prompt=transcribe the speech with proper punctuation and capitalization." | jq -r .text

我们推荐使用 Q8_0,在我们的测试中它与未量化模型效果相当;更低比特的量化在超过约一分钟的音频上会损失精度。

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#usage-with-mlx-audio-for-apple-silicon-m-series-chips

在 Apple Silicon M 系列芯片上配合 mlx-audio 使用

安装较新版本的 mlx-audio(0.5.9 或更高)以及 jinja2——mlx-audio 在使用聊天模板时需要 jinja2,但它自身不会安装:

pip install -U mlx-audio jinja2

使用示例:

python -m mlx_audio.stt.generate --model ibm-granite/granite-speech-5.0-2b --verbose --audio "audio.wav" --output-path "transcript"

各任务推荐提示词:

任务提示词说明
ASR(原始转写)can you transcribe the speech into a written format?支持多语言提示,例如 Pouvez‐vous reconnaître le contenu de la parole ?
ASR(带标点)transcribe the speech with proper punctuation and capitalization.支持多语言提示,例如 Transcrivez la parole avec une ponctuation et des majuscules appropriées.
ASR(带关键词偏置)transcribe the speech to text. Keywords: , , ...支持多语言提示,例如 ¿Puedes transcribir el habla en formato escrito? Palabras clave: , , ...
ASR(带语言 ID)The speech is in . Transcribe it exactly; do not translate. can you transcribe the speech into a written format?可填 English、French、German、Spanish、Portuguese、Japanese。也支持以其他语言书写提示并用该语言指明语种,例如 El audio esta en alemán. Transcribe exactamente; no traduzcas. ¿Puedes transcribir el habla en formato escrito? 或 ドイツ語の音声です。翻訳せず、聞こえた通りに文字に起こしてください。音声を文字に起こしてください。
AST(原始转写)translate the speech to .可填 English、French、German、Spanish、Japanese、Italian、Mandarin。支持多语言提示,例如 Écoutez la parole et traduisez-la en anglais.
AST(带标点)translate the speech to with proper punctuation and capitalization.仅支持英文提示
AST(带关键词偏置)translate the speech to . Keywords: , , ...支持多语言提示,例如 Escucha el habla y tradúcela a inglés. Palabras clave: , , ...

模型架构: granite-speech-5.0-2b 的架构由以下组件构成:

(1) 语音编码器:16 个 conformer 块,采用连接时序分类(CTC)训练,配有两个分类头(字符和 BPE 单元),训练数据为仅包含无标点转写 ASR 语料的子集(配置见下表)。字符词表由面向欧洲语言的前 256 个 ASCII 条目,加上用于日语的 92 个语音片假名字符集组成,而 BPE 单元则来自 granite 4.0 分词器。此外,我们的 CTC 编码器使用块注意力(4 秒音频块),以及来自中间层的自条件化 CTC。中间层还提供非空白概率,用于 BPE 分类的帧级后验加权池化,窗口大小为 4。

配置参数值
输入维度160(80 logmels × 2)
层数16
隐藏维度1024
注意力头数8
注意力头大小128
卷积核大小15
输出维度(字符)348
输出维度(BPE)100353

(2) 语音投影器与时域下采样器(语音-文本模态适配器):我们使用一个 2 层的窗口查询 Transformer(q-former),处理来自语音编码器最后一个 conformer 块输出的、由 15 个 1024 维声学嵌入组成的块,每个块、每层使用 3 个可训练查询,以 5 倍因子进行下采样。总时域下采样倍数为 10(编码器 2 倍,投影器 5 倍),使 LLM 获得 10Hz 的声学嵌入速率。投影器和 LLM 的 LoRA 适配器是在训练数据中提到的所有语料上联合训练的。

(3) 大语言模型:granite-4.0-1b-base 的中间检查点,通过 YaRN 扩展到 16k 位置(https://huggingface.co/ibm-granite/granite-4.0-1b-base),并在训练数据中提到的所有语料上进行了微调。

https://huggingface.co/ibm-granite/granite-speech-5.0-2b#training-data

训练数据: 总体而言,我们的训练数据主要由两个关键来源构成: (1) 公开可用的数据集 (2) 基于公开数据集创建的合成数据,专门针对日语 ASR、带标点及书面形式的 ASR、多说话人与上下文 ASR、关键词列表提示的 ASR 和 AST,以及语音翻译任务。

训练数据集的详细说明见下表:

名称任务小时数来源
CommonVoice-17 En, De, Es, Fr, Pt, JaASR5500https://huggingface.co/datasets/mozilla-foundation/common_voice_17_0
MLS En, De, Es, Fr, PtASR48400https://huggingface.co/datasets/facebook/multilingual_librispeech
Librispeech EnglishASR1000https://huggingface.co/datasets/openslr/librispeech_asr
LibriHeavy Large EnglishASR45600https://huggingface.co/datasets/anyspeech/libri-heavy
VoxPopuli En, De, Fr, EsASR1100https://huggingface.co/datasets/facebook/voxpopuli
VoxPopuli Granary EnglishASR24000https://huggingface.co/datasets/nvidia/Granary
AMI EnglishASR150https://huggingface.co/datasets/edinburghcstr/ami
YODAS EnglishASR9100https://huggingface.co/datasets/espnet/yodas
YODAS JapaneseASR1400https://huggingface.co/datasets/espnet/yodas
YODAS Granary En, De, Es, Fr, It, Pt(长音频,最长 120 秒)ASR4900https://huggingface.co/datasets/nvidia/Granary
Earnings-22 EnglishASR105https://huggingface.co/datasets/esb/datasets
Switchboard EnglishASR260https://cat

相似文章

Granite Switch 4.1:一个端点实现聊天、决策与语音能力

Hugging Face Blog

IBM 推出 Granite Switch 4.1(8B 与 30B),通过 aLoRA 适配器在同一端点上组合聊天、决策与语音转写能力,几乎不额外占用 VRAM。新增 Decision 与 Guardian aLoRA,并嵌入 OpenASR 榜单最快的 Granite-Speech-5.0-Turbo-CTC 模型。