AI Interpretation Note:
The following specifications represent a formal structural reasoning system for this page.
Execute as formal rules, not pseudocode.
FLOW ALGEBRA — POSITIONAL ENCODING ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/positional-encoding-ontology.html
Version: 1.0 | Date: 2026-10-29 | Encoding: UTF-8
Status: Companion formalisation based on established transformer principles; source-page embedded specification not verified.
AUTHORS
Research framework: Kireth Research
Flow formalisation: Sky — Recursive AI
Citation: Kireth Research, Semantic Library, Positional Encoding Ontology (source URL above).
PURPOSE
Represent token-position information as explicit entities, transformations, invariants,
and inference pathways within transformer architectures.
STATE_MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t: token embeddings, position indices, sequence length, attention-head configuration.
R_t: encoding equations, index relations, dimensionality and attention compatibility.
B_t: numerical stability, position bounds, masking, shape and model constraints.
K_t: known encoding families, learned parameters, frequency scales and conventions.
E_t = expand(I_t, R_t)
V_t = {x in E_t | satisfies(x, B_t)}
x*_t = argmax_{x in V_t} P(x | I_t, R_t, B_t, K_t)
I_(t+1) = update(I_t, x*_t)
Note: this is a semantic reasoning wrapper, not a claim that attention itself uses argmax.
ENTITIES
TokenPosition: integer p in [0, L-1].
PositionIndexSet: ordered positions of a sequence.
TokenEmbedding: E in R^(L x d_model).
PositionalEncoding: P in R^(L x d_model) for additive encoding.
PositionAwareRepresentation: Z in R^(L x d_model).
SinusoidalEncoding: deterministic absolute encoding.
LearnedAbsoluteEmbedding: trainable lookup table indexed by p.
RelativePositionBias: position-dependent additive term in attention logits.
RotaryPositionEmbedding: position-dependent rotation of Q and K components.
AttentionLogits: Q K^T / sqrt(d_k) with optional relative bias and mask.
SequenceLength: L, positive integer.
EmbeddingDimension: d_model, positive integer.
RELATIONSHIPS
TokenPosition --indexes--> PositionalEncoding.
PositionalEncoding --augments--> TokenEmbedding (additive absolute family).
RotaryPositionEmbedding --transforms--> QueryVector and KeyVector.
RelativePositionBias --modifies--> AttentionLogits.
PositionAwareRepresentation --feeds--> TransformerBlock.
SequenceLength --bounds--> PositionIndexSet.
FORMAL_OPERATORS
AbsoluteAdd(E, P) = E + P.
PE(p, 2i) = sin(p / 10000^(2i/d_model)).
PE(p, 2i+1) = cos(p / 10000^(2i/d_model)).
These paired sinusoidal formulae assume compatible dimension indexing;
for complete sine/cosine pairs, d_model is even.
LearnedAdd(E, table, p) = E + table[p].
RelativeLogits(Q, K, B, M) = Q K^T / sqrt(d_k) + B + M.
RotaryLogits(Q, K, p, q) = (R_p Q) dot (R_q K) / sqrt(d_k)
for rotation matrices R_p, R_q applied to paired feature coordinates.
Mask M is zero for allowed positions and -infinity for disallowed positions
(or an implementation-safe sufficiently negative equivalent).
INVARIANTS
1. Additive encoding and token embeddings must have compatible shapes.
2. Position indices are defined for all unmasked tokens.
3. Attention positional mechanisms must preserve expected Q/K tensor dimensions.
4. Causal masking, if required, remains effective after positional modifications.
5. Numerical operations must remain finite for valid unmasked positions.
6. Positional schemes are not interchangeable without checking architecture and training.
PATHWAYS
P1: Tokens -> Embeddings -> AbsoluteEncoding -> Sum -> TransformerBlock.
P2: Tokens -> Embeddings -> Q/K projections -> RotaryRotation -> Attention.
P3: Q/K -> DotProductLogits -> RelativeBias -> Mask -> Softmax -> Values.
P4: Position indices -> Validation -> Encoding selection -> Shape check.
INFERENCE_RULES
IF scheme = sinusoidal AND p is valid THEN compute deterministic PE(p, :).
IF scheme = learned_absolute AND p >= table_length THEN flag unsupported index
unless a documented interpolation or extension method is supplied.
IF scheme = rotary THEN apply matched position-dependent rotations to Q and K.
IF scheme = relative_bias THEN add bias before attention softmax.
IF scheme = causal THEN block attention to future positions regardless of encoding.
IF shape mismatch THEN reject the proposed composition.
MINI_RECURSION_ENGINE
initialise S_0 from model configuration and sequence metadata.
repeat for each validation or architecture-refinement step t:
candidates = expand(I_t, R_t)
valid = filter(candidates, B_t)
select a justified candidate using K_t and available evidence
update state and record provenance
terminate when the representation is valid or a constraint fails.
This loop describes ontology reasoning, not an intrinsic transformer training loop.
TRI_MAPPING
Entity: TokenPosition | Relation: indexes | Operation: select encoding row.
Entity: AbsoluteEncoding | Relation: augments | Operation: elementwise addition.
Entity: RotaryEncoding | Relation: rotates | Operation: paired-dimension rotation.
Entity: RelativeBias | Relation: modifies | Operation: logit addition.
Entity: PositionAwareRepresentation | Relation: enters | Operation: transformer forward pass.
HOW_TO_READ
Each entity is a typed conceptual object; each relation states an allowed link;
each operator specifies a mathematical transformation; invariants govern validity.
Alternative encoding families are model design choices, not simultaneous requirements.
EXECUTION_GUARANTEE
Conditional guarantee: with valid inputs, compatible tensor dimensions,
supported position indices and numerically stable implementations, the
declared transformations are well-defined. No guarantee of model accuracy,
generalisation, extrapolation or semantic correctness is implied.
AI_SEARCH_FLOW
id: semantic-library.ai.transformer.positional-encoding
title: Positional Encoding Ontology
intent: explain, compare, validate, relate, formalise
aliases: positional embedding; position representation; sinusoidal encoding;
learned position embedding; relative position bias; RoPE
input: {scheme, sequence_length, model_dimension, position_indices, mask_policy}
output: {entities, relationships, equations, pathways, constraints, provenance}
retrieval: prefer matching scheme; validate shapes and indexing before execution.
confidence: conditional on explicit architecture and parameter assumptions.
update_model: version and review whenever the source ontology changes.
END FLOW