core/nn/positional library
Positional encodings for sequence models.
Two variants, both Modules that take a [seqLen, embedDim] input
and return [seqLen, embedDim] with a position-dependent bias
added:
- SinusoidalPositionalEncoding — fixed, non-trainable, from "Attention Is All You Need" (Vaswani et al., 2017). No parameters; the encoding is recomputed on each forward for the exact sequence length (cheap, O(N * D), avoids needing a slice op).
- LearnedPositionalEmbedding — a trainable table of shape
[maxLen, embedDim], gathered by position indices[0, 1, ..., seqLen-1]via the existingEmbeddingop.
Both variants expect input shape [seqLen, embedDim] (single
sequence — the same 2D convention used by the rest of dart_pytorch).