Skip to content
PaniniHQPublic

About

Experiments in User adaptation of small ASR models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

adapt

Experiments with user adapted ASR, focusing on on-device use cases.

On-device ASR models have become great but there is still WER gap specially if considering non-English languages. Since many mobile-on-device use cases are for use by just one person, we could bring the WER of such languages to an acceptable range by doing some tuning on that person’s voice. This repository explores such personalizations using Moonshine models.

Current state

  1. There is a data generation interface in ./data/generation/ that allows you to record audios in Indian English, Hindi, Tamil, and Hinglish (hi-en). The Hinglish track exists because real usage code-switches, and a plain per-locale corpus (e.g. MASSIVE) can’t reflect that. It’s the one language with a train/eval split baked into the prompt bank itself ("split": "train"/"eval" per prompt) — train is assistant-command style, eval is conversational/news/question/ instruction style with deliberately different vocabulary, so that a WER gain from fine-tuning can’t just be the model having memorized train phrasing. Recordings for a split-tagged language land in separate <lang>/train/ and <lang>/eval/ folders from the start (see data/generation/README.md).
  2. After data generation, you can run the evaluate_asr.py script on the dataset (the jsonl file) to get a report of baseline moonshine model performance.
  3. The moonshine-voice[lora] extra is installed for personalization: it trains a decoder-only LoRA adapter on a Moonshine Streaming checkpoint directly from a metadata.jsonl manifest (same {audio, text} format we already use), auto-mixing in a general-domain replay corpus to avoid forgetting. torch is pinned to a cu126 build (see pyproject.toml) since the default PyPI wheel targets CUDA 13 and this machine’s GPU (GTX 1060, Pascal/sm_61) is otherwise dropped from PyTorch’s newer prebuilt wheels; cu126 still carries forward-compatible PTX for it. Once there’s enough personalization audio recorded (plan: record a new 1h manifest, keep the en-in set above untouched as a held-out --eval-manifest for a clean before/after WER comparison), train with e.g.:
    uv run python -m moonshine_voice.lora \
      --train-manifest path/to/new_manifest.jsonl \
      --eval-manifest "data/generation/recordings/Abhinav Tushar/en-in/mixed/metadata.jsonl" \
      --model moonshine-ai/moonshine-streaming-medium \
      --output-dir lora_runs/lepisma-en-in \
      --eval
        

    Then --export the result to .ort graphs so evaluate_asr.py can score it like any other moonshine model.

  4. The shipped LoRA recipe only adapts decoder self-attention — encoder self-attention (the part that actually processes raw audio/accent) and cross-attention both stay frozen, so it can reshape the decoder’s language-model prior but can’t correct genuine acoustic mishearing. train_lora_encoder.py (repo root) wraps the same recipe with a --variant flag selecting which self-attention sites get LoRA-adapted:
    • decoder (default): the shipped recipe, decoder only.
    • decoder_encoder: decoder (all layers) + encoder (all layers).
    • encoder_bottom (--encoder-bottom-n, default 2): only the bottom N encoder layers, decoder untouched — the Euphonia-style arm (Google’s on-device disordered-speech personalization found fine-tuning just the bottom 2 of 8 encoder layers recovers ~91% of the gain from fine-tuning the whole encoder, with less overfitting risk on a small personal dataset).

    All three are comparable on the same data — this is the acoustic-vs-non-acoustic question from the intro, made concrete. It reuses the packaged data loading / replay-mixing / eval / save logic unchanged (see lora_encoder_adapter.py for the extended adapter functions and why that’s safe to splice in); only the LoRA-site selection differs. Same flags as moonshine-voice lora, e.g.:

    uv run train_lora_encoder.py \
      --train-manifest path/to/new_manifest.jsonl \
      --eval-manifest "data/generation/recordings/Abhinav Tushar/en-in/mixed/metadata.jsonl" \
      --model moonshine-ai/moonshine-streaming-medium \
      --variant decoder_encoder \
      --output-dir lora_runs/lepisma-en-in-encoder \
      --eval
        

    --export is not handled by this wrapper — run moonshine-voice lora --export --model lora_runs/.../adapted --output-dir ... directly, it needs no changes to pick up encoder weights.

    Memory: touching the encoder means backprop runs through the whole network, which used to OOM a 6 GiB GTX 1060 at the default batch-size 8 (see the batch-size 2 workarounds in the results below). train_lora_encoder.py now enables gradient checkpointing by default (no-op during --eval’s generate()). Pass --no-gradient-checkpointing to turn it off on a bigger GPU. See experiments/README.md for details.

  5. android/ has a minimal Android demo app (“Adapt”) that runs a fine-tuned model live on-device: tap to record, see partial transcripts as you speak, and keep the audio + transcript of each session for playback. Models are user-managed rather than baked into the APK — add several named exports from a picked folder or adb push, switch between them from a dropdown, and on a past recording re-run its saved audio through a different model in the same streaming fashion a live session uses, to compare fine-tunes against a fixed recording. See android/README.md for the file layout and android/scripts/push_model.sh.
  6. Recording is the real bottleneck for personalization data, so data/synthetic/ clones the recorded voice (Chatterbox TTS) and synthesizes new text in a news/internet register — deliberately different from the real recordings’ conversational register, so the real recordings can stay reserved as held-out eval instead of being split into train/eval. Its own isolated uv project (Chatterbox pins an older torch than this repo’s LoRA training needs); see data/synthetic/README.md for the method, the Chatterbox-vs-XTTS-v2 pick, and how to reuse it for a different voice/language/domain.
  7. experiments/run_sweep.py runs the data-scaling x LoRA-variant sweep (tiny/medium x decoder/decoder_encoder/encoder_bottom x 5-60 minutes of synthetic training data, eval’d against the real held-out en-in recordings) as a resumable batch of subprocesses, logging status/results to experiments/sweep_log.jsonl and redrawing experiments/plot.png after every run so progress is visible without waiting for the whole sweep. See experiments/README.md for how to read it mid-run and the findings once it’s done.

Here is the current performance of moonshine (all sizes, model language en) on voice data of @lepisma for around 5 mins of Indian English. Size is on-disk weight size (quantized), not parameter count. Params is the count of elements across all weight tensors in the exported ONNX graph (summed from the deployed .ort files, de-duplicated across the encoder/decoder’s with-past/without-past branches) — it can run a bit above the parameter count of the original training-time model since ONNX export can materialize tied weights (e.g. an untied LM head) as separate tensors. WER/MER/WIL below are computed with OpenAI’s Whisper-paper EnglishTextNormalizer (lowercases, strips punctuation, expands contractions/titles, standardizes number formatting) before scoring, the same normalizer moonshine_voice.lora’s corpus_wer() uses for its --eval WER during fine-tuning, so these numbers are directly comparable to LoRA training/eval output:

ModelSizeParamsWERMERWILSubDelInsHits
medium-streaming291 MiB266.4M0.19640.19070.31191552132883
small-streaming158 MiB140.4M0.30970.29050.44772263270801
base135 MiB75.2M0.33330.32030.49552585243749
tiny-streaming50 MiB44.2M0.53730.49740.71234255985575
tiny42 MiB36.5M0.55620.50690.715641472103573

Moonshine has no locale-specific Indian-English model; en above is its general English model. The same dataset run through Whisper (all sizes, via faster-whisper, GPU, int8, transcription language forced to en — .en-suffixed models are Whisper’s English-only checkpoints, the rest are the multilingual checkpoints run against English; no locale-specific Indian-English variant exists here either), scored with the same Whisper normalizer as above. Params here is OpenAI’s officially published parameter count per size (.en and multilingual checkpoints of the same size have the same count):

ModelSizeParamsWERMERWILSubDelInsHits
large-v32.9 GiB1550M0.04630.04610.081539731013
medium1.5 GiB769M0.06700.06670.115855115993
turbo1.6 GiB809M0.08780.08690.1448661611977
medium.en1.5 GiB769M0.09250.09140.157376913974
small464 MiB244M0.11330.11170.1838842115954
small.en464 MiB244M0.11990.11860.20541031212944
base142 MiB74M0.22190.21480.34941772335859
base.en141 MiB74M0.24360.23670.38391982931832
tiny.en75 MiB39M0.33240.31320.48652592865772
tiny75 MiB39M0.39380.36710.55703063477719

Whisper large-v3 beats the best Moonshine model (medium-streaming) by a wide margin on this dataset, but at a much larger model size and without Moonshine’s on-device/streaming design goals.

Zero-shot: Cactus Whistle vs. Moonshine/Whisper on every en-in set

Cactus Compute’s Whistle (released 2026-10-02) is a 16.9 MB (55M params, mostly 2-bit) CPU-only ASR model. It ran zero-shot on all five en-in sets through its own C runtime (cactus-needle 3.2.7, language forced to en), next to the ONNX-runtime Moonshine and faster-whisper (CPU int8) models. All use the same Whisper normalizer as above. agent5min is the fixed 100-clip held-out split of custom_agent_instructions that the fine-tuning experiments score on. Reproduce with experiments/eval_whistle.py; results are in experiments/results/eval_whistle.json. WER %:

ModelSizemixednewsquestioninstructionagent(338)agent5minall
whisper-small464 MiB11.528.460.710.807.838.648.37
moonshine-medium-streaming291 MiB19.6410.304.260.8011.0310.6311.61
whisper-base142 MiB22.3814.743.552.4011.5711.5714.16
moonshine-small-streaming158 MiB30.9712.428.512.4012.6213.2014.83
whisper-tiny75 MiB35.4120.0112.069.6015.2817.2919.99
whistle17 MiB39.5723.9716.3120.8019.8019.6324.32
moonshine-tiny-streaming50 MiB53.8224.2711.3518.4021.1921.5026.83
  • Whistle beats moonshine-tiny-streaming, the Android app’s default, overall (24.3% vs. 26.8%) and by 14pp on conversational mixed, at about a third of its size. It loses to it on the small question/instruction sets.
  • It loses to whisper-tiny on every set, by 4–11pp, at about a quarter of whisper-tiny’s size.
  • It’s the fastest per clip here. CPU real-time factor was about 0.06–0.2 on this 8-core machine (measured with the other baselines running alongside, so treat it as rough).
  • whisper-tiny reads 35.41% on mixed here vs. 39.38% in the table above. That one ran on GPU, this one on CPU int8: same model, different numerics.

Whistle fine-tuning: acoustic adaptation

whistle/ (its own uv project, JAX; see whistle/README.md) tests whether fine-tuning adapts to the voice rather than the vocabulary: train on one register, score on others with no shared vocabulary.

  • Train on: ~17 min of real news recordings.
  • Score on: mixed and agent5min, registers with no vocabulary overlap with training.
  • Runs: 23 on a rented RTX 3090, about $1.10.

WER % through Whistle’s own runtime, vs. a same-pipeline base (mean ± sd over 3 seeds):

RecipemixedΔagent5minΔ
base (no training)38.34—19.86—
needle’s own fine-tuner, as shipped46.40 ±0.05+8.0621.46 ±0.70+1.60
LoRA, all 15 sites (W2)35.38 ±1.11−2.9620.05 ±0.70+0.19
LoRA, decoder only38.15 ±1.06−0.1920.64 ±0.34+0.78
LoRA, encoder only36.73 ±1.34−1.6118.65 ±0.95−1.21
full-rank, whole encoder (n=8)36.51 ±0.14−1.8319.70 ±0.18−0.16
full-rank, bottom 3 encoder layers37.02 ±1.88−1.3217.06 ±0.51−2.80
  • cactus-needle’s fine-tuner changes the deployed model. It trains and exports everything at 4 bits, but the published model is mostly 2-bit. Its output is about 8pp worse on mixed before training matters. whistle/deploy_quant.py trains and exports in the published scheme, and reproduces the published archive.
  • Decoder-only training transfers nothing; encoder-side training does. Tuning the bottom 3 of 8 encoder layers full-rank is the best recipe on the unrelated register (−14% relative on agent5min).
  • Learning rate, replay and whole-model training don’t help: lr 1e-5 / 5e-5, replay 0.5 and full are all within noise of the whole-encoder row.
  • Full results, plus what the recipe is probably still missing (checkpoint selection on a news-only dev set, 30–60 epochs with no augmentation, and depth). Raw numbers are in experiments/results/eval_whistle_finetune.json.

Whistle encoder pruning for one speaker (negative result)

The question: if the model only ever hears one speaker, can whole encoder layers be dropped and then recovered by fine-tuning on that speaker, to get a smaller and faster Whistle at the same WER on their voice?

  • Setup: same data and evals as the fine-tuning section above.
  • Recipe: prune the encoder to k of 8 layers (whistle/prune.py), then train every kept layer on the ~17 min of news.
  • Losses compared:
    • plain CE
    • CE + token-level distillation from the unpruned model
    • those plus encoder-output distillation (match the full encoder on every 80 ms frame)
  • Runs: 22 on a rented RTX 3090, about $0.90.

Only depth can be cut without changing the Cactus runtime. Width, heads and conv size are shared with the decoder or hard-coded. Kept layers per depth were chosen by greedy backward elimination on teacher-forced loss.

WER % through Whistle’s runtime, best recipe per depth (encoder-output distillation), single seed:

Encoder layersMBmixedagent5minencoder RTFe2e RTF
8 (base)16.9238.3419.860.02250.0570
7 (drop 6)16.3948.0630.140.02090.0564
6 (0,1,2,3,4,7)15.8652.3142.760.01920.0561
5 (0–4)15.3278.0969.980.01750.0560
4 (0,1,2,4)14.7989.9994.040.01580.0656
2 (0,7)13.73142.3148.710.0139—
  • Dropping even one layer costs ~10pp after recovery. Every depth below 8 is far worse on your own voice, at every loss. 17 minutes of one speaker isn’t enough to relearn what a layer did.
  • Encoder-output distillation is the only loss that keeps improving (best step 1500–3000 vs. 200–400 for CE / token-KD, which overfit).
    • At 6 layers it cuts mixed from 60.5 to 52.3.
    • At 4 layers with a 4× frame weight, it hit the 3000-step cap still improving.
    • Replay and training the decoder too don’t help.
  • Size and speed gains are small.
    • Each encoder layer is only ~0.53 MB (the encoder is 22% of the archive; the engram tables and embedding are 45%).
    • The encoder is ~40% of CPU time, so 6 layers should save ~6% end to end. Measured is ≤2%, probably because the worse hypotheses decode more tokens. TTFT drops 58 → 52 ms at 6 layers. The 4-layer model is slower overall because its garbled output decodes longer.
  • Raw numbers: experiments/results/eval_whistle_prune.json, whistle_prune_log.jsonl, whistle_prune_speed.json (CPU, 8 cores, median of 3 rounds) and lora_runs/whistle_prune_probe/ (no-training probes).

Whistle round 2: voice that transfers, and small + voice

Same isolation test as round 1: train on ~29 min of news only, score on mixed / agent_eval5min (no shared vocabulary), so gains there are voice, not domain. New: token KD from the published model (--kd-weight 0.5), waveform augmentation (--augment: speed 0.9/1.0/1.1, ±6 dB, noise at 15-35 dB SNR), whisper-small pseudo-labels, and two-stage voice-then-shrink training (--save-float, then --checkpoint). run_sweep.py --sweep voice2. 40 runs on two rented RTX 3090s plus 20 .cact splices, ~$1.95.

WER %, mean ± sd over seeds (n):

ModelMBnmixedagent5min
base16.92138.3419.86
round 1: bottom 3 encoder layers, CE16.92337.02 ±1.8817.06 ±0.51
bottom 3 + KD16.92335.44 ±0.4817.41 ±0.20
bottom 3 + KD + augmentation16.92534.03 ±0.6616.99 ±0.13
whole model + KD + augmentation16.92233.9019.69
bottom 3 + KD, whisper-small labels16.92135.4117.64
11.19 MB shrink recovery alone (news + agent)11.19338.46 ±0.3818.77 ±0.70
11.19 MB, shrink + voice jointly, news only11.19242.6819.57
11.19 MB, splice voice layers in11.19937.36 ±0.9318.48 ±0.51
11.19 MB, two stages: voice, then recovery11.19236.78 ±0.7317.29 ±0.50
16.92 MB, whole + KD (news + agent) + splice16.92932.43 ±1.0916.94 ±0.53
9.99 MB, two stages9.99141.4520.33
  • Voice transfers once KD and augmentation are combined. The bottom 3 encoder layers, trained on news alone: -4.3pp mixed, -2.9pp agent5min, with the smallest seed spread of any recipe. Augmentation without KD doesn’t help (37.6).
  • Pseudo-labels work. whisper-small’s transcripts (8.5% WER) matched the real ones, so the voice step can run on untranscribed device audio.
  • Small + voice: voice first, then shrink. The shrink needs audio in your text domain to recover, and the voice layers need your voice. Two stages give 36.8 / 17.3 at 11.19 MB, beating the 16.92 MB base on both. Doing both at once on news fails. 9.99 MB doesn’t keep the voice gain.
  • The voice layers are portable. Writing the 3 trained encoder layers’ records into another fine-tuned .cact (no training) gives the best Whistle numbers so far: 32.4 / 16.9 at full size.
  • Raw: experiments/results/whistle_voice2_log.jsonl, eval_whistle_voice2.json, eval_whistle_splice.json.

Moonshine round 2: Whistle’s KD + augmentation recipe (negative result)

Ported the Whistle round-2 recipe to Moonshine voice training (train_lora_encoder.py --kd-weight 0.5 --augment, teacher = frozen base model). Same news-only isolation, same encoder_bottom_full setup as the round-1 Moonshine voice runs (tiny ebn6, medium ebn5, lr 2e-5, batch 32). run_sweep.py --experiment voice2, 14 runs + 11 fixed-step checks on one RTX 3090, ~$0.55.

WER %, eval_voice_vs_domain.py, mean ± sd over seeds (n):

Modelnmixedagent5min
tiny base141.7421.26
tiny round 1, CE335.22 ±0.1617.48 ±0.41
tiny KD340.89 ±0.2519.12 ±0.13
tiny augmentation340.23 ±1.0621.14 ±0.62
tiny KD + augmentation342.34 ±1.6917.60 ±0.41
medium base117.0010.05
medium round 1, CE313.50 ±0.008.61 ±0.24
medium KD115.399.58
medium augmentation115.207.59
medium KD + augmentation317.60 ±0.399.58 ±0.00
  • It doesn’t port. Every arm is worse than plain CE on mixed, for both models. Medium augmentation’s 7.59 on agent5min is the one cell that wins (n=1).
  • Not just checkpoint choice. The round-1 runs all early-stopped at step 100. The new arms picked later steps (200-1300) because augmentation fits news dev better, and that hurts transfer. But a fixed 100-step rerun (trainer’s mixed WER, results/moonshine_voice2_s100.txt) still shows no gain: tiny CE 37.08 ±0.20, aug 37.33 ±1.59, KD + aug 37.83 ±0.70; medium CE 13.50, aug 15.86, KD + aug 15.30.
  • Likely why (untested): Whistle’s round-1 voice training overfit, so KD and augmentation helped as regularisers. Moonshine’s round 1 already stops after 100 steps. KD pulls toward a teacher that doesn’t know the voice, and speed perturbation distorts the speaker cues being learned.
  • Moonshine voice training stays at round 1 (plain CE, early stop).
  • Raw: results/moonshine_voice2_log.jsonl, eval_voice_vs_domain.json (-kd0.5 / -aug run ids).

Whistle vocabulary-side shrink for one user

The encoder can’t be cut (above), but 45% of the archive is the vocabulary side: two engram n-gram memories (4.7 MB, hashed 2/3-gram tables feeding decoder layers 3 and 7) and the token embedding (2.1 MB). One user needs only part of that vocabulary. The question: shrink it, then fine-tune back to the base model’s WER on your voice.

  • Shrink levers (=whistle/shrink.py=, no training):
    • fold each engram table from 18432 to N slots (slot % N), merging rows by usage, with counts from your domain text plus general English text
    • lower bit widths (engram tables 1-bit, embedding 2-bit)
    • drop decoder layers (ranked by teacher-forced CE; 2 and 4 hurt least)
  • Training: ~29 min of news + custom_agent_instructions/train audio. Token distillation from the published model (KD 0.5, or 1.0 = no CE), optional general-English replay 0.5, QAT at the shrunk widths.
  • Runs: 27 CPU probes and 15 training runs on a rented RTX A5000 (~$1.60 including two failed hosts).

WER %, single seed (instruction/question are only 12/16 clips):

Model / trainingMBmixedagent5mininstrquest
base (no training)16.9238.319.920.817.0
full size, whole model + KD16.9234.520.114.412.8
full size, decoder + KD16.9239.920.424.814.2
11.19 MB untrained11.1944.223.124.017.0
LoRA everywhere + engram/emb, KD11.1938.118.727.216.3
decoder, pure KD + replay11.1940.320.620.816.3
whole model + KD11.1941.620.123.218.4
whole model + KD + replay11.1940.120.325.617.7
engram/emb only, pure KD + replay11.1941.820.920.816.3
decoder + KD11.1944.421.122.419.2
9.99 MB untrained (also drop dec 2, 4)9.9945.924.824.019.9
whole model + KD9.9939.121.326.416.3
whole model + KD + replay9.9943.120.625.616.3
decoder + KD (± replay, pure KD)9.9944–4622–2326–3017–20
  • 11.19 MB (−34%) holds base WER on your voice with LoRA on every site plus trainable engram/embedding: 38.1 mixed, 18.7 agent5min. Instruction is worse (27.2), but that’s 12 clips.
  • Train the whole model, not just the decoder. Decoder-only CE on 29 min overfits (dev loss falls, mixed WER rises). Pure KD + replay was the only decoder-only recipe that got close (40.3).
  • The full-size whole-model run is the best Whistle result so far (34.5 mixed vs. round 1’s 35.4). This one isn’t a clean voice-only result: training included agent-instruction audio (disjoint from agent5min, but same register), though agent5min didn’t move.
  • Usage-weighted folding beats a plain mean, and folding with the eval text itself (an oracle) is better still. Your own text is a real lever for this.
  • Smaller isn’t faster, except for decoder depth. CPU end-to-end RTF: 11.19 MB runs the same as the unshrunk fine-tune (0.055). The 9.99 MB model, two decoder layers fewer, decodes 21% faster (0.049, 1.12×).
  • Raw numbers: experiments/results/eval_whistle_shrink.json, eval_whistle_shrink_probe.json, whistle_shrink_log.jsonl, whistle_shrink_speed.json.

Preliminary decoder-only vs. decoder+encoder LoRA result (medium-streaming)

5 min en-in recording, 75/25 stratified split: 81 train / 28 eval clips (69 of the 81 actually drove gradient updates after the dev/replay carve-out). Single run, single seed — directional, not conclusive.

ModelWER on the 28-clip eval splitvs. baselineFine-tune time
Baseline (medium-streaming, no fine-tune)21.46%——
Decoder-only LoRA (shipped recipe)18.35%−3.1pp (≈14% rel)not recorded
Decoder+encoder LoRA (train_lora_encoder.py)12.36%−9.1pp (≈42% rel)not recorded
  • Decoder+encoder OOM’d at batch-size 8 on the 6 GiB GTX 1060 (encoder backprop needs much more activation memory); dropped to batch-size 2.
  • Both runs showed mild forgetting on the replay dev set (general-domain loss rose 0.1996→0.2159 decoder-only, 0.2073→0.2278 decoder+encoder).

Tiny model LoRA (the Android app’s default model)

tiny-streaming is the app’s default/stock download, so it’s the model worth personalizing on-device first. Same en-in recordings, a fresh 75/25 stratified split (109 clips, seed 42; 69 train / 12 dev / 28 eval).

ModelWER on the 28-clip eval splitvs. baselineFine-tune time
Baseline (tiny-streaming)38.83%——
Decoder-only LoRA31.87%−6.96pp (≈18% rel)~2 min
Decoder+encoder LoRA (train_lora_encoder.py)34.43%−4.40pp (≈11% rel)~2 min

Times are wall-clock for training+eval on a GTX 1060 (6 GiB), with the domain/replay audio caches already built (adds a few minutes on a cold cache). Both commands need --dev-hours 0.0107 (the packaged default of 0.25h exceeds this manifest’s total 0.07h and silently carves the entire train pool into dev, hanging the run with zero training batches); the decoder+encoder run additionally needs --batch-size 2 (default batch-size 8 OOMs on encoder backprop, same as the medium run above).

Unlike medium, decoder-only beat decoder+encoder here — tiny’s small capacity likely leaves less room for the encoder-side adapter to help without needing more data/steps than this 69-clip set gives it.

Exported+quantized models (android/README.md file layout) land in lora_runs/lepisma-en-in-tiny-{decoder,encoder}/exported/.

About

Experiments in User adaptation of small ASR models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages