Branchformer<T>

Models & Types · AiDotNet.SpeechRecognition.ConformerFamily

Branchformer (Peng et al. 2022): parallel self-attention and convolutional gating MLP branches, merged by concatenation.

Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → Branchformer<T>

Implements: ISpeechRecognizer<T>

For Beginners

Branchformer turns 16 kHz audio into an 80-band log-mel spectrogram, shortens it 4x with two convolutions, and encodes it with Conformer blocks, each mixing self-attention (long-range context) with a convolution (local patterns). A linear layer gives every frame a probability for each token; collapsing repeats and blanks gives the transcript.

How It Works

Each block runs pre-norm self-attention (global context) and a convolutional gating MLP (local context) side by side and merges them by concatenation and a linear projection (section 3). The defaults are the Branchformer of the ESPnet LibriSpeech recipe (train_asr_branchformer_hop_length160_e18_linear3072): 18 blocks, width 512, 8 heads, 3072 gating-MLP units and a 31-wide gating convolution, with a 6-layer Transformer decoder trained jointly with CTC (CTC weight 0.3, label smoothing 0.1) and a 5000-token vocabulary. SpecAugment masks the features in training (section 3.1). Training minimizes the joint CTC/attention loss (Watanabe et al. 2017); transcription decodes the attention decoder greedily. The paper’s blocks use relative positional encoding; these use rotary position encoding, the relative scheme ConformerBlockLayer provides.

Example

var architecture = new NeuralNetworkArchitecture<float>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.SpeechRecognition,
    inputSize: 16000, outputSize: 34);
var model = new Branchformer<float>(architecture);
var text = model.Transcribe(waveform).Text;

Constructors

Constructor Summary
Branchformer(NeuralNetworkArchitecture<T> architecture, BranchformerOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
Branchformer(NeuralNetworkArchitecture<T> architecture, string modelPath, BranchformerOptions options)

Properties

Property Summary
IReadOnlyList<string> SupportedLanguages { get; }
bool SupportsStreaming { get; }
bool SupportsWordTimestamps { get; }

Methods

Method Summary
IReadOnlyDictionary<string, T> DetectLanguageProbabilities(Tensor<T> audio)
IStreamingTranscriptionSession<T> StartStreamingSession(string language)
ModelMetadata<T> GetModelMetadata()
Task<TranscriptionResult<T>> TranscribeAsync(Tensor<T> audio, string language, bool? includeTimestamps, CancellationToken cancellationToken)
Tensor<T> ForwardForTraining(Tensor<T> input)
TranscriptionResult<T> Transcribe(Tensor<T> audio, string language, bool? includeTimestamps) Transcribes audio: the encoder and the attention decoder with greedy decoding.
string DetectLanguage(Tensor<T> audio)