LocationSensitiveAttentionLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Location-sensitive attention (Chorowski et al. 2015) as Tacotron 2 uses it (Shen et al. 2018, §2.2): additive attention whose energies also read convolutional features of the previous and the cumulative attention weights.

Inheritance: LayerBase<T> → LocationSensitiveAttentionLayer<T>

Implements: IShapeContract

For Beginners

At every output frame the decoder decides which input characters to read next; remembering where it looked before keeps it moving steadily forward through the text.

How It Works

e_j = vᵀ tanh(W q + V h_j + U (F * [α_prev; α_cum])_j), α = softmax(e), context Σ_j α_j h_j. The paper projects inputs and location features to 128 dimensions and computes location features with 32 filters of length 31; following the reference implementation (NVIDIA tacotron2 Attention) the location convolution and every projection have no bias and the location features cover both the previous and the cumulative weights.

The layer is driven step by step with Attend; ProjectMemory projects the encoder output once per utterance.

Constructors

Constructor Summary
LocationSensitiveAttentionLayer(int queryDim, int memoryDim, int attentionDim, int filters, int kernelSize) Creates the layer.

Properties

Property Summary
bool SupportsTraining { get; }

Methods

Method Summary
Dictionary<string, string> GetParameterRoles() Returns parameter roles for per-role optimizer configuration (e.g., weight decay exemption for biases).
IReadOnlyList<ILayer<T>> GetSubLayers()
IReadOnlyList<OutputAxisContract> OutputAxesFor(int inputRank)
IReadOnlyList<Tensor<T>> GetTrainableParameters() Returns all trainable parameter tensors marked with [TrainableParameter].
Tensor<T> ProjectMemory(Tensor<T> memory) The once-per-utterance memory projection V h, [tokens, attentionDim].
ValueTuple<Tensor<T>, Tensor<T>> Attend(Tensor<T> query, Tensor<T> memory, Tensor<T> projectedMemory, Tensor<T> previousWeights, Tensor<T> cumulativeWeights) One attention step: the context [1, memoryDim] and the new weights [1, tokens] for the query [1, queryDim], the memory [tokens, memoryDim], its projection, and the previous and cumulative weights [1, tokens].
void ResetState()
void SetTrainableParameters(IReadOnlyList<Tensor<T>> parameters) Replaces trainable parameter tensors (e.g., with ParameterBuffer views).
void ZeroGrad() Clears all gradient fields discovered by convention ({paramName}Gradient).