ποΈ State Space Models for Speech: Keyword Spotting and Speech to Text
Trained weights for three speech models built on state space models (SSMs): neural networks that read audio step by step while carrying a fixed-size memory, their state. All three were written in PyTorch and trained from scratch in Google Colab on a T4 GPU, without any pretrained speech model. The code, the training notebooks and a Streamlit app are on GitHub: laurelthejas/state-space-models-speech-recognition.
| File | Task | Model | Parameters | Result on speakers not heard in training |
|---|---|---|---|---|
keyword_s4d.safetensors |
1 second of audio β one of 35 words | S4D | 1.21M | 95.5% accuracy |
keyword_mamba2.safetensors |
1 second of audio β one of 35 words | Mamba-2-style SSM | 1.33M | 96.3% accuracy |
speech_to_text.safetensors |
English speech β text, letter by letter | Mamba-2-style SSM | 6.92M | 7.9% character error rate, 24.9% word error rate |
config.json holds each model's settings, the 35 words, the alphabet and the measured results. SHA256SUMS.txt holds checksums of the files.
π Results
- Keyword spotting: the official test set of Speech Commands v0.02, 11,005 recordings by speakers not in the training set. With 35 words, guessing would be right about 3% of the time.
- Speech to text: LibriSpeech test-clean, 2,620 recordings (5.4 hours) by 40 speakers not in the training set, with greedy decoding and no language model. Trained on train-clean-100: 100.7 hours by 251 speakers.
π Use
The weights need the model code in ssm_speech.py from the GitHub repository, plus torch, numpy and safetensors. Audio must be mono at 16 kHz, with values between β1 and 1.
import torch
from safetensors.torch import load_file
import ssm_speech as S
# Keyword spotting: one second of audio -> one of 35 words
model = S.KeywordSSM(kind="mamba2", dim=128).eval() # S4D: kind="s4d", dim=256
model.load_state_dict(load_file("keyword_mamba2.safetensors"))
wave = torch.zeros(1, 16000) # replace with your 1-second recording
with torch.no_grad():
word = S.KEYWORDS[model(wave).argmax(-1).item()]
# Speech to text: up to about 30 seconds of audio -> text
model = S.SpeechToTextSSM(kind="mamba2", dim=256, layers=8).eval()
model.load_state_dict(load_file("speech_to_text.safetensors"))
wave = torch.zeros(1, 16000 * 5) # replace with your recording
with torch.no_grad():
log_probs, lengths = model(wave)
text = S.ctc_greedy_decode(log_probs, lengths)[0]
β οΈ Limitations
These models are a from-scratch study of state space models for speech, trained in under four hours on one free GPU, rather than a general-purpose speech recognizer trained at large scale. For applications that need dependable transcription across many voices and recording conditions, an established model such as Whisper, trained on 680,000 hours of speech, or a cloud speech service is the right tool.
- The keyword models know only the 35 words of Speech Commands and always pick one of them, even for other words or background noise.
- The speech-to-text model learned from audiobooks read aloud: clear, read English works best, while casual speech, strong accents and noisy recordings are harder. It spells by sound with no dictionary, so many errors are plausible misspellings, such as fervant for fervent. The test results are best-case figures: on a laptop microphone, a quick good morning everyone came out as s good moning yevreryon.
- Both SSMs read each recording forward and backward, so they answer after the recording ends rather than while you speak.
βοΈ License
The weights are released under the MIT license, like the code. They were trained on Speech Commands v0.02 by Pete Warden (Warden, 2018) and LibriSpeech by Vassil Panayotov, Guoguo Chen, Daniel Povey and Sanjeev Khudanpur (Panayotov et al., 2015), both released under CC BY 4.0.
π References
- Albert Gu, Ankit Gupta, Karan Goel and Christopher RΓ©. On the Parameterization and Initialization of Diagonal State Space Models. NeurIPS 2022.
- Tri Dao and Albert Gu. Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality. ICML 2024.
- Pete Warden. Speech Commands: A Dataset for Limited-Vocabulary Speech Recognition. arXiv:1804.03209, 2018.
- Vassil Panayotov, Guoguo Chen, Daniel Povey and Sanjeev Khudanpur. Librispeech: An ASR Corpus Based on Public Domain Audio Books. ICASSP 2015.
- Alex Graves, Santiago FernΓ‘ndez, Faustino Gomez and JΓΌrgen Schmidhuber. Connectionist Temporal Classification: Labelling Unsegmented Sequence Data with Recurrent Neural Networks. ICML 2006.
- Downloads last month
- -