BiaffineSpanScorerLayer<T>

Layers · AiDotNet.NeuralNetworks.Layers

Biaffine span scorer per Yu et al., ACL 2020, “Named Entity Recognition as Dependency Parsing” (arXiv:2005.07150). Scores every (start, end) span against every entity category in one pass.

Inheritance: LayerBase<T> → BiaffineSpanScorerLayer<T>

Implements: IShapeContract

How It Works

Scoring function (paper §2):

where U_m is a d x c x d tensor, W_m is 2d x c, h_s and h_e come from two SEPARATE feed-forward networks over the encoder output, and (+) is concatenation. The bilinear term is what couples the start and end boundaries; a plain MLP over concatenated endpoints (the additive term alone) cannot represent it, which is precisely the paper’s point.

Shapes: input [B, S, D] token representations; output [B, S * S, C] — the flattened S x S span grid scored over C categories, with row-major index start * S + end. The grid is kept rank-3 so it composes with the rest of the layer stack; consumers reshape to [S, S, C] and mask the lower triangle, since the paper only considers spans with start <= end.

Gradient tracking: every operation goes through IEngine so the tape records the whole scorer automatically. The bilinear term is evaluated as (H_s . U_c) . H_e^T per category using batched matmuls rather than an explicit triple loop, so there is no scalar arithmetic on the gradient path.

Constructors

Constructor Summary
BiaffineSpanScorerLayer(int inputDim, int spanDim, int numCategories, IActivationFunction<T> activation, double ffnnDropout, int ffnnDepth) Initializes a new biaffine span scorer.

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].
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).