模型概述
模型特點
模型能力
使用案例
🚀 KB-Whisper Medium
瑞典國家圖書館發佈了一套全新的Whisper模型,這些模型在超過50,000小時的瑞典語語音數據上進行了訓練。在對FLEURS、CommonVoice和NST等數據集的評估中,我們表現最佳的模型與OpenAI的whisper-large-v3
相比,平均將單詞錯誤率(WER)降低了47%。較小尺寸的Whisper模型在瑞典語語音上的性能也有了顯著提升,例如kb-whisper-small
的表現就超過了體積大其六倍的openai/whisper-large-v3
。
✨ 主要特性
- 性能卓越:在多個瑞典語語音數據集評估中,大幅降低單詞錯誤率,小尺寸模型也有出色表現。
- 多格式支持:提供
Hugging Face
、whisper.cpp
(GGML)、onnx
和ctranslate2
等不同格式的檢查點。 - 多種轉錄風格:除默認轉錄風格外,還有更簡潔的
Subtitle
和更逐字的Strict
版本。
📦 安裝指南
文檔未提及安裝步驟,故跳過此章節。
💻 使用示例
基礎用法
以下是使用Hugging Face
調用KB-Whisper
的推理示例:
import torch
from datasets import load_dataset
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
device = "cuda:0" if torch.cuda.is_available() else "cpu"
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
model_id = "KBLab/kb-whisper-medium"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id, torch_dtype=torch_dtype, use_safetensors=True, cache_dir="cache"
)
model.to(device)
processor = AutoProcessor.from_pretrained(model_id)
pipe = pipeline(
"automatic-speech-recognition",
model=model,
tokenizer=processor.tokenizer,
feature_extractor=processor.feature_extractor,
torch_dtype=torch_dtype,
device=device,
)
generate_kwargs = {"task": "transcribe", "language": "sv"}
# Add return_timestamps=True for output with timestamps
res = pipe("audio.mp3",
chunk_length_s=30,
generate_kwargs={"task": "transcribe", "language": "sv"})
print(res)
高級用法
Faster-whisper
Faster-whisper通過使用ctranslate2
重新實現Whisper,提供快速高效的推理:
#### faster-whisper model ####
from faster_whisper import WhisperModel
model_id = "KBLab/kb-whisper-medium"
model = WhisperModel(
model_id,
device="cuda",
compute_type="float16",
download_root="cache", # cache directory
# condition_on_previous_text = False # Can reduce hallucinations if we don't use prompts
)
# Transcribe audio.wav (convert to 16khz mono wav first via ffmpeg)
segments, info = model.transcribe("audio.wav", condition_on_previous_text=False)
print("Detected language '%s' with probability %f" % (info.language, info.language_probability))
for segment in segments:
print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
WhisperX
WhisperX提供了一種方便的方法來獲取準確的單詞級時間戳。該庫將Whisper的文本輸出與Wav2vec2的準確時間戳相結合。以下是如何將KB-Whisper
與KBLab/wav2vec2-large-voxrex-swedish一起使用的示例:
import whisperx
device = "cuda"
audio_file = "audio.wav"
batch_size = 16 # reduce if low on GPU mem
compute_type = "float16" # change to "int8" if low on GPU mem (may reduce accuracy)
# 1. Transcribe with original whisper (batched)
model = whisperx.load_model(
"KBLab/kb-whisper-medium", device, compute_type=compute_type, download_root="cache" # cache_dir
)
audio = whisperx.load_audio(audio_file)
result = model.transcribe(audio, batch_size=batch_size)
print(result["segments"]) # before alignment
# delete model if low on GPU resources
# import gc; gc.collect(); torch.cuda.empty_cache(); del model
# 2. Align whisper output
model_a, metadata = whisperx.load_align_model(
language_code=result["language"],
device=device,
model_name="KBLab/wav2vec2-large-voxrex-swedish",
model_dir="cache", # cache_dir
)
result = whisperx.align(
result["segments"], model_a, metadata, audio, device, return_char_alignments=False
)
print(result["segments"]) # word level timestamps after alignment
Whisper.cpp / GGML
我們提供了可用於whisper.cpp
和MacWhisper
應用程序的GGML檢查點。要在whisper.cpp
中使用我們的模型,首先克隆倉庫並構建庫:
git clone https://github.com/ggerganov/whisper.cpp.git
cd whisper.cpp
cmake -B build
cmake --build build --config Release
要使用該模型,你需要下載我們上傳的GGML檢查點之一。你可以點擊此處的下載按鈕,或者使用wget
下載:
wget https://huggingface.co/KBLab/kb-whisper-medium/resolve/main/ggml-model-q5_0.bin # Quantized version
# wget https://huggingface.co/KBLab/kb-whisper-medium/resolve/main/ggml-model.bin # Non-quantized version
通過在參數-m
後指定模型路徑,並將音頻文件的路徑作為最後一個位置參數來運行推理:
./build/bin/whisper-cli -m ggml-model-q5_0.bin ../audio.wav
onnx (optimum) and transformers.js usage
你可以通過Hugging Face的optimum
庫以以下方式使用onnx
檢查點:
from optimum.onnxruntime import ORTModelForSpeechSeq2Seq
from transformers import AutoProcessor
model_id = "KBLab/kb-whisper-medium"
processor = AutoProcessor.from_pretrained(model_id, cache_dir="cache")
model = ORTModelForSpeechSeq2Seq.from_pretrained(
model_id,
cache_dir="cache",
subfolder="onnx",
)
import soundfile as sf
audio = sf.read("audio.wav")
inputs = processor.feature_extractor(audio[0], sampling_rate=16000, return_tensors="pt")
gen_tokens = model.generate(**inputs, max_length=300)
processor.decode(gen_tokens[0], skip_special_tokens=True)
一個使用transformers.js
和KB-Whisper
在瀏覽器中進行本地推理的應用示例可以在https://whisper.mesu.re/找到(由Pierre Mesure創建)。一個使用JavaScript設置此類應用的模板可以在https://github.com/xenova/whisper-web找到。
📚 詳細文檔
訓練數據
我們的模型在超過50,000小時帶有文本轉錄的瑞典語音頻數據上進行了訓練。模型分兩個階段進行訓練,每個階段的特點是應用不同的質量過濾器和相應的閾值。
階段1採用較低的閾值(根據數據集,BLEU值在0到0.30之間),而階段2使用更嚴格的閾值(BLEU >= 0.7
,加權ROUGE-N >= 0.7
,前10個和後10個字符的CER <= 0.2
)。
數據集 | 持續預訓練(小時) - 階段1 | 微調(小時) - 階段2 |
---|---|---|
字幕 | 34,261 | 3,110 |
瑞典議會 | 21,949 | 5,119 |
ISOF | 54 | 54 |
NST | 250 | 250 |
總計 | 56,514 | 8,533 |
通過Hugging Face加載我們的模型時,默認使用階段2。不過,我們也上傳了持續預訓練的檢查點並進行了標記。你可以通過在.from_pretrained()
中指定revision
來加載這些其他檢查點。例如,預訓練檢查點的標籤可以在pretrained-checkpoint
找到。階段2的默認模型標籤名為standard
。我們還提供了另一個階段2的檢查點,其轉錄風格更簡潔,名為subtitle
。
評估
單詞錯誤率(WER)
模型大小 | FLEURS | CommonVoice | NST | |
---|---|---|---|---|
tiny | KBLab | 13.2 | 12.9 | 11.2 |
OpenAI | 59.2 | 67.8 | 85.2 | |
base | KBLab | 9.1 | 8.7 | 7.8 |
OpenAI | 39.6 | 52.1 | 53.4 | |
small | KBLab | 7.3 | 6.4 | 6.6 |
OpenAI | 20.6 | 26.4 | 26.4 | |
medium | KBLab | 6.6 | 5.4 | 5.8 |
OpenAI | 12.1 | 15.8 | 17.1 | |
large-v3 | KBLab | 5.4 | 4.1 | 5.2 |
OpenAI | 7.8 | 9.5 | 11.3 |
BLEU分數
模型大小 | FLEURS | CommonVoice | NST | |
---|---|---|---|---|
tiny | KBLab | 76.6 | 73.7 | 74.3 |
OpenAI | 26.9 | 21.1 | 24.0 | |
base | KBLab | 83.2 | 79.9 | 78.3 |
OpenAI | 41.1 | 32.5 | 36.9 | |
small | KBLab | 86.6 | 83.5 | 79.6 |
OpenAI | 64.0 | 56.5 | 58.2 | |
medium | KBLab | 87.6 | 85.0 | 80.2 |
OpenAI | 77.1 | 70.1 | 68.9 | |
large-v3 | KBLab | 89.8 | 87.2 | 81.1 |
OpenAI | 84.9 | 79.1 | 75.1 |
🔧 技術細節
文檔未提及技術實現細節,故跳過此章節。
📄 許可證
本項目採用apache-2.0
許可證。
致謝
我們感謝歐洲高性能計算聯合事業(EuroHPC Joint Undertaking)通過歐洲高性能計算人工智能和數據密集型應用訪問項目,授予本項目使用由意大利CINECA和LEONARDO聯盟託管的歐洲高性能計算超級計算機LEONARDO的權限。
引用
論文參考文獻即將公佈。



