🚀 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 許可證。
致謝