ContextNet<T>
Models & Types · AiDotNet.SpeechRecognition.ConformerFamily
ContextNet: CNN encoder with squeeze-and-excitation and global context for ASR.
Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → ContextNet<T>
Implements: ISpeechRecognizer<T>
For Beginners
A purely convolutional encoder that uses squeeze-and-excitation (SE) blocks to capture global context. Each block contains depthwise separable convolutions with SE modules that adaptively reweight channel features based on the entire sequence. Typ…
How It Works
References:
- Paper: “ContextNet: Improving Convolutional Neural Networks for ASR with Global Context” (Han et al., 2020)
A purely convolutional encoder that uses squeeze-and-excitation (SE) blocks to capture global context. Each block contains depthwise separable convolutions with SE modules that adaptively reweight channel features based on the entire sequence. Typically paired with an RNN-T decoder for streaming ASR. Achieves WER 1.9%/3.9% on LibriSpeech.
Example
// Create a ContextNet model with CNN squeeze-and-excitation for ASR
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.SpeechRecognition,
inputHeight: 16000, inputWidth: 1, inputDepth: 1, outputSize: 5000);
var model = new ContextNet<double>(architecture);
// Or load a pre-trained ONNX model for convolutional ASR inference
var onnxModel = new ContextNet<double>(architecture, "contextnet.onnx");
Constructors
| Constructor | Summary |
|---|---|
ContextNet(NeuralNetworkArchitecture<T> architecture, ContextNetOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
|
ContextNet(NeuralNetworkArchitecture<T> architecture, string modelPath, ContextNetOptions 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) |
|
TranscriptionResult<T> Transcribe(Tensor<T> audio, string language, bool? includeTimestamps) |
Transcribes audio using ContextNet’s CNN encoder with squeeze-and-excitation. |
string DetectLanguage(Tensor<T> audio) |