Building Hong Kong Cantonese ASR v1: Problems We Hit and How We Fixed Them
Engineering notes from training and shipping our first Hong Kong Cantonese speech model (Qwen3-ASR 1.7B & 0.6B): data hygiene, an SFT left-padding bug, code-switching, and running in the browser.
Many open speech models list "Cantonese" support, but few produce Hong Kong Cantonese the way people here actually say and write it. In everyday speech, especially mixed with English at work or over messaging, generic models tend to fall apart in three predictable ways:
- Formal written rewrites: colloquial words like 係, 喺, 嘅, 咗 and 㗎 get normalised into Mandarin written Chinese (是, 在, 的, 了), or non-Hong Kong regional characters (噶, 捻) slip in.
- Phonetic transliteration of English: natural code-switching such as 「今日 send 咗個 proposal 畀 client」 or 「book 咗聽晚七點嘅枱」 becomes mangled Chinese homophones like 「布克」 instead of "book".
- Huge baseline variance across registers: on
openai/whisper-large-v3, character error rate (CER) sits between 20.97% (FLEURS yue_hant_hk) and 41.76% (Common Voice 23 zh-HK). StockQwen/Qwen3-ASR-1.7Bis a much stronger starting point (4.20% on FLEURS), but still scores 7.65% on Common Voice 23 zh-HK and 11.74% on MCE code-switching, while defaulting to Simplified or non-HK orthography.
Why OpenCC post-processing is not enough
An obvious shortcut is to keep a stock model and run Simplified-to-Hong Kong conversion (OpenCC s2hk) afterwards. In our internal audit of OpenCC s2hk outputs on stock Qwen3-ASR-1.7B against held-out Hong Kong Cantonese speech, that post-processing step alone added about 1.92 percentage points of extra error: common words like 系 were left unmapped 2,017 times or mapped to 繫 (204 times) instead of colloquial 係. Even worse, character conversion cannot undo lexical rewrites that already happened inside the decoder. If the target is authentic Hong Kong Cantonese (繁體口語照寫、英文照寫英文), the model has to emit it natively.
Four problems we hit building v1
1. Cross-corpus leakage and dirty transcripts
Public Cantonese datasets (FLEURS yue_hant_hk, Common Voice 21 yue, Common Voice 23 zh-HK, MDCC, LegCo, CanCLID/zoengjyutgaai and MCE) are messy to combine directly. Prompts repeat across evaluation splits, crowded sentences get read dozens of times by different speakers, digits in text clash with spoken words, and a single-speaker storytelling corpus (zoengjyutgaai) can easily drown out multi-speaker Hong Kong conversation.
In our internal data preparation pipeline, we locked down four strict rules before training:
- Global sentence deduplication: strip every
devandtestsentence across all evaluation benchmarks (plus all Common Voicetestspeakers) from every training manifest. - Repeat caps & speaker balance: cap repeated Common Voice prompts at 5 clips from distinct speakers, and cap single-speaker zoengjyutgaai at 40 hours so one voice never dominates acoustic priors.
- Quality & length gates: keep LegCo only where
qc_flagsis empty andmatch_confidence >= 0.6; drop segments longer than 30 seconds; drop training rows containing raw ASCII digits so the acoustic-to-text mapping stays aligned. - Spoken conversational diversity: balance clean read corpora with natural multi-speaker Hong Kong conversational speech (upsampled 2×) so informal timing, particles, and code-switching carry through.
2. A silent left-padding bug in the SFT data collator
During our early qwen-asr 0.0.6 (transformers 4.57.6) fine-tuning setup, we hit a subtle batching bug that would have poisoned shorter clips inside mixed-length batches. Even when tokenizer.padding_side == "right", the processor left-pads multimodal batches. Upstream masking did labels[i, :pl] = -100, assuming the prefix began at index 0, which only masked leading padding tokens on shorter rows, leaving the system prompt, user turn, and audio_pad tokens as active training loss targets!
We also noticed labels[labels == pad_id] = -100 can accidentally zero out the end-of-sequence loss when pad_token_id == eos_token_id. The fix was to locate the first real non-pad position from attention_mask before masking the prefix:
# Under left-padded batches, prefix tokens start after leading pad tokens (`start`),
# not at index 0; mask padding with attention_mask so EOS is never masked out.
prefix_lens = prefix_inputs["attention_mask"].sum(dim=1).tolist()
attn = full_inputs["attention_mask"]
labels = full_inputs["input_ids"].clone()
for i, pl in enumerate(prefix_lens):
real = attn[i].nonzero()
start = int(real[0]) if len(real) else 0
labels[i, : start + int(pl)] = -100
labels[attn == 0] = -100
That small patch kept supervision strictly on language Cantonese<asr_text>{transcript}<eos>.
3. Code-switching and short-command fragility
A major worry when fine-tuning a bilingual speech model is catastrophic forgetting: teaching colloquial Cantonese shouldn't break English tokens or formal register like Legislative Council transcripts. Running full-parameter BF16 SFT (in our internal runs, a learning rate of 2e-5 for v1, then a 1e-5 cosine schedule in Stage 2) cleanly cut MCE code-switching CER in half, from 11.74% down to 5.61% in v1 (5.52% in v2.1), and from 15.52% to 6.98% on 0.6B, while LegCo stayed rock solid (7.22% to 7.17%, and 7.16% in v2.1).
Where v1 and v2 still stumbled was short commands under long hotword lists. Users of voice-typing tools often supply custom glossaries (OraType, place names, commands like 閂燈, 開燈, 閂冷氣). When someone spoke a 2-character clip with a long glossary in the system prompt, v2 scored 21.88% CER on the 70-clip short_long_prompt condition of our 210-clip context test suite, which motivated the 75/15/7/3 Jyutping homophone-trap + pure-distractor training mix we introduced in v2.1.
4. Shipping 1.7B offline and 0.6B in the browser
Getting accurate weights trained was only half the job; people also need to run them locally without a cloud server:
- In the browser (demo.koelony.com, 0.6B int8 ONNX, ~1.2 GB): WebGPU runtimes cannot swallow a single monolithic weights blob inside static edge asset limits (25 MiB per file). We exported
encoder.onnx,decoder_init.onnx, anddecoder_step.onnxsharing an externaldecoder_weights.datatensor store split into chunks of at most 24 MiB for the Cache API, kept KV caches ingpu-bufferon WebGPU, pre-converted embeddings into a compact FP16embed_tokens.binlookup table, wrote a pure-JS mixed-radix N=400 Whisper log-mel frontend (verified within ~2e-5 max diff against PyTorch), and added same-origin COOP/COEP headers so the WASM fallback can use multi-threading. Recordings over 30 s split at low-energy boundaries, and a loop-breaker (repetition threshold of 20) catches decoder repetition. Mobile browsers still hit memory caps around 1.2 GB, so the demo shows a warning on phones and tablets and recommends desktop Chrome or Edge. - Desktop & macOS (1.7B GGUF, 1.1–1.8 GB): For local apps like OraType and
llama-server, pairing GGUF quantizations (Q4_K_M,Q6_K,Q6_K_H,Q8_0) withmmproj-Q8_0(356 MB) runs 1.7B completely offline.
Benchmark results across six Cantonese test sets
All figures below are greedy-decoding character error rates (CER %, lower is better) in BF16 (transformers) with language forced to Cantonese, OpenCC t2s, normalised numbers, and spaces removed. Checkpoints compared: whisper-large-v3, stock Qwen/Qwen3-ASR-1.7B & 0.6B, Qwen3-ASR-1.7B-Cantonese-HK (v1, v2.1), and Qwen3-ASR-0.6B-Cantonese-HK.
| Test set (CER %) | whisper-large-v3 | Stock 1.7B | 1.7B v1 | 1.7B v2.1 | Stock 0.6B | 0.6B (ours) |
|---|---|---|---|---|---|---|
| FLEURS (yue_hant_hk) | 20.97 | 4.20 | 4.00 | 3.89 | 6.10 | 5.70 |
| Common Voice yue | 36.44 | 5.46 | 3.80 | 3.94 | 6.84 | 5.12 |
| Common Voice 23 zh-HK | 41.76 | 7.65 | 5.18 | 5.02 | 9.55 | 6.44 |
| MDCC | 34.52 | 4.25 | 2.53 | 2.47 | 5.45 | 3.29 |
| LegCo | 32.15 | 7.22 | 7.17 | 7.16 | 8.81 | 7.62 |
| MCE (code-switching) | 24.00 | 11.74 | 5.61 | 5.52 | 15.52 | 6.98 |
Try it or grab the weights: Test 0.6B right in your browser on demo.koelony.com, inspect interactive benchmark comparisons on koelony.com/asr/, read the evaluation & inference code on GitHub (
koelony/qwen3-asr-cantonese-hk), or pull BF16 / GGUF / FP8 / NVFP4 checkpoints from Hugging Face (koelony).