Instructions to use Phreak87/moonshine-tiny_V2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use Phreak87/moonshine-tiny_V2 with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('automatic-speech-recognition', 'Phreak87/moonshine-tiny_V2');
moonshine-tiny_V2
V2 of Phreak87/moonshine-tiny-de-onnx. Same model weights as dattazigzag/moonshine-tiny-de, re-exported with optimum.
Why this version exists: V1's HTML had a custom 50-line decoder loop because optimum's merged-decoder export has a broken then_branch (cache=True path uses past_key_values.X.encoder.* directly as cross-attention K/V, which are zero on step1, producing wrong first token). V2 fixes the merged decoder at the ONNX level so the standard pipeline('automatic-speech-recognition', modelId) call works without any model-specific decoder hack in the HTML.
The fix:
- then_branch cross-attention fix: For each of the 6 layers, adds a fresh K/V projection from encoder_hidden_states inside the then_branch subgraph.
- Bakes use_cache_branch_const=False: This is critical for tiny models. The tiny model has Float32 numerical drift in the self-attention KV-cache when the then_branch recomputes K/V every step (token degenerates to repetition). Baking the If condition to False forces always-full_seq mode, matching V1's behavior exactly.
Without the bake, incremental decoding on tiny produces "g g g g g g..." (repetition loop).
See v2/fix_then_branch.py for the patch script.
Demo HTML
Moonshine_DE_V2.html in Phreak87/moonshine-base_V2 is the matching V2 HTML. It supports both tiny and base via dropdown.
Verification
Validated against V1's full-seq-each-step decoding on test-de.mp3:
V2 greedy: guten morgen das ist ein thes der lokalen sprach erkennung mit mundschiene
V1 greedy: guten morgen das ist ein thes der lokalen sprach erkennung mit mundschiene
Both paths produce identical ids, byte-for-byte.
Files
- config.json, generation_config.json, preprocessor_config.json, tokenizer_config.json, tokenizer.json, special_tokens_map.json - model and tokenizer configs
- onnx/encoder_model.onnx - audio encoder
- onnx/decoder_model_merged.onnx - text decoder (with V2 then_branch fix + baked use_cache_branch_const=False)
Use
import { pipeline, AutoTokenizer } from 'https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.2.0/dist/transformers.min.js';
const pipe = await pipeline('automatic-speech-recognition', 'Phreak87/moonshine-tiny_V2', { dtype: 'fp32' });
pipe.processor.components.tokenizer = await AutoTokenizer.from_pretrained('Phreak87/moonshine-tiny_V2');
const result = await pipe(audio, {}); // audio: Float32Array @ 16 kHz
console.log(result.text);
- Downloads last month
- 34