Transformer Architecture: A Bridge
Trace representations, attention, position, and output without assuming factual correctness.
artificial intelligence, transformers, attention, deep learningFrom tokens to representations
Tokens are mapped to vectors, with positional information so order can matter. In self-attention, each position forms a query, key and value from its representation. Query-key scores are scaled and normalised into weights, which combine value vectors. Multiple heads can learn different relationships. Feedforward layers, residual connections and normalisation are also important parts of transformer blocks.
A tiny attention calculation
For one position, suppose a head has already computed attention weights 0.75
and 0.25 for two scalar values 4 and 8. The weighted result is
0.75 × 4 + 0.25 × 8 = 5. This is a deliberately simplified illustration:
real values are vectors and the weights are computed from query-key scores
using learned projections.
- The input positions have values 4 and 8.
- The head weights them 0.75 and 0.25.
- The combined value is 5, passed onward within the model.
See the reasoning
Combine weighted values
Follow a simplified scalar attention calculation. This is a prepared demonstration, not live code execution.
Start with values
- Value 14Current focus
- Value 28
- OutputNot computed
The example uses scalar values for readability; real value representations are vectors.
Masks, models, and limits
A causal mask prevents a position in an autoregressive decoder from looking at later tokens during next-token prediction. Encoder-style attention can use different visibility rules; an encoder-decoder can also use cross-attention to input representations. Pretraining and later adaptation change the learned parameters, not the basic need to verify results.
Attention weights are not by themselves a faithful explanation of an entire prediction. Context length, compute cost, training data and distribution shift constrain these models. The separate Generative AI module explores training and deployment in greater depth.
Reflect on the concept
Four fixed questions to reinforce the reasoning. Answers are not saved or scored.
