模型概述
模型特點
模型能力
使用案例
🚀 Kotoba-Whisper-v1.1
Kotoba-Whisper-v1.1 是一個基於日語的自動語音識別(ASR)模型。它在 kotoba-tech/kotoba-whisper-v1.0 的基礎上,通過集成額外的後處理棧作為 pipeline
來增強功能,例如使用 punctuators 添加標點符號。該模型由 Asahi Ushio 和 Kotoba Technologies 合作開發。
✨ 主要特性
- 基於 kotoba-tech/kotoba-whisper-v1.0 模型,集成額外後處理棧。
- 可以通過 punctuators 為預測轉錄結果添加標點符號。
- 支持 Hugging Face 🤗 Transformers 庫從 4.39 版本起的使用。
📦 安裝指南
Kotoba-Whisper-v1.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
如果你想使用 Flash-Attention 2,需要先安裝 Flash Attention:
pip install flash-attn --no-build-isolation
💻 使用示例
基礎用法
該模型可以使用 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=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。要使用它,需要在 from_pretrained
中傳入 attn_implementation="flash_attention_2"
:
- 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 不同,具體評估腳本可查看 此處:
模型 | 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 輸出的標點符號和時間戳。然而,由於需要對每個塊應用標點符號器和 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 |
完整表格可查看 此處。
🔧 技術細節
Kotoba-Whisper-v1.1 基於 kotoba-tech/kotoba-whisper-v1.0 模型,通過集成額外的後處理棧作為 pipeline
來增強功能。具體來說,使用了 punctuators 庫來為預測轉錄結果添加標點符號。這些庫通過管道合併到 Kotoba-Whisper-v1.1 中,並將無縫應用於 kotoba-tech/kotoba-whisper-v1.0 的預測轉錄結果。
📄 許可證
本項目採用 Apache-2.0 許可證。
致謝
- OpenAI 提供了 Whisper 模型。
- Hugging Face 🤗 Transformers 實現了模型集成。
- Hugging Face 🤗 提供了 Distil-Whisper 代碼庫。
- Reazon Human Interaction Lab 提供了 ReazonSpeech 數據集。



