XLSR<T>

Models & Types · AiDotNet.SpeechRecognition.Multilingual

XLS-R: cross-lingual speech representation at scale

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

Implements: ISpeechRecognizer<T>

For Beginners

XLS-R scales wav2vec 2.0 pre-training to 128 languages using 436k hours of unlabeled speech. The model (up to 2B parameters) uses the same contrastive pre-training approach but with massively multilingual data. Fine-tuning with CTC on labeled data…

How It Works

References:

  • Paper: “XLS-R: Self-supervised Cross-lingual Speech Representation Learning at Scale” (Babu et al., Meta, 2022)

XLS-R scales wav2vec 2.0 pre-training to 128 languages using 436k hours of unlabeled speech. The model (up to 2B parameters) uses the same contrastive pre-training approach but with massively multilingual data. Fine-tuning with CTC on labeled data achieves strong results across many languages, with particularly significant improvements for low-resource languages. The cross-lingual transfer is enabled by shared phonetic structures across languages.

Example

// Create an XLS-R model for cross-lingual speech representation (128 languages)
var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.SpeechRecognition,
    inputHeight: 16000, inputWidth: 1, inputDepth: 1, outputSize: 5000);
var model = new XLSR<double>(architecture);
            
// Or load a pre-trained ONNX model for cross-lingual ASR
var onnxModel = new XLSR<double>(architecture, "xlsr.onnx");

Constructors

Constructor Summary
XLSR(NeuralNetworkArchitecture<T> architecture, XLSROptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer)
XLSR(NeuralNetworkArchitecture<T> architecture, string modelPath, XLSROptions 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 using XLS-R’s cross-lingual SSL encoder with CTC.
string DetectLanguage(Tensor<T> audio)
void LoadTorchWeights(Func<string, int[], double[]> read) Loads a transformers *ForCTC state dict straight from source.