Skip to main content

Attention Layer Ontology

Neural Network Entities
Authors: MArk Anthony Higgins - Sky Recursive Ai
© Mark Anthony Higgins 11 October 2025
Revised Date: 28 October 2026
Audio Overview
FLOW ALGEBRA — ATTENTION LAYER ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Neural Network Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/neural-network-entities/attention-layer-ontology.html
Status: Original companion formalisation; source-page specification not independently verified.
Author attribution: Kireth Research | Flow Algebra companion: Sky — Recursive AI
Date: 2026-10-28

1. PURPOSE
Represent attention layers as typed, parameterised neural transformations that compute context-dependent weighted combinations of value representations. Distinguish self-attention, cross-attention, causal masking and multi-head attention.

2. ENTITY MODEL
AttentionLayer := (id, kind, heads, d_model, d_k, d_v, parameters, mask_policy, precision, version)
kind in {self, cross, causal_self, multi_head, grouped_query, other}
parameters := {W_Q, W_K, W_V, W_O, optional biases}
Input entities: query sequence X_q, context sequence X_kv, attention mask M.
Output entities: attention weights A, contextualised representation Y, optional diagnostics.
Relations: hasHead, projectsQuery, projectsKey, projectsValue, attendsTo, masksPosition, producesRepresentation, belongsToModel.

3. FORMAL STATE
S_t = (I_t, R_t, B_t, K_t)
I_t := current query/context tensors and optional positional representations
R_t := tensor shape, mask, projection, normalisation and policy rules
B_t := compute budget, memory budget, precision, permitted context, latency constraints
K_t := learned attention parameters, architecture metadata and validated provenance

4. CORE ATTENTION ALGEBRA
Q = X_q W_Q ; K = X_kv W_K ; V = X_kv W_V
L = Q K^T / sqrt(d_k) + M
A = softmax(L, axis=keys)
H = A V
Y = concat(H_1, ..., H_h) W_O   [multi-head case]
For a single head, Y may equal H or include an output projection.
M_ij = 0 for permitted attention; M_ij = -infinity for prohibited positions (ideal mathematical form).
For practical finite precision, implement masking with a numerically stable method that yields zero probability for disallowed keys.
Causal self-attention permits key position j only if j <= i (subject to padding and additional constraints).
Cross-attention uses queries and key/value representations from distinct sequences or sources.

5. FLOW OPERATORS
expand(I_t, R_t) -> candidate valid tensor projections and attention configurations
validate(X_q, X_kv, M, K_t) -> {valid, errors}
project(X_q, X_kv, K_t) -> (Q,K,V)
score(Q,K,M) -> L
normalise(L) -> A
aggregate(A,V) -> H
combineHeads(H_1..H_h,W_O) -> Y
update(K_t, gradients, optimiser) -> K_(t+1) [training only]

6. EXECUTION FLOW
INPUT -> SHAPE CHECK -> MASK VALIDATION -> Q/K/V PROJECTIONS ->
SCALED DOT-PRODUCT SCORES -> MASK -> STABLE SOFTMAX -> VALUE AGGREGATION ->
HEAD CONCATENATION/PROJECTION -> OUTPUT VALIDATION -> RESULT
If a query has no permitted key, return a defined error or explicit empty-attention handling; do not apply undefined softmax to all-masked logits.

7. INFERENCE RULES
R1: If tensor dimensions are incompatible, reject execution.
R2: If kind=causal_self, future positions must receive zero attention probability.
R3: If a key is masked, its attention contribution must be zero.
R4: For a valid non-empty attention row, sum_j A_ij = 1 within numerical tolerance.
R5: If context changes, attention weights may change even when model parameters are fixed.
R6: Attention weights are computational coefficients, not by themselves reliable causal explanations.
R7: Training updates parameters only when gradients are finite and update policies permit.
R8: Context provenance and access permissions must be checked before cross-source attention.

8. TRI-MAPPING
Entity -> Algebra -> Operational meaning
AttentionLayer -> A=softmax(QK^T/sqrt(d_k)+M) -> context-sensitive weighting
AttentionHead -> H_i=A_i V_i -> one projected attention channel
AttentionMask -> M -> restrict permitted token interactions
MultiHeadAttention -> concat(H_i)W_O -> integrate head outputs
ParameterSet -> K_t -> learned projections and metadata

9. MAPPING TABLE
Input tokens | X_q/X_kv | source representations
Query projection | W_Q | query feature space
Key projection | W_K | addressable feature space
Value projection | W_V | transmitted content space
Attention scores | L | scaled compatibility plus mask
Attention weights | A | row-normalised permitted coefficients
Context output | Y | downstream representation

10. RECURSIVE COMPOSITION
Layer_(n+1)(X) = AttentionLayer_n(Representation_n(X))
Residual connections, normalisation and feed-forward blocks are separate architectural components unless explicitly included in a composite layer definition.
Iteration may reuse a layer with shared parameters or compose distinct parameter sets; do not assume equivalence.

11. SAFETY AND VALIDATION INVARIANTS
- No attention across explicitly prohibited positions or data boundaries.
- Tensor dimensions and head partitioning are valid.
- All permitted-row probabilities are finite and normalised within tolerance.
- Outputs respect numerical and memory constraints or fail explicitly.
- No claim that attention alone guarantees factuality, fairness or interpretability.
- No inference about confidential context without authorisation.

12. CONDITIONAL EXECUTION GUARANTEE
Given compatible finite inputs, valid projections, at least one permitted key per query, adequate resources and a numerically stable implementation, attention produces a defined tensor output with the specified shape and masking behaviour. This is a conditional computational property, not a guarantee of semantic correctness, security or model reliability.

13. AI SEARCH FLOW
flow "AttentionLayerOntology" v1.0
  INPUT: {query_tensor, context_tensor, mask, layer_spec}
  REQUIRE: shapes_valid AND access_authorised AND mask_valid
  STATE: S=(I,R,B,K)
  PATHWAY:
    validate -> project -> score -> mask -> softmax -> aggregate -> combine -> verify
  OUTPUT: {contextualised_tensor, optional_attention_weights, diagnostics}
  ON_FAILURE: {error_code, failed_invariant, remediation_hint}
  SEMANTIC_EQUIVALENCE:
    "attention mechanism" -> AttentionLayer [context dependent]
    "self attention" -> AttentionLayer(kind=self)
    "cross attention" -> AttentionLayer(kind=cross)
    "causal attention" -> AttentionLayer(kind=causal_self)
  CONFIDENCE: structural_rules=high; semantic_interpretation=conditional
  UPDATE_MODEL: parameter_versioned; provenance_preserved
  CITATION_BACKLINK: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/neural-network-entities/attention-layer-ontology.html

14. HOW TO READ
The entity schema identifies what the layer is; the equations describe what it computes; the flow describes execution order; the rules specify admissible operations; and the invariants state properties that can be tested. The original ontology page should be consulted for any source-specific terminology not captured in this companion formalisation.
Kireth Research
38 Thorndale Croft, Wetwang, Driffield
East Riding of Yorkshire YO25 9XZ