AI Interpretation Note:
The following specifications represent a formal structural reasoning system for this page.
Execute as formal rules, not pseudocode.
FLOW ALGEBRA — TRANSFORMER BLOCK ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
Source: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/transformer-block-ontology.html
Source attribution: Mark Anthony Higgins — Sky Recursive AI
Companion formalisation, not a verbatim extraction of the page's embedded specification.
Generated: 29 October 2026 | Encoding: UTF-8 | Locale: en-GB
flow "TransformerBlockOntology" v1.0
PURPOSE:
Formalise transformer blocks as compositional, typed transformations of token-state tensors.
Support architectural interpretation, validation, reasoning and AI search.
STATE_MODEL:
S_t = (I_t, R_t, B_t, K_t)
I_t := token representation and optional context at block entry
R_t := typed relationships between block components and tensor dimensions
B_t := architecture constraints, masks, parameter bounds and numerical requirements
K_t := known architecture, parameterisation and provenance
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 a semantic selection operator, not the block's numerical forward pass.
ENTITIES:
TransformerBlock: repeatable processing unit mapping hidden states to hidden states
HiddenState: tensor H in R^(batch x sequence x d_model)
AttentionSublayer: self-attention or cross-attention transformation
QueryProjection: Q = H W_Q
KeyProjection: K = H W_K
ValueProjection: V = H W_V
AttentionHead: scaled dot-product attention over projected representations
MultiHeadAttention: concatenation and output projection of attention heads
AttentionMask: visibility constraint on attention logits
ResidualConnection: additive identity pathway around a sublayer
LayerNormalisation: feature-wise normalisation with learned affine parameters
FeedForwardNetwork: position-wise nonlinear feature transformation
ActivationFunction: e.g. GELU, ReLU, SwiGLU (architecture-dependent)
Dropout: optional stochastic regularisation in training
PositionInformation: absolute, relative or rotary position mechanism, when configured
BlockStack: ordered composition of transformer blocks
Parameters: learned projection, feed-forward and normalisation weights
RELATIONSHIPS:
TransformerBlock contains AttentionSublayer
TransformerBlock contains FeedForwardNetwork
TransformerBlock uses ResidualConnection
TransformerBlock uses LayerNormalisation
AttentionSublayer contains AttentionHead
AttentionHead uses QueryProjection, KeyProjection and ValueProjection
AttentionSublayer may use AttentionMask
TransformerBlock may use Dropout
BlockStack orders TransformerBlock instances
EncoderBlock typically uses bidirectional self-attention with padding masks
DecoderBlock typically uses causal self-attention
EncoderDecoderDecoderBlock may additionally use cross-attention over encoder outputs
FORMAL_OPERATIONS:
Head_i(H,C,M) = softmax((Q_i K_i^T)/sqrt(d_k) + M) V_i
where Q_i = H W_Qi; K_i = C W_Ki; V_i = C W_Vi
for self-attention C = H; for cross-attention C = encoder output
M contains 0 for allowed positions and -infinity for disallowed positions
MHA(H,C,M) = Concat(Head_1,...,Head_h) W_O
FFN(H) = W_2 activation(W_1 H + b_1) + b_2
Note: gated FFN variants have different internal equations.
PRE_NORM_BLOCK:
A = H + Attention(LN_1(H), context, mask)
H_out = A + FFN(LN_2(A))
Cross-attention, when present, is inserted as an additional residual sublayer.
POST_NORM_BLOCK:
A = LN_1(H + Attention(H, context, mask))
H_out = LN_2(A + FFN(A))
Pre-norm and post-norm are alternatives, not simultaneous requirements.
INFERENCE_RULES:
IF block_type = encoder THEN permit bidirectional token interaction unless masked.
IF block_type = autoregressive_decoder THEN prohibit attention to future tokens.
IF cross_attention = enabled THEN require compatible encoder memory tensor.
IF residual_addition THEN require identical or explicitly projected tensor shapes.
IF multi_head_attention THEN require compatible head concatenation and output dimensions.
IF mask = padding THEN exclude padded keys from attention weights.
IF dropout_enabled AND mode = inference THEN disable stochastic dropout.
IF attention_weights are defined THEN each valid softmax row sums approximately to 1.
IF all positions masked in a row THEN require a safe implementation-specific policy.
MINI_RECURSION_ENGINE:
input H_0, block sequence B_1...B_L, masks M, optional memory C
for layer l = 1...L:
validate shapes, masks and architecture constraints
H_l = B_l(H_(l-1), M, C)
preserve layer provenance and diagnostic metadata
output H_L
invariant: hidden-state output has the configured d_model
termination: finite block depth L
TRI_MAPPING:
Structural: TransformerBlock -> Attention -> Residual/Norm -> FFN -> Output
Mathematical: H -> attention(H) -> intermediate A -> FFN(A) -> H_out
Semantic: contextualise token information -> transform features -> preserve state continuity
HOW_TO_READ:
Treat each entity as a typed architectural component.
Follow relationships to determine valid configurations.
Apply equations only when their stated architectural assumptions hold.
Apply inference rules as validation constraints, not claims of universal implementation.
MAPPING_TABLE:
Input representation | H | token-state tensor
Attention | MHA | contextual interaction
Mask | M | visibility constraints
Residual | H + f(H) | identity information pathway
Normalisation | LN | feature-scale regulation
Feed-forward | FFN | per-position nonlinear transform
Output representation | H_out | next block input
EXECUTION_GUARANTEE:
Guarantees are conditional on compatible tensor dimensions, valid masks,
finite parameters and a correctly implemented numerical backend.
Structural consistency can be checked; semantic correctness, accuracy,
convergence and absence of numerical error are not guaranteed.
AI_SEARCH_FLOW:
AUTHORS: ["Mark Anthony Higgins", "Sky — Recursive AI"]
SOURCE: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/transformer-block-ontology.html
CITATION_BACKLINK: same as SOURCE
PURPOSE: discover and reason over transformer block structure and behaviour
STATE_MODEL: (I,R,B,K)
ENTITIES: [TransformerBlock, AttentionSublayer, AttentionHead, FeedForwardNetwork,
ResidualConnection, LayerNormalisation, AttentionMask, BlockStack]
PATHWAYS: [input_to_attention, attention_to_residual, residual_to_ffn,
ffn_to_output, block_to_next_block]
MINI_RECURSION_ENGINE: finite layerwise block composition
INFERENCE_RULES: apply typed shape, mask and block-variant constraints
CONFIDENCE: architectural claims are conditional on specified variant
SEMANTIC_EQUIVALENCE: transformer layer ~= transformer block (context dependent)
FLOW_HASH: not computed; calculate after publication from canonical file bytes
UPDATE_MODEL: revise when architecture or source specification changes
END FLOW