Downloads · 30 days
1.4K
0% of all-time downloads
alvanlii/whisper-small-cantonese
whisper-small-cantonese is a automatic speech recognition model from alvanlii. Use it when you need speech turned into text. It is set up for transformers. The card lists the license as apache-2.0.
should probably proofread and complete it, then remove this comment. --
Downloads · 30 days
1.4K
0% of all-time downloads
All-time downloads
730K
Public
Parameters
242M
15 GB on disk
Likes
121
Public
Click a slice to open those files.
.bin2.4 GB · 46%
From the Hugging Face model README
This model is a fine-tuned version of openai/whisper-small on the Cantonese language. It achieves a 7.93 CER (without punctuations), 9.72 CER (with punctuations) on Common Voice 16.0
For training,
| Name | # of Hours |
|---|---|
| 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 |
For evaluation, Common Voice 16.0 yue Test set is used.
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"
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"]
Just add attn_implementation="sdpa" for Flash Attention.
model = AutoModelForSpeechSeq2Seq.from_pretrained(
"alvanlii/whisper-small-cantonese",
torch_dtype=torch_dtype,
low_cpu_mem_usage=True,
use_safetensors=True,
attn_implementation="sdpa",
)
Using Flash Attention reduced the amount of time taken per sample from 0.308s to 0.055s.
You can use a bigger model, then use alvanlii/whisper-small-cantonese to speed up inference with basically no loss in accuracy.
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)
In the original simonl0909/whisper-large-v2-cantonese model, it runs at 0.714s/sample for a CER of 7.65.
Using speculative decoding with alvanlii/whisper-small-cantonese, it runs at 0.137s/sample for a CER of 7.67, which is much faster.
Uploaded a GGML bin file for Whisper cpp as of June 2024. You can download the bin file here and try it out here.
For use in WhisperX or FasterWhisper, a CT2 file is needed. The converted model is under here