Reading preferences
Concept

Transformer Architecture: A Bridge

Trace representations, attention, position, and output without assuming factual correctness.

artificial intelligence, transformers, attention, deep learning

From 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.

  1. The input positions have values 4 and 8.
  2. The head weights them 0.75 and 0.25.
  3. 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

One head at one position
  1. Value 14Current focus
  2. Value 28
  3. 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.

1. Why add positional information to token representations?
2. What does an attention head combine?
3. What does a causal mask prevent in next-token training?
4. Does transformer architecture guarantee factual output?

References and further reading