🚀 Whisper Small Cantonese - Alvin
このモデルは、広東語に対してopenai/whisper-smallをファインチューニングしたバージョンです。Common Voice 16.0では、句読点なしで7.93のCER、句読点ありで9.72のCERを達成しています。
📦 インストール
このセクションではインストールに関する具体的なコマンドが提供されていないため、スキップします。
✨ 主な機能
- 広東語に対する高精度な自動音声認識を実現。
- 異なる条件下(句読点の有無など)での低いCERを達成。
- 高速な推論が可能。
💻 使用例
基本的な使用法
import librosa
import torch
from transformers import WhisperForConditionalGeneration, WhisperProcessor
y, sr = librosa.load('audio.mp3', sr=16000)
MODEL_NAME = "alvanlii/whisper-small-cantonese"
processor = WhisperProcessor.from_pretrained(MODEL_NAME)
model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME)
processed_in = processor(y, sampling_rate=sr, return_tensors="pt")
gout = model.generate(
input_features=processed_in.input_features,
output_scores=True, return_dict_in_generate=True
)
transcription = processor.batch_decode(gout.sequences, skip_special_tokens=True)[0]
print(transcription)
高度な使用法
from transformers import pipeline
MODEL_NAME = "alvanlii/whisper-small-cantonese"
lang = "zh"
device = ...
pipe = pipeline(
task="automatic-speech-recognition",
model=MODEL_NAME,
chunk_length_s=30,
device=device,
)
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
text = pipe(file)["text"]
📚 ドキュメント
トレーニングと評価データ
トレーニングには以下のデータセットを使用しています。
- CantoMap: Winterstein, Grégoire, Tang, Carmen and Lai, Regine (2020) "CantoMap: a Hong Kong Cantonese MapTask Corpus", in Proceedings of The 12th Language Resources and Evaluation Conference, Marseille: European Language Resources Association, p. 2899-2906.
- Cantonse-ASR: Yu, Tiezheng, Frieske, Rita, Xu, Peng, Cahyawijaya, Samuel, Yiu, Cheuk Tung, Lovenia, Holy, Dai, Wenliang, Barezi, Elham, Chen, Qifeng, Ma, Xiaojuan, Shi, Bertram, Fung, Pascale (2022) "Automatic Speech Recognition Datasets in Cantonese: A Survey and New Dataset", 2022. Link: https://arxiv.org/pdf/2201.02419.pdf
名前 |
時間数 |
Common Voice 16.0 zh-HK Train |
138 |
Common Voice 16.0 yue Train |
85 |
Common Voice 17.0 yue Train |
178 |
Cantonese-ASR |
72 |
CantoMap |
23 |
Pseudo-Labelled YouTube Data |
438 |
評価には、Common Voice 16.0 yue Test setを使用しています。
結果
- CER(低いほど良い): 0.0972
- 前のバージョンの0.1073、0.1581から改善。
- CER(句読点を削除): 0.0793
- 高速アテンションを使用したGPU推論(以下の例): 0.055秒/サンプル
- すべてのGPU評価はRTX 3090 GPUで行われています。
- GPU推論: 0.308秒/サンプル
- CPU推論: 2.57秒/サンプル
- GPU VRAM: ~1.5 GB
モデルの高速化
Flash Attentionを使用するには、attn_implementation="sdpa"を追加します。
model = AutoModelForSpeechSeq2Seq.from_pretrained(
"alvanlii/whisper-small-cantonese",
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
use_safetensors=True,
attn_implementation="sdpa",
)
Flash Attentionを使用することで、サンプルあたりの処理時間が0.308秒から0.055秒に短縮されます。
推測的デコード
より大きなモデルを使用し、alvanlii/whisper-small-cantonese
を用いて精度をほぼ損なうことなく推論を高速化することができます。
model_id = "simonl0909/whisper-large-v2-cantonese"
model = AutoModelForSpeechSeq2Seq.from_pretrained(
model_id,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
use_safetensors=True,
attn_implementation="sdpa",
)
model.to(device)
processor = AutoProcessor.from_pretrained(model_id)
assistant_model_id = "alvanlii/whisper-small-cantonese"
assistant_model = AutoModelForSpeechSeq2Seq.from_pretrained(
assistant_model_id,
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
use_safetensors=True,
attn_implementation="sdpa",
)
assistant_model.to(device)
...
model.generate(**inputs, use_cache=True, assistant_model=assistant_model)
元のsimonl0909/whisper-large-v2-cantonese
モデルでは、CER 7.65で0.714秒/サンプルの速度で動作します。alvanlii/whisper-small-cantonese
を用いた推測的デコードでは、CER 7.67で0.137秒/サンプルと、大幅に高速化されています。
Whisper.cpp
2024年6月現在、Whisper cpp用のGGMLバイナリファイルをアップロードしています。バイナリファイルはここからダウンロードでき、ここで試すことができます。
Whisper CT2
WhisperXまたはFasterWhisperで使用するには、CT2ファイルが必要です。変換されたモデルはここにあります。
トレーニングハイパーパラメータ
- 学習率: 5e-5
- トレーニングバッチサイズ: 25(1台の3090 GPUで)
- 評価バッチサイズ: 8
- 勾配累積ステップ: 4
- 総トレーニングバッチサイズ: 25x4 = 100
- オプティマイザ: Adam(betas=(0.9,0.999)、epsilon=1e-08)
- 学習率スケジューラの種類: 線形
- 学習率スケジューラのウォームアップステップ: 500
- トレーニングステップ: 15000
- データ拡張: なし
📄 ライセンス
このモデルはApache-2.0ライセンスの下で提供されています。