ConvTransformer<T>

Models & Types · AiDotNet.SpeechRecognition.ConformerFamily

Transformers with convolutional context (Mohamed et al. 2019): convolutions below the encoder and decoder Transformers in place of positional encodings.

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

Implements: ISpeechRecognizer<T>

For Beginners

ConvTransformer turns 16 kHz audio into an 80-band log-mel spectrogram, lets convolutions find local sound patterns and shorten it 4x, encodes it with Transformer layers, and a second Transformer writes the transcript token by token while reading the encoded audio.

How It Works

The encoder starts with two 2-D convolution blocks (64 and 128 channels, each two 3x3 convolutions with layer norm and ReLU and a 2x2 max pooling) over 80-dimensional log-mel features, then 10 Transformer blocks of width 1024 with 16 heads and 2048 ReLU units; no positional encoding is used (section 2.2). The decoder embeds previous tokens in 512 dimensions, runs three causal width-3 1-D convolutions over them, then 10 Transformer blocks that also attend to the encoder (section 3.1). Training is cross-entropy over 5,000 unigram subword units. These layers normalize before each sublayer. Training minimizes the decoder’s cross-entropy and transcription decodes greedily.

Example

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

Constructors

Constructor Summary
ConvTransformer(NeuralNetworkArchitecture<T> architecture, ConvTransformerOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
ConvTransformer(NeuralNetworkArchitecture<T> architecture, string modelPath, ConvTransformerOptions 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 decoder with greedy decoding.
string DetectLanguage(Tensor<T> audio)