模型简介
模型特点
模型能力
使用案例
语言: 日语
库名称: transformers
许可证: apache-2.0
标签:
- 音频
- 自动语音识别
- hf-asr-leaderboard
小部件: - 示例标题: CommonVoice 8.0 (测试分割)
来源: >-
https://huggingface.co/datasets/japanese-asr/ja_asr.common_voice_8_0/resolve/main/sample.flac - 示例标题: JSUT Basic 5000
来源: >-
https://huggingface.co/datasets/japanese-asr/ja_asr.jsut_basic5000/resolve/main/sample.flac - 示例标题: ReazonSpeech (测试分割)
来源: >-
https://huggingface.co/datasets/japanese-asr/ja_asr.reazonspeech_test/resolve/main/sample.flac
管道标签: 自动语音识别
数据集: - japanese-asr/whisper_transcriptions.reazonspeech.large
- japanese-asr/whisper_transcriptions.reazonspeech.large.wer_10.0
- japanese-asr/whisper_transcriptions.reazonspeech.large.wer_10.0.vectorized
Kotoba-Whisper-v1.1
Kotoba-Whisper-v1.1 是基于 kotoba-tech/kotoba-whisper-v1.0 的日语自动语音识别(ASR)模型,集成了额外的后处理栈作为 pipeline
。新功能包括使用 punctuators 添加标点符号。这些库通过管道集成到 Kotoba-Whisper-v1.1 中,并将无缝应用于 kotoba-tech/kotoba-whisper-v1.0 的预测转录结果。该管道由 Asahi Ushio 和 Kotoba Technologies 合作开发。
下表展示了原始字符错误率(CER)(与通常去除标点符号后计算的 CER 不同,详见评估脚本 此处)及其对比。
模型 | CommonVoice 8 (日语测试集) | JSUT Basic 5000 | ReazonSpeech (保留测试集) |
---|---|---|---|
kotoba-tech/kotoba-whisper-v2.0 | 17.6 | 15.4 | 17.4 |
kotoba-tech/kotoba-whisper-v2.1 | 17.7 | 15.4 | 17 |
kotoba-tech/kotoba-whisper-v1.0 | 17.8 | 15.2 | 17.8 |
kotoba-tech/kotoba-whisper-v1.1 | 17.9 | 15 | 17.8 |
openai/whisper-large-v3 | 15.3 | 13.4 | 20.5 |
openai/whisper-large-v2 | 15.9 | 10.6 | 34.6 |
openai/whisper-large | 16.6 | 11.3 | 40.7 |
openai/whisper-medium | 17.9 | 13.1 | 39.3 |
openai/whisper-base | 34.5 | 26.4 | 76 |
openai/whisper-small | 21.5 | 18.9 | 48.1 |
openai/whisper-tiny | 58.8 | 38.3 | 153.3 |
关于归一化 CER,由于 v1.1 的更新会被归一化过程移除,kotoba-tech/kotoba-whisper-v1.1 的 CER 值与 kotoba-tech/kotoba-whisper-v1.0 相同。
延迟
Kotoba-whisper-v1.1 改进了 Kotoba-whisper-v1.0 输出的标点符号和时间戳。然而,由于我们对每个片段应用 punctuator 和 stable-ts,需要获取时间戳,这会降低原始 kotoba-whisper-v1.0 的延迟。下表比较了转录 50 分钟 日语语音音频的推理速度,报告了五次独立运行的平均值。
模型 | return_timestamps | 时间(平均值) |
---|---|---|
kotoba-tech/kotoba-whisper-v1.0 | False | 10.8 |
kotoba-tech/kotoba-whisper-v1.0 | True | 15.7 |
kotoba-tech/kotoba-whisper-v1.1 (punctuator + stable-ts) | True | 17.9 |
kotoba-tech/kotoba-whisper-v1.1 (punctuator) | True | 17.7 |
kotoba-tech/kotoba-whisper-v1.1 (stable-ts) | True | 16.1 |
openai/whisper-large-v3 | False | 29.1 |
openai/whisper-large-v3 | True | 37.9 |
完整表格见 此处。
Transformers 使用
Kotoba-Whisper-v1.1 从 4.39 版本开始支持 Hugging Face 🤗 Transformers 库。要运行模型,首先安装最新版本的 Transformers。
pip install --upgrade pip
pip install --upgrade transformers accelerate torchaudio
pip install stable-ts==2.16.0
pip install punctuators==0.0.5
转录
可以使用 pipeline
类转录音频文件,如下所示:
import torch
from transformers import pipeline
from datasets import load_dataset
# 配置
model_id = "kotoba-tech/kotoba-whisper-v1.1"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
generate_kwargs = {"language": "ja", "task": "transcribe"}
# 加载模型
pipe = pipeline(
model=model_id,
torch_dtype=torch_dtype,
device=device,
model_kwargs=model_kwargs,
batch_size=16,
trust_remote_code=True,
punctuator=True
)
# 加载示例音频
dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
sample = dataset[0]["audio"]
# 运行推理
result = pipe(sample, chunk_length_s=15, return_timestamps=True, generate_kwargs=generate_kwargs)
print(result)
- 要转录本地音频文件,只需在调用管道时传递音频文件路径:
- result = pipe(sample, return_timestamps=True, generate_kwargs=generate_kwargs)
+ result = pipe("audio.mp3", return_timestamps=True, generate_kwargs=generate_kwargs)
- 停用 punctuator:
- punctuator=True,
+ punctuator=False,
带提示的转录
Kotoba-whisper 可以通过提示生成转录,如下所示:
import re
import torch
from transformers import pipeline
from datasets import load_dataset
# 配置
model_id = "kotoba-tech/kotoba-whisper-v1.1"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
device = "cuda:0" if torch.cuda.is_available() else "cpu"
model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
generate_kwargs = {"language": "japanese", "task": "transcribe"}
# 加载模型
pipe = pipeline(
model=model_id,
torch_dtype=torch_dtype,
device=device,
model_kwargs=model_kwargs,
batch_size=16,
trust_remote_code=True
)
# 加载示例音频
dataset = load_dataset("japanese-asr/ja_asr.reazonspeech_test", split="test")
# --- 无提示 ---
text = pipe(dataset[10]["audio"], chunk_length_s=15, generate_kwargs=generate_kwargs)['text']
print(text)
# 81歳、力強い走りに変わってきます。
# --- 带提示 ---: 将 `81` 改为 `91`。
prompt = "91歳"
generate_kwargs['prompt_ids'] = pipe.tokenizer.get_prompt_ids(prompt, return_tensors="pt").to(device)
text = pipe(dataset[10]["audio"], generate_kwargs=generate_kwargs)['text']
# 当前 ASR 管道会在转录开头附加提示,因此需要移除
text = re.sub(rf"\A\s*{prompt}\s*", "", text)
print(text)
# あっぶったでもスルガさん、91歳、力強い走りに変わってきます。
Flash Attention 2
如果 GPU 支持,我们推荐使用 Flash-Attention 2。为此,首先需要安装 Flash Attention:
pip install flash-attn --no-build-isolation
然后传递 attn_implementation="flash_attention_2"
给 from_pretrained
:
- model_kwargs = {"attn_implementation": "sdpa"} if torch.cuda.is_available() else {}
+ model_kwargs = {"attn_implementation": "flash_attention_2"} if torch.cuda.is_available() else {}
致谢
- OpenAI 提供 Whisper 模型。
- Hugging Face 🤗 Transformers 提供模型集成。
- Hugging Face 🤗 提供 Distil-Whisper 代码库。
- Reazon Human Interaction Lab 提供 ReazonSpeech 数据集。



