CIFEncoder<T>
Models & Types · AiDotNet.SpeechRecognition.ConformerFamily
CIF (Continuous Integrate-and-Fire) encoder for soft monotonic alignment in ASR.
Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → CIFEncoder<T>
Implements: ISpeechRecognizer<T>
For Beginners
CIF provides a soft, monotonic alignment mechanism between encoder frames and output tokens. Each encoder frame produces a firing weight; when cumulative weight exceeds a threshold (1.0), the accumulated weighted features “fire” as an output token…
How It Works
References:
- Paper: “CIF: Continuous Integrate-and-Fire for End-to-End Speech Recognition” (Dong & Xu, 2020)
CIF provides a soft, monotonic alignment mechanism between encoder frames and output tokens. Each encoder frame produces a firing weight; when cumulative weight exceeds a threshold (1.0), the accumulated weighted features “fire” as an output token representation. This enables non-autoregressive decoding (like Paraformer) while maintaining monotonic alignment.
Example
// Create a CIF encoder model for soft monotonic alignment ASR
var architecture = new NeuralNetworkArchitecture<double>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.SpeechRecognition,
inputHeight: 16000, inputWidth: 1, inputDepth: 1, outputSize: 5000);
var model = new CIFEncoder<double>(architecture);
// Or load a pre-trained ONNX model for CIF-based encoding
var onnxModel = new CIFEncoder<double>(architecture, "cifencoder.onnx");
Constructors
| Constructor | Summary |
|---|---|
CIFEncoder(NeuralNetworkArchitecture<T> architecture, CIFEncoderOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
Creates a CIF encoder in native training mode. |
CIFEncoder(NeuralNetworkArchitecture<T> architecture, string modelPath, CIFEncoderOptions options) |
Creates a CIF encoder in native training mode. |
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 CIF-based soft monotonic alignment. |
string DetectLanguage(Tensor<T> audio) |