Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Speechbrain Speechbrain Train Switchboard Transformer

From Leeroopedia


Knowledge Sources
Domains ASR, Training
Last Updated 2026-02-09 00:00 GMT

Overview

Concrete tool for training a Transformer ASR model on the Switchboard dataset provided by the SpeechBrain library.

Description

This recipe defines the ASR class (subclass of sb.core.Brain) for Transformer-based speech recognition on Switchboard conversational telephone speech (~300 hours). The architecture uses a convolutional frontend and a Transformer encoder-decoder with joint CTC/attention training and label smoothing. Beam search decoding coupled with a Transformer language model is used at evaluation. The class accepts a custom normalize_fn for Switchboard transcript normalization. The best model is averaged over the last 5 checkpoints.

Usage

Use this recipe to train a Transformer ASR model with CTC/attention joint decoding on the Switchboard dataset. Requires the corresponding hyperparameter YAML file, a pre-trained tokenizer and language model, and data preparation script.

Code Reference

Source Location

Signature

class ASR(sb.core.Brain):
    def __init__(self, modules=None, opt_class=None, hparams=None,
                 run_opts=None, checkpointer=None, normalize_fn=None):
        ...
    def compute_forward(self, batch, stage):
        """Forward computations from the waveform batches to the output probabilities."""
        ...
    def compute_objectives(self, predictions, batch, stage):
        """Computes the loss (CTC+NLL) given predictions and targets."""
        ...

Import

# Run as recipe script
python recipes/Switchboard/ASR/transformer/train.py hparams/transformer.yaml --data_folder /path/to/switchboard

I/O Contract

Inputs

Name Type Required Description
batch.sig torch.Tensor Yes Input waveform signal
batch.tokens_bos torch.Tensor Yes Target token sequence with BOS prefix
batch.tokens_eos torch.Tensor Yes Target token sequence with EOS suffix
batch.tokens torch.Tensor Yes Target token sequence (for CTC)

Outputs

Name Type Description
p_ctc torch.Tensor CTC log-probabilities from encoder
p_seq torch.Tensor Seq2seq log-probabilities from Transformer decoder
wav_lens torch.Tensor Relative waveform lengths
hyps list Beam search hypotheses (at validation/test)

Usage Examples

python train.py hparams/transformer.yaml --data_folder /path/to/Switchboard

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment