🚀 Kotoba-Whisper-v2.1
Kotoba-Whisper-v2.1 是基于 kotoba-tech/kotoba-whisper-v2.0 的日语自动语音识别(ASR)模型。它集成了额外的后处理栈,以 pipeline
的形式呈现。新特性包括使用 punctuators 添加标点符号。这些库通过管道合并到 Kotoba-Whisper-v2.1 中,并将无缝应用于 kotoba-tech/kotoba-whisper-v2.0 的预测转录结果。该管道由 Asahi Ushio 和 Kotoba Technologies 合作开发。
✨ 主要特性
📦 安装指南
Kotoba-Whisper-v2.1 从 Hugging Face 🤗 Transformers 库的 4.39 版本开始支持。要运行该模型,首先需要安装最新版本的 Transformers:
pip install --upgrade pip
pip install --upgrade transformers accelerate torchaudio
pip install stable-ts==2.16.0
pip install punctuators==0.0.5
💻 使用示例
基础用法
import torch
from transformers import pipeline
from datasets import load_dataset
model_id = "kotoba-tech/kotoba-whisper-v2.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=True,
+ punctuator=False,
使用 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 {}
📚 详细文档
模型对比
以下表格展示了原始字符错误率(CER)(与通常的 CER 不同,这里在计算指标之前不会去除标点符号,评估脚本见 此处):
关于归一化 CER,由于 v2.1 的更新在归一化过程中会被去除,因此 kotoba-tech/kotoba-whisper-v2.1
的 CER 值与 kotoba-tech/kotoba-whisper-v2.0 相同。
延迟
请参考 kotoba-whisper-v1.1 的延迟部分 此处。
📄 许可证
本项目采用 Apache-2.0 许可证。
致谢