Skip to main content

Attention Matrix 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 — ATTENTION MATRIX ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/attention-matrix-ontology.html
Authors: Mark Anthony Higgins — Sky Recursive AI
Prepared: 2026-10-29 | Encoding: UTF-8
Status: Companion formalisation using established transformer mathematics; embedded page specification not accessible in retrieved HTML.

flow "AttentionMatrixOntology" v1.0

PURPOSE:
  Formalise attention score matrices, probability matrices, masks, and their role in contextual aggregation.

STATE_MODEL:
  S_t = (I_t, R_t, B_t, K_t)
  I_t: current query/key/value tensors and optional mask
  R_t: projection, score, masking, normalisation and aggregation relations
  B_t: shape, visibility, numeric and implementation constraints
  K_t: validated attention semantics, provenance and prior state
  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: argmax is an optional semantic-selection layer, not the numeric attention calculation.

ENTITIES:
  QueryTensor Q: [batch, heads, query_length, d_k]
  KeyTensor K: [batch, heads, key_length, d_k]
  ValueTensor V: [batch, heads, key_length, d_v]
  ScoreMatrix L: [batch, heads, query_length, key_length]
  Mask M: broadcastable to shape(L)
  AttentionMatrix A: [batch, heads, query_length, key_length]
  ContextTensor C: [batch, heads, query_length, d_v]
  AttentionHead: owns one Q/K/V projection set and corresponding matrix slice
  TransformerBlock: consumes contextual attention outputs

RELATIONSHIPS:
  Q compares_with K -> L
  M restricts_visibility_of L
  softmax normalises L -> A
  A weights V -> C
  AttentionHead produces A and C
  TransformerBlock incorporates C

FORMAL_OPERATIONS:
  L = (Q @ transpose_last_two(K)) / sqrt(d_k)
  L_masked = L + M
  A[b,h,i,j] = exp(L_masked[b,h,i,j] - m) /
               sum_r exp(L_masked[b,h,i,r] - m)
    where m = max_r L_masked[b,h,i,r] for stable computation
  C = A @ V
  For allowed, finite logits: A[b,h,i,j] >= 0
  For rows with >= 1 permitted key: sum_j A[b,h,i,j] = 1 (up to floating-point tolerance)
  For masked keys: A[b,h,i,j] = 0 (mathematical ideal)
  For self-attention: Q,K,V are derived from the same sequence representation
  For cross-attention: Q may derive from decoder states; K,V from encoder states

MASK_SEMANTICS:
  PaddingMask: suppress padded key positions
  CausalMask: suppress future keys (j > i for aligned autoregressive self-attention)
  CustomMask: permit only authorised query-key edges
  Disallowed logit: -infinity before softmax, subject to implementation safeguards
  Fully masked rows: undefined for ordinary softmax; must be rejected or handled by a documented safe policy

INFERENCE_RULES:
  R1: If shape(Q)[-1] != shape(K)[-1], scaled dot-product scores are invalid.
  R2: If shape(K)[-2] != shape(V)[-2], weighted aggregation is invalid.
  R3: If M is not broadcastable to L, masking is invalid.
  R4: If any row has no permitted keys, normalisation requires explicit handling.
  R5: If A is row-stochastic over permitted keys, it defines attention weights, not calibrated explanatory probabilities.
  R6: If A is multiplied by V, resulting C is a weighted combination of value vectors.
  R7: Different heads may learn different patterns; no semantic role is guaranteed for a given head.
  R8: Attention weights alone do not establish causal explanation of model behaviour.

MINI_RECURSION_ENGINE:
  initialise Q,K,V,M
  validate shapes and finite input values
  calculate scaled scores L
  apply visibility mask M
  detect fully masked rows
  normalise valid rows to A
  aggregate values to C
  validate invariants
  emit (A,C,metadata) or structured failure
  In autoregressive decoding, append new key/value states to cache and repeat for new queries.

TRI_MAPPING:
  Entity: AttentionMatrix
  Structure: directed, weighted query-to-key matrix per batch and head
  Operation: scaled scores -> masking -> softmax -> weighted value aggregation
  Meaning: context-dependent distribution of permitted key contributions to each query

MAPPING_TABLE:
  Query position -> attention row -> contextual output vector
  Key position -> attention column -> candidate information source
  Score -> unnormalised compatibility -> relative logit
  Mask -> visibility constraint -> prohibited/allowed links
  Softmax -> row normalisation -> nonnegative attention weights
  Value -> content vector -> information aggregated into output

EXECUTION_CONSTRAINTS:
  d_k > 0 and d_v > 0
  query_length >= 1 and key_length >= 1 for standard attention
  matched batch/head dimensions or documented broadcast policy
  deterministic masking semantics for a given input
  softmax performed over key axis, never query axis
  numerical stability via maximum subtraction or equivalent kernel
  floating-point checks use tolerances rather than exact equality
  implementation may use fused kernels without materialising A; ontology still defines logical A
  privacy/security restrictions on accessible keys must be enforced before aggregation

EXECUTION_GUARANTEE:
  Conditional: for valid dimensions, finite permitted logits, at least one permitted key per row,
  and a numerically sound softmax, output weights are nonnegative and approximately sum to one per row.
  No guarantee of semantic correctness, interpretability, generalisation or safety follows solely from this operation.

AI_SEARCH_FLOW:
  ID: attention-matrix-ontology
  INTENT: define, identify, validate and reason about transformer attention matrices
  ALIASES: attention weights; attention probability matrix; attention score matrix (distinguish pre-softmax)
  INPUTS: Q, K, V, mask, scaling dimension, head metadata
  PATHWAYS:
    definition -> entities -> matrix shape
    computation -> score -> mask -> softmax -> aggregate
    validation -> shapes -> visibility -> row sums -> output
    interpretation -> weighted relationships -> limitations
  OUTPUTS: attention matrix A, contextual representation C, validation report
  CONFIDENCE: conditional on input validity and documented implementation
  SEMANTIC_EQUIVALENCE:
    'attention logits' != 'attention weights'
    'attention matrix' usually means normalised weights A; disambiguate in context
    'attention output' C != 'attention matrix' A
  UPDATE_MODEL: versioned schema; preserve source and provenance
  CITATION_BACKLINK: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/attention-matrix-ontology.html

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