Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Continual fine-tuning SenseVoiceSmall
This guide covers adding an accent, dialect, or domain to SenseVoiceSmall while retaining its existing languages. Full-parameter, partial-parameter, adapter, and replay setups cannot guarantee zero regression. Treat retention as an explicit evaluation constraint.
1. Lock the evaluation sets first
Create one fixed validation set for every language or domain that must be preserved and one for the new domain. The speakers in validation must be speaker-disjoint from all training and replay data. Do not use a single mixed CER to select checkpoints because a large Mandarin set can hide Cantonese regression.
Record the original model's CER or WER on every set before generating pseudo-labels. Define an acceptable relative regression for each retained language before training:
relative regression = (candidate CER - baseline CER) / baseline CER
The threshold is a product decision, not a FunASR guarantee. Select a checkpoint only when it meets every retention threshold and the new-domain target.
References must be independently audited for transcription policy and provenance. Check whether new-domain labels are verbatim transcripts or written-language paraphrases, and whether test references were generated by the same process as training labels. Speaker separation alone does not make those references reliable. An unaudited new-domain CER must not select checkpoints or tune replay ratios.
The reporter in issue #3388 later withdrew the earlier new-domain evaluation and rebuilt an independent test set. The old baseline table is therefore not a valid selection reference. Recompute the frozen baseline and all candidates with the same reviewed references and CER normalization. For Mandarin and Cantonese, also separate read and spontaneous speech when both matter in production. Keep held-out speakers out of the 8.45-hour training example below; its replay budgets are illustrative, not validated optima.
2. Build a replay manifest
When manually labeled old-domain data is unavailable, decode owned or appropriately licensed Mandarin and Cantonese audio with the original model. Store the model revision and raw decoding output with each pseudo-label so the manifest can be audited and regenerated.
Filter or review at least these cases before training:
- empty, repeated, or obviously truncated pseudo-labels;
- language mismatches;
- audio outside the duration range supported by the training setup;
- low decoder scores when a comparable score is available;
- a random sample from every speaker and language, including high-score samples.
A pseudo-label is not ground truth. Keep validation labels independent from pseudo-label generation.
Sample a fixed replay budget for each training epoch instead of copying the entire old-domain pool. Start with this small matrix:
| replay:new | New Teochew | Replay per epoch |
|---|---|---|
| 1:1 | 8.45 h | 8.45 h |
| 2:1 | 8.45 h | 16.9 h |
| 3:1 | 8.45 h | 25.35 h |
For this example, start with 2:1. A practical first replay split is about 10.1 hours Mandarin and 6.8 hours Cantonese per epoch. The 60:40 split is an experiment starting point, not an official ratio: it deliberately oversamples Cantonese relative to a 100 h / 10 h source pool because Cantonese retention is a separate requirement. Sample different records across epochs and keep a minimum Cantonese share. Use the manifest as the source of truth when reported pool totals disagree.
3. Use a supported language token
The current model's named inference language mapping includes zh, en, yue,
ja, and ko (plus automatic/no-speech handling). This is not the complete
tokenizer vocabulary. Sharing <|zh|> with a new domain is an experiment, not an
isolation mechanism: it can interfere with Mandarin and must pass retention gates.
The #3388 reporter found a useful <|minnan|> comparison in their setup. A token
existing in a vocabulary does not mean it is unused, freely repurposable, or
accepted by the stock inference language mapping. Pin the tokenizer/model revision
and inspect the token id, training target and query embedding path, and inference
mapping before adopting a language-tag change. Do not generalize that experiment
into a guarantee for another language or checkpoint.
Do not add <|teochew|> to the JSONL and assume it becomes a new language id.
The current tokenizer does not encode it as one supported special token. A real
custom language id requires coordinated tokenizer, vocabulary, language
embedding, checkpoint migration, export, and inference changes.
Check downstream language validation and every allowlist as well. Test an actual result through export, service parsing and the final client: a valid model result must not be silently discarded because its language tag is unfamiliar. Preserve raw model output while diagnosing an empty response; do not simply disable all validation or relabel the result to pass a closed list.
4. Train in two stages
Copy finetune.sh to an experiment directory, point it at the mixed training
manifest and fixed validation manifests, and replace the default long,
high-learning-rate run with a short first stage.
Stage 1: head warm-up
Freeze the complete acoustic encoder and train the language-query embedding and CTC/output parameters:
++train_conf.max_epoch=5 \
++freeze_param="encoder" \
++optim_conf.lr=0.00002 \
Three to five epochs are an initial budget, not a required value. Validate and save often enough to observe all three curves. Do not wait for 50 epochs before checking retention.
Stage 2: release the later encoder blocks
If Teochew CER stalls while Mandarin and Cantonese remain inside their retention gates, resume the best Stage 1 checkpoint and freeze only the input block and the first three regular encoder blocks:
++freeze_param="encoder.encoders0,encoder.encoders.0,encoder.encoders.1,encoder.encoders.2" \
++optim_conf.lr=0.00002 \
The value is a comma-separated list of parameter-name prefixes. With the
current SenseVoiceSmall encoder, later encoder.encoders.* blocks remain
trainable. Lower the learning rate further, for example to 0.00001, or stop
earlier if a retained language regresses.
At startup, verify that the log contains the expected lines:
Setting encoder...requires_grad = False
Also inspect the model summary. A misspelled prefix silently leaves the intended parameters trainable because no parameter name matches it.
5. Select the checkpoint by constraints
The maintained finetune.sh explicitly uses:
++train_conf.avg_keep_nbest_models_type=loss
SenseVoice returns ASR CTC loss plus a rich-tag objective and acc_rich, not the
trainer's ASR acc. acc_rich is not CER or ASR accuracy. A missing metric must not
be treated as a real zero; genuine acc=0 remains a valid score for models that
actually report it. The trainers exclude an unavailable/nonfinite selected metric
from best selection, keep-N ranking and metric-based averaging, with an explicit
warning. This can leave unranked checkpoints on disk; correct the criterion/data
instead of assuming the keep-N limit applies to them.
Use a new output directory when changing from accuracy to loss ranking. Resuming with a different criterion is rejected; old zero-valued histories cannot reliably be identified as missing after the fact, and pruned weights cannot be recovered. Earlier runs affected by this defect need independent reevaluation of retained checkpoints, not just an upgrade. Revalidation cannot overwrite the current best under the same checkpoint name if its selected metric becomes unavailable.
model.pt.best now means best total validation loss for this recipe, not the
lowest CER or best retained-language behavior. Weight averaging is also only a
candidate: reevaluate the averaged model under all the same gates.
Evaluate every candidate checkpoint on Mandarin, Cantonese, and Teochew separately.
- Discard checkpoints that violate either retained-language threshold.
- Among the remaining checkpoints, choose the lowest Teochew CER.
- If none pass, increase replay from 1:1 to 2:1 or 3:1, increase the minimum Cantonese share, reduce the learning rate, or shorten training.
- If all retained metrics pass but Teochew stalls, move from Stage 1 to the partial-freeze Stage 2 configuration.
Keep a table with the model revision, manifest revision, replay mix, frozen prefixes, learning rate, step, and all three metrics. This makes the selected checkpoint reproducible.
6. LoRA status
FunASR contains LoRA support for specific Paraformer/SANM paths, but
SenseVoiceSmall does not currently expose a complete, documented LoRA recipe.
Do not assume that setting lora_only creates trainable SenseVoice adapters.
Verify the trainable parameter list before relying on any adapter experiment.
Launch checklist
- Validation speakers do not occur in train or replay data.
- Baseline CER/WER and acceptable relative regression are recorded per language.
- Pseudo-labels are filtered and manually sampled for audit.
- Replay is sampled to an explicit per-epoch budget with a Cantonese floor.
- References and normalization are independently audited before any CER comparison.
- Language-token mapping and downstream allowlists pass an end-to-end result check.
- The ranking metric is explicit; changed criteria use a new output directory.
- Freeze logs and trainable parameters match the intended stage.
- Every saved checkpoint is evaluated on all retained and new domains.