Instructions to use Phreak87/moonshine-base_V2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use Phreak87/moonshine-base_V2 with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('automatic-speech-recognition', 'Phreak87/moonshine-base_V2');
moonshine-base_V2
V2 of Phreak87/moonshine-base-de-onnx. Same model weights as fidoriel/moonshine-base-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 8 layers, adds a fresh K/V projection from encoder_hidden_states inside the then_branch subgraph (replacing the empty-past cross-attention path).
- Bakes use_cache_branch_const=False: Removes use_cache_branch from the If-node input and hard-codes the If condition to False. The model always runs the else_branch (full_seq mode). This avoids numerical drift in the self-attention KV-cache that occurs on tiny models when the then_branch recomputes K/V every step.
See v2/fix_then_branch.py in the V2 repository for the patch script.
Demo HTML
Moonshine_DE_V2.html in this repo is the matching V2 HTML. It uses the standard pipeline() call with no custom decoder loop, just a single workaround line for a transformers.js v4 MoonshineProcessor tokenizer-loading bug (static class attrs aren't picked up by the parent Processor.from_pretrained).
Verification
Validated against V1's full-seq-each-step decoding on test-de.mp3:
V2 greedy: Guten Morgen, das ist ein Test der lokalen Spracherkennung mit Munchie.
V1 greedy: Guten Morgen, das ist ein Test der lokalen Spracherkennung mit Munchie.
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-base_V2', { dtype: 'fp32' });
pipe.processor.components.tokenizer = await AutoTokenizer.from_pretrained('Phreak87/moonshine-base_V2');
const result = await pipe(audio, {}); // audio: Float32Array @ 16 kHz
console.log(result.text);
- Downloads last month
- 44