Upload audact-stage_b_ctc8
Browse files- README.md +11 -8
- audact/audio_encoder.py +38 -2
- audact/voice_model.py +12 -5
- config.json +2 -2
- model.safetensors +1 -1
README.md
CHANGED
|
@@ -26,7 +26,7 @@ numbers or short strings. Built to work on **tools it never saw in training**.
|
|
| 26 |
## How it works
|
| 27 |
|
| 28 |
```
|
| 29 |
-
audio (16 kHz) -> FastConformer (NVIDIA, top
|
| 30 |
frames -> linear adapter (256 -> 512) -> take the place of the text query in Needle's input
|
| 31 |
[audio vectors] [<tools>] [tool list as compact JSON] -> Needle encoder (Cactus, fine-tuned)
|
| 32 |
Needle decoder -> <tool_call> [{"name": ..., "arguments": {...}}] or [] (no call)
|
|
@@ -57,11 +57,11 @@ ignored), false triggers (a call on a clip that needs none).
|
|
| 57 |
|
| 58 |
| | This model | NeuDecide (reference) |
|
| 59 |
|---|---|---|
|
| 60 |
-
| Synthetic val, unseen tools, TTS voices (908 clips): right tool / exact | **
|
| 61 |
| Synthetic val: false triggers (256 no-call clips) | **17%** | 79% |
|
| 62 |
-
| SLURP val, real voices (1,507 clips): right tool / exact |
|
| 63 |
-
| SLURP val: false triggers (152 no-call clips) | **
|
| 64 |
-
| SLURP val, scenarios held out of our training (alarm, social): right tool |
|
| 65 |
| Pure noise or silence, no speech (350 clips): false triggers | **0%** | not measured |
|
| 66 |
|
| 67 |
NeuDecide scores the same on alarm and social as on other scenarios, which suggests those were in its
|
|
@@ -74,12 +74,15 @@ training data; they were not in ours.
|
|
| 74 |
tends to pick a familiar-looking tool.
|
| 75 |
- Argument values are written as spoken ("next tuesday"); arithmetic and relative values belong in
|
| 76 |
the calling app.
|
| 77 |
-
- Exact match on real voices is low (
|
|
|
|
| 78 |
|
| 79 |
## Training
|
| 80 |
|
| 81 |
-
- Audio encoder: NVIDIA `stt_en_fastconformer_hybrid_medium_streaming_80ms`, frozen in stage A, top
|
| 82 |
-
layers fine-tuned in stage B
|
|
|
|
|
|
|
| 83 |
- Data: SLURP real recordings (scenarios alarm, social, transport, cooking, takeaway, audio and
|
| 84 |
recommendation held out), with LLM-written versions of its tools; synthetic spoken commands
|
| 85 |
(tools and commands from Glaive, ToolACE, xLAM and LLM-written ones) voiced by Kokoro and Piper
|
|
|
|
| 26 |
## How it works
|
| 27 |
|
| 28 |
```
|
| 29 |
+
audio (16 kHz) -> FastConformer (NVIDIA, top 8 of 16 layers fine-tuned) -> frames, about 13 per second
|
| 30 |
frames -> linear adapter (256 -> 512) -> take the place of the text query in Needle's input
|
| 31 |
[audio vectors] [<tools>] [tool list as compact JSON] -> Needle encoder (Cactus, fine-tuned)
|
| 32 |
Needle decoder -> <tool_call> [{"name": ..., "arguments": {...}}] or [] (no call)
|
|
|
|
| 57 |
|
| 58 |
| | This model | NeuDecide (reference) |
|
| 59 |
|---|---|---|
|
| 60 |
+
| Synthetic val, unseen tools, TTS voices (908 clips): right tool / exact | **85.7% / 53.3%** | 69.4% / 26.4% |
|
| 61 |
| Synthetic val: false triggers (256 no-call clips) | **17%** | 79% |
|
| 62 |
+
| SLURP val, real voices (1,507 clips): right tool / exact | 50.0% / **28.3%** | **55.9%** / 18.4% |
|
| 63 |
+
| SLURP val: false triggers (152 no-call clips) | **31%** | 97% |
|
| 64 |
+
| SLURP val, scenarios held out of our training (alarm, social): right tool | 16.2% | **55.0%** |
|
| 65 |
| Pure noise or silence, no speech (350 clips): false triggers | **0%** | not measured |
|
| 66 |
|
| 67 |
NeuDecide scores the same on alarm and social as on other scenarios, which suggests those were in its
|
|
|
|
| 74 |
tends to pick a familiar-looking tool.
|
| 75 |
- Argument values are written as spoken ("next tuesday"); arithmetic and relative values belong in
|
| 76 |
the calling app.
|
| 77 |
+
- Exact match on real voices is low (28%): mishearing names, places and times, and choosing which
|
| 78 |
+
optional arguments to fill.
|
| 79 |
|
| 80 |
## Training
|
| 81 |
|
| 82 |
+
- Audio encoder: NVIDIA `stt_en_fastconformer_hybrid_medium_streaming_80ms`, frozen in stage A, top 8
|
| 83 |
+
layers fine-tuned in stage B, with a transcription side task (FastConformer's own speech-to-text head
|
| 84 |
+
trained on our transcripts at weight 0.1; the head is for training only and isn't included). Its word
|
| 85 |
+
error rate on SLURP val fell from 44% to 31%. Text side: Cactus `Needle` (26M), ported from JAX to PyTorch.
|
| 86 |
- Data: SLURP real recordings (scenarios alarm, social, transport, cooking, takeaway, audio and
|
| 87 |
recommendation held out), with LLM-written versions of its tools; synthetic spoken commands
|
| 88 |
(tools and commands from Glaive, ToolACE, xLAM and LLM-written ones) voiced by Kokoro and Piper
|
audact/audio_encoder.py
CHANGED
|
@@ -19,6 +19,31 @@ REVISION = "4207369a33"
|
|
| 19 |
FRAME_DIM = 256 # FastConformer medium's output width
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
class AudioEncoder(nn.Module):
|
| 23 |
"""FastConformer's preprocessor + encoder; the ASR decoders (RNNT, CTC) are dropped."""
|
| 24 |
|
|
@@ -37,6 +62,11 @@ class AudioEncoder(nn.Module):
|
|
| 37 |
for layer in self.encoder.layers[len(self.encoder.layers) - k:] if k else []:
|
| 38 |
for p in layer.parameters():
|
| 39 |
p.requires_grad = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
self.train(self.training)
|
| 41 |
|
| 42 |
def train(self, mode: bool = True) -> AudioEncoder:
|
|
@@ -55,7 +85,9 @@ class AudioEncoder(nn.Module):
|
|
| 55 |
return frames.transpose(1, 2), frame_lengths # (B, T, 256), (B,)
|
| 56 |
|
| 57 |
@classmethod
|
| 58 |
-
def from_pretrained(cls, device: str = "cpu") -> AudioEncoder:
|
|
|
|
|
|
|
| 59 |
import nemo.collections.asr as nemo_asr
|
| 60 |
from huggingface_hub import hf_hub_download
|
| 61 |
|
|
@@ -63,4 +95,8 @@ class AudioEncoder(nn.Module):
|
|
| 63 |
asr = nemo_asr.models.ASRModel.restore_from(path, map_location=device)
|
| 64 |
asr.preprocessor.featurizer.dither = 0.0 # no random noise in the features: same audio, same frames
|
| 65 |
asr.preprocessor.featurizer.pad_to = 0
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
FRAME_DIM = 256 # FastConformer medium's output width
|
| 20 |
|
| 21 |
|
| 22 |
+
def _checkpoint_forward(layer: nn.Module) -> None:
|
| 23 |
+
"""Gradient checkpointing for one learning layer: its intermediate results aren't kept for backward but
|
| 24 |
+
recomputed then (same math; dropout replays the same random numbers). With 8 learning layers a heavy
|
| 25 |
+
batch needed more than 6.4 GB in backward (stage_b_ctc8, 2026-11-27)."""
|
| 26 |
+
if getattr(layer, "_checkpointed", False):
|
| 27 |
+
return
|
| 28 |
+
from torch.utils.checkpoint import checkpoint
|
| 29 |
+
|
| 30 |
+
plain = layer.forward
|
| 31 |
+
|
| 32 |
+
def forward(*args, **kwargs):
|
| 33 |
+
if not (torch.is_grad_enabled() and layer.training):
|
| 34 |
+
return plain(*args, **kwargs)
|
| 35 |
+
# checkpoint saves and replays the GPU's random numbers (dropout) only for devices of tensors passed
|
| 36 |
+
# by position, and NeMo passes everything by name (x=..., att_mask=...): without this the recomputed
|
| 37 |
+
# pass drew new dropout masks and gave wrong gradients (checked 2026-11-27).
|
| 38 |
+
if not args and "x" in kwargs:
|
| 39 |
+
x = kwargs.pop("x")
|
| 40 |
+
return checkpoint(lambda x, **kw: plain(x=x, **kw), x, use_reentrant=False, **kwargs)
|
| 41 |
+
return checkpoint(plain, *args, use_reentrant=False, **kwargs)
|
| 42 |
+
|
| 43 |
+
layer.forward = forward
|
| 44 |
+
layer._checkpointed = True
|
| 45 |
+
|
| 46 |
+
|
| 47 |
class AudioEncoder(nn.Module):
|
| 48 |
"""FastConformer's preprocessor + encoder; the ASR decoders (RNNT, CTC) are dropped."""
|
| 49 |
|
|
|
|
| 62 |
for layer in self.encoder.layers[len(self.encoder.layers) - k:] if k else []:
|
| 63 |
for p in layer.parameters():
|
| 64 |
p.requires_grad = True
|
| 65 |
+
if getattr(self, "ctc_head", None) is not None: # the transcription side task trains it too
|
| 66 |
+
for p in self.ctc_head.parameters():
|
| 67 |
+
p.requires_grad = True
|
| 68 |
+
for layer in self.encoder.layers[len(self.encoder.layers) - k:] if k else []:
|
| 69 |
+
_checkpoint_forward(layer)
|
| 70 |
self.train(self.training)
|
| 71 |
|
| 72 |
def train(self, mode: bool = True) -> AudioEncoder:
|
|
|
|
| 85 |
return frames.transpose(1, 2), frame_lengths # (B, T, 256), (B,)
|
| 86 |
|
| 87 |
@classmethod
|
| 88 |
+
def from_pretrained(cls, device: str = "cpu", with_ctc: bool = False) -> AudioEncoder:
|
| 89 |
+
"""with_ctc: also keep FastConformer's CTC speech-to-text head and its tokenizer, for the
|
| 90 |
+
transcription side task in Stage B (2026-11-26). Inference never uses them."""
|
| 91 |
import nemo.collections.asr as nemo_asr
|
| 92 |
from huggingface_hub import hf_hub_download
|
| 93 |
|
|
|
|
| 95 |
asr = nemo_asr.models.ASRModel.restore_from(path, map_location=device)
|
| 96 |
asr.preprocessor.featurizer.dither = 0.0 # no random noise in the features: same audio, same frames
|
| 97 |
asr.preprocessor.featurizer.pad_to = 0
|
| 98 |
+
enc = cls(asr.preprocessor, asr.encoder)
|
| 99 |
+
if with_ctc:
|
| 100 |
+
enc.ctc_head = asr.ctc_decoder # frames (B, 256, T) -> log-probs (B, T, 1025), blank = 1024
|
| 101 |
+
enc.ctc_tokenizer = asr.tokenizer # lowercase SentencePiece, 1,024 pieces
|
| 102 |
+
return enc.eval()
|
audact/voice_model.py
CHANGED
|
@@ -225,10 +225,16 @@ class VoiceToolModel(nn.Module):
|
|
| 225 |
return self.encode(self.batch_frames(batch), batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 226 |
return self.encode_text(batch.prefix, batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 227 |
|
| 228 |
-
def forward_batch(self, batch
|
| 229 |
-
"""A src.train_data.Batch (audio or text rows) -> logits (B, T_d, 8192)
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
def frames_from_audio(self, waveform: torch.Tensor, lengths: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 234 |
"""waveform (B, samples), lengths (B,) -> frames (B, T_a, 256), frame_lengths (B,)."""
|
|
@@ -267,6 +273,7 @@ def load_checkpoint(path, device: str = "cuda") -> VoiceToolModel:
|
|
| 267 |
model.needle.load_state_dict(ck["needle"])
|
| 268 |
if "audio_encoder" in ck:
|
| 269 |
from .audio_encoder import AudioEncoder
|
| 270 |
-
|
|
|
|
| 271 |
model.audio_encoder.load_state_dict(ck["audio_encoder"])
|
| 272 |
return model.to(device)
|
|
|
|
| 225 |
return self.encode(self.batch_frames(batch), batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 226 |
return self.encode_text(batch.prefix, batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 227 |
|
| 228 |
+
def forward_batch(self, batch, return_frames: bool = False):
|
| 229 |
+
"""A src.train_data.Batch (audio or text rows) -> logits (B, T_d, 8192); with return_frames also the
|
| 230 |
+
audio frames (B, T_a, 256) it used (for the CTC side task), None for text rows."""
|
| 231 |
+
frames = self.batch_frames(batch) if batch.kind == "audio" else None
|
| 232 |
+
if frames is not None:
|
| 233 |
+
memory, memory_mask = self.encode(frames, batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 234 |
+
else:
|
| 235 |
+
memory, memory_mask = self.encode_text(batch.prefix, batch.prefix_lengths, batch.tool_ids, batch.tool_lengths)
|
| 236 |
+
logits = self.needle.decode(batch.decoder_in, memory, memory_mask)
|
| 237 |
+
return (logits, frames) if return_frames else logits
|
| 238 |
|
| 239 |
def frames_from_audio(self, waveform: torch.Tensor, lengths: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
|
| 240 |
"""waveform (B, samples), lengths (B,) -> frames (B, T_a, 256), frame_lengths (B,)."""
|
|
|
|
| 273 |
model.needle.load_state_dict(ck["needle"])
|
| 274 |
if "audio_encoder" in ck:
|
| 275 |
from .audio_encoder import AudioEncoder
|
| 276 |
+
with_ctc = any(k.startswith("ctc_head.") for k in ck["audio_encoder"]) # side-task runs saved the head
|
| 277 |
+
model.audio_encoder = AudioEncoder.from_pretrained(device=device, with_ctc=with_ctc)
|
| 278 |
model.audio_encoder.load_state_dict(ck["audio_encoder"])
|
| 279 |
return model.to(device)
|
config.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
| 17 |
"audio_encoder": {
|
| 18 |
"base": "nvidia/stt_en_fastconformer_hybrid_medium_streaming_80ms",
|
| 19 |
"revision": "4207369a33",
|
| 20 |
-
"trained_layers":
|
| 21 |
},
|
| 22 |
"tokenizer": {
|
| 23 |
"file": "tokenizer.model",
|
|
@@ -27,7 +27,7 @@
|
|
| 27 |
"max_input_positions": 1024,
|
| 28 |
"decoding": "whole-name scoring, then greedy arguments",
|
| 29 |
"trained_from": {
|
| 30 |
-
"checkpoint": "runs/stage_a/
|
| 31 |
"update": 4898
|
| 32 |
},
|
| 33 |
"parameters": 52559132
|
|
|
|
| 17 |
"audio_encoder": {
|
| 18 |
"base": "nvidia/stt_en_fastconformer_hybrid_medium_streaming_80ms",
|
| 19 |
"revision": "4207369a33",
|
| 20 |
+
"trained_layers": 8
|
| 21 |
},
|
| 22 |
"tokenizer": {
|
| 23 |
"file": "tokenizer.model",
|
|
|
|
| 27 |
"max_input_positions": 1024,
|
| 28 |
"decoding": "whole-name scoring, then greedy arguments",
|
| 29 |
"trained_from": {
|
| 30 |
+
"checkpoint": "runs/stage_a/stage_b_ctc8/model_step4898.pt",
|
| 31 |
"update": 4898
|
| 32 |
},
|
| 33 |
"parameters": 52559132
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 210423928
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c92099ea32dae23a27d468503b71040420033c28b29566d0e4f72dd6ad0a0845
|
| 3 |
size 210423928
|