Instructions to use moonshine-ai/moonshine-streaming-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use moonshine-ai/moonshine-streaming-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="moonshine-ai/moonshine-streaming-tiny")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("moonshine-ai/moonshine-streaming-tiny", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
library_name: transformers
|
| 6 |
+
pipeline_tag: automatic-speech-recognition
|
| 7 |
+
---
|
| 8 |
+
# Moonshine Streaming
|
| 9 |
+
|
| 10 |
+
This is the model card for the Moonshine Streaming automatic speech
|
| 11 |
+
recognition (ASR) models trained and released by Useful Sensors. Moonshine Streaming
|
| 12 |
+
pairs a lightweight 50~Hz audio frontend with a sliding-window Transformer
|
| 13 |
+
encoder to deliver low-latency streaming ASR on edge-class hardware. The encoder
|
| 14 |
+
uses bounded local attention and no positional embeddings (an "ergodic"
|
| 15 |
+
encoder), while an adapter injects positional information before a standard
|
| 16 |
+
autoregressive decoder.
|
| 17 |
+
|
| 18 |
+
This model card follows the recommendations from Model Cards for Model Reporting
|
| 19 |
+
(Mitchell et al.). See the paper draft in this repository for full details.
|
| 20 |
+
|
| 21 |
+
## Usage
|
| 22 |
+
|
| 23 |
+
Moonshine Streaming is supported in Hugging Face Transformers. The following example
|
| 24 |
+
matches the standard seq2seq ASR API and uses the streaming model checkpoint:
|
| 25 |
+
|
| 26 |
+
```bash
|
| 27 |
+
pip install --upgrade pip
|
| 28 |
+
pip install --upgrade git+https://github.com/huggingface/transformers.git#egg=transformers datasets[audio]
|
| 29 |
+
```
|
| 30 |
+
|
| 31 |
+
```python
|
| 32 |
+
from transformers import MoonshineStreamingForConditionalGeneration, AutoProcessor
|
| 33 |
+
from datasets import load_dataset, Audio
|
| 34 |
+
import torch
|
| 35 |
+
|
| 36 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 37 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 38 |
+
|
| 39 |
+
model = MoonshineStreamingForConditionalGeneration.from_pretrained(
|
| 40 |
+
"usefulsensors/moonshine-streaming-small"
|
| 41 |
+
).to(device).to(torch_dtype)
|
| 42 |
+
processor = AutoProcessor.from_pretrained("usefulsensors/moonshine-streaming-small")
|
| 43 |
+
|
| 44 |
+
dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 45 |
+
dataset = dataset.cast_column("audio", Audio(processor.feature_extractor.sampling_rate))
|
| 46 |
+
sample = dataset[0]["audio"]
|
| 47 |
+
|
| 48 |
+
inputs = processor(
|
| 49 |
+
sample["array"],
|
| 50 |
+
return_tensors="pt",
|
| 51 |
+
sampling_rate=processor.feature_extractor.sampling_rate,
|
| 52 |
+
)
|
| 53 |
+
inputs = inputs.to(device, torch_dtype)
|
| 54 |
+
|
| 55 |
+
# Limit max output length to avoid hallucination loops.
|
| 56 |
+
token_limit_factor = 6.5 / processor.feature_extractor.sampling_rate
|
| 57 |
+
seq_lens = inputs.attention_mask.sum(dim=-1)
|
| 58 |
+
max_length = int((seq_lens * token_limit_factor).max().item())
|
| 59 |
+
|
| 60 |
+
generated_ids = model.generate(**inputs, max_length=max_length)
|
| 61 |
+
print(processor.decode(generated_ids[0], skip_special_tokens=True))
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
Note: the current Transformers code path does not yet implement fully efficient
|
| 65 |
+
streaming for these models. It uses the flash-attention backend's sliding-window
|
| 66 |
+
attention when available.
|
| 67 |
+
|
| 68 |
+
## Model Details
|
| 69 |
+
|
| 70 |
+
### Model type
|
| 71 |
+
|
| 72 |
+
Sequence-to-sequence ASR model with a streaming, sliding-window Transformer
|
| 73 |
+
encoder and an autoregressive Transformer decoder.
|
| 74 |
+
|
| 75 |
+
### Supported languages
|
| 76 |
+
|
| 77 |
+
English (trained and evaluated on English datasets).
|
| 78 |
+
|
| 79 |
+
### Model sizes
|
| 80 |
+
|
| 81 |
+
| Size | Parameters | Encoder / Decoder layers | Encoder dim | Decoder dim |
|
| 82 |
+
|:-----:|:----------:|:------------------------:|:-----------:|:-----------:|
|
| 83 |
+
| Tiny | 34M | 6 / 6 | 320 | 320 |
|
| 84 |
+
| Small | 123M | 10 / 10 | 620 | 512 |
|
| 85 |
+
| Medium| 245M | 14 / 14 | 768 | 640 |
|
| 86 |
+
|
| 87 |
+
### Architecture summary
|
| 88 |
+
|
| 89 |
+
- Audio frontend: 50~Hz features using simple time-domain operations, CMVN, and
|
| 90 |
+
two causal stride-2 convolutions.
|
| 91 |
+
- Encoder: sliding-window self-attention with no positional embeddings (ergodic
|
| 92 |
+
encoder). Windowing uses $(16,4)$ for the first two and last two layers and
|
| 93 |
+
$(16,0)$ for intermediate layers, giving an 80~ms lookahead in the lookahead
|
| 94 |
+
layers.
|
| 95 |
+
- Adapter: adds learned positional embeddings and aligns dimensions before the
|
| 96 |
+
decoder.
|
| 97 |
+
- Decoder: causal Transformer with RoPE, autoregressively generating text.
|
| 98 |
+
|
| 99 |
+
## Model Use
|
| 100 |
+
|
| 101 |
+
### Intended use
|
| 102 |
+
|
| 103 |
+
These models are intended for low-latency, on-device English speech
|
| 104 |
+
transcription on memory- and compute-constrained platforms (roughly
|
| 105 |
+
0.1--1~TOPS and sub-1~GB memory budgets). Typical applications include live
|
| 106 |
+
captioning, voice commands, and real-time transcription.
|
| 107 |
+
|
| 108 |
+
### Out-of-scope use
|
| 109 |
+
|
| 110 |
+
These models are not intended for non-consensual surveillance, speaker
|
| 111 |
+
identification, or high-stakes decision-making contexts. They have not been
|
| 112 |
+
robustly evaluated for tasks outside English ASR.
|
| 113 |
+
|
| 114 |
+
## Training Data
|
| 115 |
+
|
| 116 |
+
Moonshine Streaming was trained on roughly 300K hours of speech data. This includes the
|
| 117 |
+
original Moonshine training sources (about 200K hours of public web data and
|
| 118 |
+
open datasets) plus an additional 100K hours of internally prepared speech
|
| 119 |
+
data. See the paper for details and dataset sources.
|
| 120 |
+
|
| 121 |
+
## Performance and Limitations
|
| 122 |
+
|
| 123 |
+
### Open ASR benchmark results (WER %)
|
| 124 |
+
|
| 125 |
+
| Dataset | Tiny (34M) | Small (123M) | Medium (245M) |
|
| 126 |
+
|:----------------------|----------:|-------------:|--------------:|
|
| 127 |
+
| AMI | 19.03 | 12.54 | 10.68 |
|
| 128 |
+
| Earnings-22 | 20.27 | 13.53 | 11.90 |
|
| 129 |
+
| GigaSpeech | 13.90 | 10.41 | 9.46 |
|
| 130 |
+
| LibriSpeech (clean) | 4.49 | 2.49 | 2.08 |
|
| 131 |
+
| LibriSpeech (other) | 12.09 | 6.78 | 5.00 |
|
| 132 |
+
| SPGISpeech | 6.16 | 3.19 | 2.58 |
|
| 133 |
+
| TED-LIUM | 6.12 | 3.77 | 2.99 |
|
| 134 |
+
| VoxPopuli | 14.02 | 9.98 | 8.54 |
|
| 135 |
+
| **Average** | **12.01** | **7.84** | **6.65** |
|
| 136 |
+
|
| 137 |
+
### Known limitations
|
| 138 |
+
|
| 139 |
+
- The decoder is autoregressive, so full-output latency grows with transcript
|
| 140 |
+
length even when TTFT is low.
|
| 141 |
+
- The Transformers implementation does not yet perform fully efficient
|
| 142 |
+
streaming; it relies on the flash-attention backend for sliding-window
|
| 143 |
+
attention.
|
| 144 |
+
- Like other seq2seq ASR models, Moonshine Streaming can hallucinate words that are not
|
| 145 |
+
present in the audio, and may repeat phrases, especially on short or noisy
|
| 146 |
+
segments.
|
| 147 |
+
|
| 148 |
+
## Broader Implications
|
| 149 |
+
|
| 150 |
+
Moonshine Streaming enables low-cost, low-latency transcription, which benefits
|
| 151 |
+
accessibility and user interaction on edge devices. At the same time, ASR
|
| 152 |
+
capabilities can be misused for surveillance or other harmful purposes. Users
|
| 153 |
+
should consider consent, privacy, and domain-specific evaluation before
|
| 154 |
+
deployment.
|
| 155 |
+
|
| 156 |
+
## Citation
|
| 157 |
+
|
| 158 |
+
**TBD**
|