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