BartEncoderDecoderLayer<T>
Layers · AiDotNet.NeuralNetworks.Layers
The BART encoder-decoder Florence-2 uses as its language model (Lewis et al. 2020; HF BartModel).
Inheritance: LayerBase<T> → BartEncoderDecoderLayer<T>
Implements: IShapeContract
How It Works
The architecture follows the reference:
- Learned absolute positions with BART’s offset of 2, then
layernorm_embedding. - Post-norm blocks with biased projections and GELU feed-forwards.
- A causal decoder with cross-attention.
- A head tied to the shared embedding.
The encoder takes precomputed embeddings, so Florence-2 can splice image tokens ahead of its text. BART’s
final_logits_bias is a zero buffer and is omitted. Dropout is applied to the residual branches in
training mode.
Constructors
| Constructor | Summary |
|---|---|
BartEncoderDecoderLayer(int vocabSize, int dim, int numHeads, int ffnDim, int numEncoderLayers, int numDecoderLayers, int maxPositions, double dropoutRate) |
Properties
| Property | Summary |
|---|---|
bool SupportsTraining { get; } |
|
int Dim { get; } |
|
int MaxPositions { get; } |
Longest encoder or decoder sequence the learned positions cover. |
int VocabSize { 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]. |
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). |
Fields
| Field | Summary |
|---|---|
int DecoderStartTokenId |
BART’s decoder start token (also EOS). |