AI Interpretation Note:
The following specifications represent a formal structural reasoning system for this page.
Execute as formal rules, not pseudocode.
FLOW ALGEBRA — ENCODER ONTOLOGY
Semantic Library | AI Core > Entity Graph > AI Entities > Transformer Entities
SOURCE: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/encoder-ontology.html
AUTHORS: Mark Anthony Higgins — Sky Recursive AI
SOURCE PAGE DATE: 11 October 2025 | Revised 29 July 2026
DOCUMENT TYPE: Companion formalisation; the page's embedded AI Search specification was not accessible in the retrieved HTML.
flow "EncoderOntology" v1.0
PURPOSE:
Define transformer encoder entities, their structural relationships, validated operations,
state transitions, and inference pathways for machine-readable semantic retrieval.
STATE_MODEL:
S = (I, R, B, K)
I := input token sequence, embeddings, masks and current hidden states
R := encoder transformations and typed structural relations
B := dimensional, masking, numerical and architecture constraints
K := architecture metadata, trained parameters and semantic context
E_t = expand(I_t, R)
V_t = {x in E_t | satisfies(x, B)}
x* = argmax_{x in V_t} P(x | I_t, R, B, K)
I_(t+1) = update(I_t, x*)
ENTITIES:
Encoder: stack of encoder layers producing contextual representations
TokenSequence: ordered token identifiers
TokenEmbedding: token-to-vector mapping
PositionInformation: positional embeddings or positional attention bias
HiddenState: contextual token representation tensor
EncoderLayer: attention and feed-forward sublayers
MultiHeadSelfAttention: multiple parallel self-attention heads
QueryProjection: linear map W_Q
KeyProjection: linear map W_K
ValueProjection: linear map W_V
AttentionMask: restriction on permitted attention pairs
FeedForwardNetwork: position-wise nonlinear transformation
ResidualConnection: skip addition around a sublayer
LayerNormalisation: stabilising normalisation operation
EncoderOutput: final contextual sequence representation
PoolingHead: optional sequence-level representation aggregation
RELATIONSHIPS:
Encoder HAS_LAYER EncoderLayer
EncoderLayer CONTAINS MultiHeadSelfAttention
EncoderLayer CONTAINS FeedForwardNetwork
EncoderLayer USES ResidualConnection
EncoderLayer USES LayerNormalisation
MultiHeadSelfAttention HAS_PROJECTION QueryProjection
MultiHeadSelfAttention HAS_PROJECTION KeyProjection
MultiHeadSelfAttention HAS_PROJECTION ValueProjection
TokenSequence MAPS_TO TokenEmbedding
TokenEmbedding COMBINES_WITH PositionInformation
Encoder PRODUCES EncoderOutput
EncoderOutput MAY_FEED PoolingHead
FORMAL_OPERATIONS:
Let X in R^(batch x length x d_model).
Q_h = X W_Q,h ; K_h = X W_K,h ; V_h = X W_V,h
A_h = softmax((Q_h K_h^T)/sqrt(d_k) + M) V_h
M_ij = 0 for permitted pairs and -infinity for forbidden pairs.
MHA(X) = concat(A_1,...,A_H) W_O
FFN(X) = W_2 activation(W_1 X + b_1) + b_2
PreNorm layer: U = X + MHA(LN(X)); Y = U + FFN(LN(U))
PostNorm layer: U = LN(X + MHA(X)); Y = LN(U + FFN(U))
Encoder(X) = layer_N(...layer_2(layer_1(X)))
NOTE: These are alternative layer arrangements, not simultaneous requirements.
INVARIANTS:
d_model > 0; num_layers >= 1; num_heads >= 1
For standard equal-sized heads: d_model mod num_heads = 0
Q_h and K_h share the same final dimension d_k
Attention weights normalise over permitted key positions
Residual operands must have matching shapes
Padding positions must be excluded where the architecture requires masking
Encoder self-attention is normally bidirectional, unlike causal decoder attention
A pooling head is optional; it is not intrinsic to every encoder
PATHWAYS:
P1: TokenSequence -> TokenEmbedding -> PositionInformation -> EncoderLayer* -> EncoderOutput
P2: HiddenState -> Q/K/V projections -> AttentionWeights -> HeadOutputs -> MHAOutput
P3: HiddenState -> Normalisation -> FeedForwardNetwork -> ResidualUpdate
P4: EncoderOutput -> optional PoolingHead -> downstream classification/retrieval
INFERENCE_RULES:
IF architecture uses encoder-only bidirectional self-attention
THEN each unmasked token may attend to other unmasked tokens.
IF padding mask blocks token j
THEN its key position contributes zero attention probability after softmax.
IF residual dimensions mismatch
THEN layer is invalid unless a defined projection reconciles dimensions.
IF output retains the sequence axis
THEN classify as token-level contextual representations.
IF output is pooled across tokens
THEN classify as sequence-level representation.
MINI_RECURSION_ENGINE:
initialise I_0 from embedded sequence and masks
FOR layer t = 1..N:
E_t := candidate contextual updates from attention and FFN relations
V_t := dimensionally valid, mask-compliant updates
select valid update consistent with trained encoder parameters
I_t := update(I_(t-1), selected layer output)
RETURN I_N as EncoderOutput
TERMINATION: finite configured number of layers N
TRI_MAPPING:
Natural: Encoder reads a token sequence and constructs contextual representations.
Structural: tokens -> embeddings -> stacked attention/FFN layers -> contextual outputs.
Formal: X_(l+1) = EncoderLayer_l(X_l), l = 0,...,N-1.
HOW_TO_READ:
HAS_LAYER and CONTAINS define architecture composition.
MAPS_TO and PRODUCES define typed transformations.
MAY_FEED denotes an optional downstream relationship.
Invariants are validation requirements; pathways are traversal routes.
EXECUTION_GUARANTEE:
Guaranteed: typed structural checks and deterministic evaluation of specified
encoder operations given fixed parameters, masks and numerical conventions.
Not guaranteed: semantic correctness, model accuracy, or identical floating-point
results across hardware and implementations.
AI_SEARCH_FLOW:
query_intents:
- What is a transformer encoder?
- How does encoder self-attention work?
- How do encoder layers create contextual embeddings?
- What distinguishes an encoder from a causal decoder?
entry_entity: Encoder
expansion_relations: [HAS_LAYER, CONTAINS, USES, HAS_PROJECTION, MAPS_TO, PRODUCES, MAY_FEED]
filters: [architecture_type, layer_count, hidden_dimension, head_count, attention_mask]
outputs: [entity_definition, architecture_path, mathematical_operation, validation_result]
confidence: conditional_on_source_and_architecture_match
semantic_equivalence:
transformer_encoder: Encoder
encoder_stack: Encoder
bidirectional_transformer_encoder: Encoder (when bidirectional attention is configured)
update_model: versioned; revise on changes to source or formalisation
citation_backlink: https://kirethresearch.org/booksai-core/entity-graph/ai-entities/transformer-entities/encoder-ontology.html
END FLOW