PrototypeAlignmentLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
A learned prototype-alignment layer per Sun et al. 2024 “TEST: Text Prototype Aligned
Embedding to Activate LLM’s Ability for Time Series”. Maintains a bank of
numPrototypes learnable embeddings of dimension embedDim. For each input
token, computes cosine similarity to every prototype, softmax-normalizes, then
aggregates prototypes by weight — producing an aligned representation that lives in
the same prototype subspace as a frozen LLM’s text-token embeddings.
Inheritance: LayerBase<T> → PrototypeAlignmentLayer<T>
Implements: IShapeContract
For Beginners
Think of this as a “translator” that maps each input patch to the closest matches in a small library of learned reference embeddings (prototypes). The output is a weighted blend of those reference embeddings, so downstream layers (often a frozen language model) see inputs in a vocabulary they already understand.
How It Works
Forward: input [B, N, D] → cosine similarity with prototypes
[K, D] → softmax over K → weights [B, N, K] → aggregate
prototypes → output [B, N, D].
The prototype bank is trainable and initialized with small random values. During training, the prototypes learn to represent the “grammar” of time-series patches in a way that is compatible with a downstream frozen LLM.
Reference: Sun, C. et al., “TEST: Text Prototype Aligned Embedding to Activate LLM’s Ability for Time Series”, ICLR 2024. https://openreview.net/forum?id=Tuh4nZVb0g.
Constructors
| Constructor | Summary |
|---|---|
PrototypeAlignmentLayer(int embedDim, int numPrototypes) |
Initializes a new PrototypeAlignmentLayer. |
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<OutputAxisContract> OutputAxesFor(int inputRank) |
Derived from this type’s [TensorLayout] declarations. |
IReadOnlyList<Tensor<T>> GetTrainableParameters() |
Returns all trainable parameter tensors marked with [TrainableParameter]. |
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). |