File size: 8,366 Bytes
3319246 541420d 3319246 541420d 3319246 541420d 3319246 541420d 3319246 541420d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | ---
license: apache-2.0
language:
- en
tags:
- automatic-speech-recognition
- speech
- ctc
- streaming-asr
- causal-transformer
- rope
- pytorch
datasets:
- openslr/librispeech_asr
- edinburghcstr/ami
- MLCommons/peoples_speech
- facebook/voxpopuli
metrics:
- wer
---
# Jalapeno-ASR-preview (56.88M)
**Jalapeno-ASR-preview** is a lightweight, **56.88M-parameter** streaming English Automatic Speech Recognition (ASR) model built on a 16-layer Causal Transformer CTC architecture with **Rotary Position Embeddings (RoPE)** and **160ms chunked lookahead**. Designed for ultra-low-latency, high-throughput inference, it achieves **2,430x real-time speed (RTFx)** on GPU while maintaining strong accuracy across multi-speaker meetings, accented speech, and clean audio.
---
## Model Highlights
* **Compact Footprint:** 56.88M parameters (~228 MB in FP32)
* **Low-Latency Streaming Architecture:** Causal 2D convolutional subsampling (4x time reduction, 40ms frame stride) + 16-layer Transformer encoder (`d_model=512`, `nhead=8`, `dim_feedforward=2048`) with **4-frame (160ms) lookahead** and zero-parameter **RoPE**
* **Multi-Domain Training (284,000 Steps):** Trained with CTC loss on leak-free `train` splits spanning read, conversational, meeting, and accented English speech:
* **LibriSpeech (`clean` & `other`)**
* **AMI Meeting Corpus (`ihm`)**
* **People's Speech (`clean`)**
* **VoxPopuli (`en`)**
* **Throughput:** **2,430.84x average RTFx** (~0.41 ms compute per 1 second of 16 kHz audio)
---
## Benchmark Evaluation (Open ASR Leaderboard Suite)
Evaluated using the official Hugging Face Whisper `EnglishTextNormalizer` (100 utterances per benchmark split, greedy CTC decoding, 160ms lookahead):
| Benchmark Dataset | Split | Normalized WER (%) | Inference Speed (RTFx) |
| :--- | :--- | :---: | :---: |
| **URGENT24** *(LibriSpeech Dev-Clean)* | `validation` | **17.60%** | 932.2x |
| **Voice Arena** *(LibriSpeech Test-Clean)* | `test` | **21.20%** | 1,249.1x |
| **SPGISpeech** | `test` | **37.80%** | 2,894.3x |
| **GigaSpeech-Cleaned** | `test` | **38.60%** | 2,964.0x |
| **VoxPopuli-AA-Cleaned** | `test` | **40.80%** | 4,049.7x |
| **Monsoon** *(LibriSpeech Test-Other)* | `test` | **41.60%** | 812.7x |
| **AMI-Cleaned** | `test` | **43.70%** | 2,742.7x |
| **Earnings22-Cleaned-AA-chunked** | `test` | **62.30%** | 3,802.1x |
| **Average across all 8 tasks** | — | **37.95%** | **2,430.84x** |
---
## Quickstart Usage
### Installation
```bash
pip install torch numpy librosa huggingface_hub
```
### Inference Script
```python
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
import librosa
from huggingface_hub import hf_hub_download
# 1. Vocabulary & Config
VOCAB = ["<pad>", "<blank>"] + list("abcdefghijklmnopqrstuvwxyz '-,.")
ID2CHAR = {i: c for i, c in enumerate(VOCAB)}
DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 2. Model Definition
class RotaryPositionalEmbedding(nn.Module):
def __init__(self, dim, max_seq_len=4096, base=10000.0):
super().__init__()
inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float() / dim))
self.register_buffer("inv_freq", inv_freq, persistent=False)
t = torch.arange(max_seq_len, dtype=torch.float32)
freqs = torch.outer(t, inv_freq)
emb = torch.cat((freqs, freqs), dim=-1)
self.register_buffer("cos_cached", emb.cos(), persistent=False)
self.register_buffer("sin_cached", emb.sin(), persistent=False)
def forward(self, x):
seq_len = x.size(2)
cos = self.cos_cached[:seq_len].unsqueeze(0).unsqueeze(0)
sin = self.sin_cached[:seq_len].unsqueeze(0).unsqueeze(0)
x1, x2 = x[..., : x.shape[-1] // 2], x[..., x.shape[-1] // 2 :]
rotated = torch.cat((-x2, x1), dim=-1)
return (x * cos) + (rotated * sin)
class CausalConvSubsampling(nn.Module):
def __init__(self, in_channels, out_channels):
super().__init__()
self.conv1 = nn.Conv2d(1, out_channels // 2, kernel_size=3, stride=2, padding=1)
self.conv2 = nn.Conv2d(out_channels // 2, out_channels, kernel_size=3, stride=2, padding=1)
def forward(self, x):
x = x.unsqueeze(1)
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
batch, channels, time_steps, freq = x.size()
return x.permute(0, 2, 1, 3).contiguous().view(batch, time_steps, channels * freq)
class SoundwhaleEncoderLayer(nn.Module):
def __init__(self, d_model=512, nhead=8, dim_feedforward=2048, dropout=0.1):
super().__init__()
self.d_model = d_model
self.nhead = nhead
self.head_dim = d_model // nhead
self.self_attn = nn.MultiheadAttention(d_model, nhead, dropout=dropout, batch_first=True)
self.rope = RotaryPositionalEmbedding(self.head_dim)
self.linear1 = nn.Linear(d_model, dim_feedforward)
self.dropout = nn.Dropout(dropout)
self.linear2 = nn.Linear(dim_feedforward, d_model)
self.norm1 = nn.LayerNorm(d_model)
self.norm2 = nn.LayerNorm(d_model)
self.dropout1 = nn.Dropout(dropout)
self.dropout2 = nn.Dropout(dropout)
def forward(self, src, attn_mask=None):
B, T, C = src.shape
src2 = self.norm1(src)
qkv = F.linear(src2, self.self_attn.in_proj_weight, self.self_attn.in_proj_bias)
q, k, v = qkv.chunk(3, dim=-1)
q = self.rope(q.view(B, T, self.nhead, self.head_dim).transpose(1, 2))
k = self.rope(k.view(B, T, self.nhead, self.head_dim).transpose(1, 2))
v = v.view(B, T, self.nhead, self.head_dim).transpose(1, 2)
attn_out = F.scaled_dot_product_attention(q, k, v, attn_mask=attn_mask)
attn_out = self.self_attn.out_proj(attn_out.transpose(1, 2).contiguous().view(B, T, C))
src = src + self.dropout1(attn_out)
src2 = self.norm2(src)
return src + self.dropout2(self.linear2(self.dropout(F.relu(self.linear1(src2)))))
class JalapenoASR56M(nn.Module):
def __init__(self, num_classes=len(VOCAB), d_model=512, num_layers=16, nhead=8, lookahead_frames=4):
super().__init__()
self.lookahead_frames = lookahead_frames
self.subsampling = CausalConvSubsampling(80, d_model)
self.proj = nn.Linear(d_model * 20, d_model)
self.layers = nn.ModuleList([
SoundwhaleEncoderLayer(d_model=d_model, nhead=nhead, dim_feedforward=2048)
for _ in range(num_layers)
])
self.ctc_head = nn.Linear(d_model, num_classes)
def forward(self, mel_input):
x = self.proj(self.subsampling(mel_input))
seq_len = x.size(1)
mask = torch.triu(
torch.full((seq_len, seq_len), float("-inf"), device=x.device),
diagonal=self.lookahead_frames + 1,
)
for layer in self.layers:
x = layer(x, attn_mask=mask)
return self.ctc_head(x)
# 3. Load Checkpoint & Transcribe
ckpt_path = hf_hub_download(
repo_id="Monster-Code/Jalapeno-ASR-preview",
filename="jalapeno_asr_preview.pt",
)
ckpt = torch.load(ckpt_path, map_location=DEVICE)
model = JalapenoASR56M(lookahead_frames=ckpt.get("lookahead_frames", 4)).to(DEVICE)
model.load_state_dict(ckpt["model_state"])
model.eval()
def transcribe(audio_path: str) -> str:
wav, _ = librosa.load(audio_path, sr=16000)
mel = librosa.feature.melspectrogram(
y=wav, sr=16000, n_fft=400, hop_length=160, n_mels=80, power=2.0, norm=None, htk=True
)
log_mel = torch.tensor(np.log(mel + 1e-5), dtype=torch.float32).transpose(0, 1).unsqueeze(0).to(DEVICE)
with torch.no_grad():
ids = torch.argmax(model(log_mel)[0], dim=-1).cpu().tolist()
chars, prev = [], None
for idx in ids:
if idx != prev and idx not in (0, 1):
chars.append(ID2CHAR.get(idx, ""))
prev = idx
return "".join(chars)
print(transcribe("sample.wav"))
```
---
## Limitations & Intended Use
* **Preview Release:** This checkpoint uses greedy character-level CTC decoding (`32`-token vocabulary: lowercase `a-z`, space, `'`, `-`, `,`, `.`). Pairing the output logits with an external 4-gram KenLM beam-search decoder (`pyctcdecode`) is recommended for production deployments to improve word boundary segmentation and rare-word spelling.
* **Language:** English only (`16 kHz` mono PCM audio). |