Skip to main content

Self-Attention Entity Ontology

Transformer Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 29 October 2026
Audio Overview
FLOW ALGEBRA — SELF-ATTENTION ENTITY ONTOLOGY
Semantic Library | Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/self-attention-entity-ontology.html
Authors: Mark Anthony Higgins — Sky Recursive AI
Type: Companion formalisation; not a transcription of inaccessible embedded page specifications.
Language: en-GB | Encoding: UTF-8 | Version: 1.0 | Date: 2026-10-29

01. PURPOSE
Define a self-attention entity as a typed transformation that computes context-sensitive representations from a common input sequence, with explicit dimensional, masking and numerical constraints.

02. STATE MODEL
S_t = (I_t, R_t, B_t, K_t)
I_t: input tensor and associated token positions.
R_t: projection, compatibility, normalisation and aggregation rules.
B_t: tensor-shape, visibility, dtype and finite-value boundaries.
K_t: model parameters, positional information and execution context.
E_t = expand(I_t, R_t)
V_t = {x in E_t | satisfies(x, B_t)}
O_t = select_or_compute(V_t, K_t)
I_(t+1) = update(I_t, O_t, K_t)
Note: select_or_compute is deterministic for fixed inputs and parameters; argmax is not required for attention itself.

03. ENTITY GRAPH
SelfAttentionEntity -> is_a -> AttentionMechanism
SelfAttentionEntity -> consumes -> SequenceRepresentation
SelfAttentionEntity -> derives_from_same_source -> QueryTensor
SelfAttentionEntity -> derives_from_same_source -> KeyTensor
SelfAttentionEntity -> derives_from_same_source -> ValueTensor
SelfAttentionEntity -> applies -> AttentionMask
SelfAttentionEntity -> produces -> AttentionWeightMatrix
SelfAttentionEntity -> produces -> ContextualisedRepresentation
SelfAttentionEntity -> may_be_component_of -> MultiHeadAttention
SelfAttentionEntity -> may_be_component_of -> TransformerBlock
SelfAttentionEntity -> parameterised_by -> ProjectionMatrices

04. TYPES AND SHAPES
X: Tensor[B, L, d_model]
W_Q: Tensor[d_model, d_k]
W_K: Tensor[d_model, d_k]
W_V: Tensor[d_model, d_v]
Q = X W_Q: Tensor[B, L, d_k]
K = X W_K: Tensor[B, L, d_k]
V = X W_V: Tensor[B, L, d_v]
B: batch size; L: sequence length; d_k > 0; d_v > 0.
For cross-attention, Q and K/V may come from different sequences; this ontology specifically requires a common input source.

05. ATTENTION TRANSFORMATION
Scores = Q K^T / sqrt(d_k)              # [B, L, L]
Scores_masked = Scores + M               # broadcastable additive mask
A = softmax(Scores_masked, axis=-1)      # [B, L, L]
Y = A V                                   # [B, L, d_v]
A[b,i,j] >= 0 and sum_j A[b,i,j] = 1 for each row with >=1 permitted key.
Numerically stable softmax subtracts the row maximum before exponentiation.

06. MASK SEMANTICS
Bidirectional: a valid query can attend to all permitted valid keys.
Causal: key position j is visible to query i only if j <= i.
Padding: invalid keys receive zero attention probability.
Combined masks apply the intersection of visibility rules.
A query row with no visible key is invalid unless the implementation explicitly defines a safe empty-row policy.
An additive mask uses 0 for permitted positions and -infinity (or a numerically safe equivalent) for forbidden positions.

07. POSITIONAL CONTEXT
Self-attention without positional signals is permutation-equivariant over sequence positions (under corresponding mask permutations).
Absolute, relative or rotary positional mechanisms may introduce order-dependent information.
Positional information may be incorporated before projections or within attention score construction, according to architecture.

08. INFERENCE RULES
RULE SA-01: If Q, K and V derive from the same sequence representation, classify as self-attention.
RULE SA-02: If Q derives from one sequence and K/V from another, classify as cross-attention, not self-attention.
RULE SA-03: If j > i is prohibited for every query i, classify masking as causal.
RULE SA-04: If all valid sequence positions can interact, classify masking as bidirectional.
RULE SA-05: If a mask permits no key for a query, flag an undefined attention row unless an explicit policy exists.
RULE SA-06: If dimensions do not satisfy Q_last = K_last, reject the attention score operation.
RULE SA-07: If attention weights do not normalise across permitted keys within numerical tolerance, flag a validation failure.
RULE SA-08: An attention matrix alone does not establish a causal explanation of model behaviour.

09. RECURSIVE ENGINE
INITIALISE: read X, projections, mask, positional policy and boundaries.
EXPAND: compute Q, K, V and scaled compatibility scores.
FILTER: apply visibility and validity constraints.
NORMALISE: compute stable masked softmax.
AGGREGATE: produce Y = A V.
VALIDATE: check shape, finiteness, masking and probability sums.
UPDATE: pass Y to the containing block, optionally with residual and normalisation operations defined externally.
REPEAT: for subsequent layers or autoregressive decoding steps as specified by the containing architecture.
STOP: on completed layer execution, invalid state or explicit termination condition.

10. TRI-MAPPING
ONTOLOGY: SelfAttentionEntity -> AttentionWeights -> ContextualisedRepresentation.
MATHEMATICS: X -> (Q,K,V) -> softmax(QK^T/sqrt(d_k)+M)V.
EXECUTION: project -> score -> mask -> normalise -> aggregate -> validate.

11. EXECUTION CONSTRAINTS
C-01: B and L are non-negative integer dimensions; operational attention requires L >= 1.
C-02: d_k and d_v are strictly positive integers.
C-03: Q and K share the same feature dimension.
C-04: Mask is broadcastable to score tensor shape.
C-05: All unmasked score values must be finite before softmax.
C-06: At least one key is visible for each processed query row, absent an explicit empty-row policy.
C-07: Attention output shape is [B, L, d_v].
C-08: Training-time dropout changes stochastic execution; deterministic claims require evaluation mode or fixed randomness.
C-09: Attention weights can be inspected but must not be treated as sufficient evidence of semantic attribution.

12. AI SEARCH FLOW
FLOW_ID: semantic-library.ai.transformer.self-attention-entity.v1
ENTITY: Self-Attention Entity Ontology
PARENT: Transformer Entities
INTENT: identify, define, relate, compute and validate self-attention.
ALIASES: intra-sequence attention; self attention; token-to-token attention.
INPUTS: sequence embeddings, projection parameters, positional policy, visibility mask.
OUTPUTS: attention weights, contextualised representations, validation result.
PATHWAY_1: query -> entity definition -> typed relationships.
PATHWAY_2: query -> attention equation -> dimensional verification.
PATHWAY_3: query -> masking requirement -> causal/bidirectional distinction.
PATHWAY_4: query -> execution trace -> validation constraints.
CONFIDENCE: high for standard transformer mathematics; page-specific correspondence unverified.
CITATION_BACKLINK: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/self-attention-entity-ontology.html
UPDATE_MODEL: revise when source ontology or implementation specification changes.

13. EXECUTION GUARANTEE AND LIMITS
Given valid inputs, consistent masks, fixed parameters and a defined numerical implementation, the attention computation yields an output with the specified shape and masked-normalisation properties within numerical tolerance.
This is a conditional computational guarantee, not a guarantee of correctness, factuality, interpretability or model performance.

END OF FLOW
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ