Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- zh
|
4 |
+
license: apache-2.0
|
5 |
+
tags:
|
6 |
+
- whisper-event
|
7 |
+
- generated_from_trainer
|
8 |
+
base_model: openai/whisper-small
|
9 |
+
datasets:
|
10 |
+
- mozilla-foundation/common_voice_11_0
|
11 |
+
model-index:
|
12 |
+
- name: Distil-Whisper Small zh-HK - Alvin
|
13 |
+
results:
|
14 |
+
- task:
|
15 |
+
name: Automatic Speech Recognition
|
16 |
+
type: automatic-speech-recognition
|
17 |
+
dataset:
|
18 |
+
name: mozilla-foundation/common_voice_16_0 yue
|
19 |
+
type: mozilla-foundation/common_voice_16_0
|
20 |
+
config: yue
|
21 |
+
split: test
|
22 |
+
args: yue
|
23 |
+
metrics:
|
24 |
+
- name: Normalized CER
|
25 |
+
type: cer
|
26 |
+
value: 9.77
|
27 |
+
---
|
28 |
+
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
|
29 |
+
should probably proofread and complete it, then remove this comment. -->
|
30 |
+
|
31 |
+
# Distil-Whisper Small zh-HK - Alvin
|
32 |
+
|
33 |
+
This model is a distilled and fine-tuned version of [openai/whisper-small](https://huggingface.co/openai/whisper-small) on the Cantonese language. It achieves a 9.77 CER (without punctuations), 11.7 CER (with punctuations) on Common Voice 16.0
|
34 |
+
|
35 |
+
## Training and evaluation data
|
36 |
+
For training,
|
37 |
+
- 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.
|
38 |
+
- 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
|
39 |
+
- Common Voice yue and zh-HK train sets
|
40 |
+
|
41 |
+
For evaluation, Common Voice 16.0 yue Test set is used.
|
42 |
+
|
43 |
+
## Results
|
44 |
+
- CER (lower is better): 0.117
|
45 |
+
- GPU Inference with Fast Attention (example below): 0.039s/sample
|
46 |
+
- Note all GPU evaluations are done on RTX 3090 GPU
|
47 |
+
- GPU Inference: <TODO>s/sample
|
48 |
+
- CPU Inference: 2.57s/sample
|
49 |
+
- GPU VRAM: ~2 GB
|
50 |
+
|
51 |
+
|
52 |
+
## Using the Model
|
53 |
+
```
|
54 |
+
import librosa
|
55 |
+
|
56 |
+
import torch
|
57 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
58 |
+
|
59 |
+
y, sr = librosa.load('audio.mp3', sr=16000)
|
60 |
+
|
61 |
+
MODEL_NAME = "alvanlii/distil-whisper-small-cantonese"
|
62 |
+
|
63 |
+
processor = WhisperProcessor.from_pretrained(MODEL_NAME)
|
64 |
+
model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME)
|
65 |
+
|
66 |
+
model.config.forced_decoder_ids = None
|
67 |
+
model.config.suppress_tokens = []
|
68 |
+
model.config.use_cache = False
|
69 |
+
|
70 |
+
processed_in = processor(y, sampling_rate=sr, return_tensors="pt")
|
71 |
+
gout = model.generate(
|
72 |
+
input_features=processed_in.input_features,
|
73 |
+
output_scores=True, return_dict_in_generate=True
|
74 |
+
)
|
75 |
+
transcription = processor.batch_decode(gout.sequences, skip_special_tokens=True)[0]
|
76 |
+
print(transcription)
|
77 |
+
```
|
78 |
+
- Alternatively, you can use huggingface pipelines
|
79 |
+
```
|
80 |
+
from transformers import pipeline
|
81 |
+
MODEL_NAME = "alvanlii/distil-whisper-small-cantonese"
|
82 |
+
lang = "zh"
|
83 |
+
pipe = pipeline(
|
84 |
+
task="automatic-speech-recognition",
|
85 |
+
model=MODEL_NAME,
|
86 |
+
chunk_length_s=30,
|
87 |
+
device=device,
|
88 |
+
)
|
89 |
+
pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
|
90 |
+
text = pipe(file)["text"]
|
91 |
+
```
|
92 |
+
|
93 |
+
## Model Speedup
|
94 |
+
Just add attn_implementation="sdpa" for Flash Attention.
|
95 |
+
```
|
96 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
97 |
+
"alvanlii/distil-whisper-small-cantonese",
|
98 |
+
torch_dtype=torch_dtype,
|
99 |
+
low_cpu_mem_usage=True,
|
100 |
+
use_safetensors=True,
|
101 |
+
attn_implementation="sdpa",
|
102 |
+
)
|
103 |
+
```
|
104 |
+
Using Flash Attention reduced the amount of time taken per sample from <TODO>s to 0.039s.
|
105 |
+
|