SALM<T>
Models & Types · AiDotNet.SpeechRecognition.LLMIntegrated
SALM (Chen et al., 2023): a speech-augmented language model that feeds a Fast Conformer encoder’s output through a Conformer modality adapter into a Megatron GPT with LoRA, for multitask speech recognition and translation with in-context learning.
Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → SALM<T>
Implements: ISpeechRecognizer<T>
For Beginners
SALM listens with a speech encoder, shortens what it hears to one token per 320 ms with two more Conformer layers, and places those tokens in front of a written instruction for a large language model. The language model then writes the answer, here a transcript. Words given in the instruction’s text context can steer the answer (the paper’s keyword boosting) without retraining.
How It Works
§3.1 of the paper: the audio encoder is the 110M Fast Conformer-large; the modality adapter is two Conformer layers
with 4x subsampling, giving a 320 ms frame shift, projected to the LLM’s width and prepended to the text context and
instruction; the LLM is NVIDIA’s 2B Megatron GPT (GPT-2B-001: 24 layers of width 2,048, SwiGLU, rotary embeddings on
half of each head, LayerNorm, no biases, untied embeddings, a 256,000-piece SentencePiece vocabulary), with LoRA of
rank 128 added; the LLM is frozen and the rest is trained. NeMo’s modular_speechllm release fixes the rest:
the adapter is NeMo’s ConformerEncoder with depthwise-separable striding; LoRA sits on the fused
query-key-value projection; the template is Q: {input}\nA: {output} without a beginning-of-sequence token and
with </s> after the answer; the loss covers the answer only. §4 trains with Adam (learning rate 1e-4,
weight decay 1e-3), cosine annealing after 2,000 warm-up steps and gradients clipped to 5. A model built here starts
from random weights and a frozen random LLM cannot fit a transcript, so the default updates every parameter; the
paper’s scope is EncoderAdapterAndLora.
Example
var architecture = new NeuralNetworkArchitecture<float>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.SpeechRecognition,
inputSize: 160000, outputSize: 256000);
var model = new SALM<float>(architecture);
var text = model.Transcribe(waveform).Text;
Constructors
| Constructor | Summary |
|---|---|
SALM(NeuralNetworkArchitecture<T> architecture, SALMOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
|
SALM(NeuralNetworkArchitecture<T> architecture, string modelPath, SALMOptions 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 LLM’s greedy answer (the paper’s default decoding) to the instruction, at most MaxTextLength tokens. |
string DetectLanguage(Tensor<T> audio) |