The Sky Is Blue: Transformer Model
Or why large language models and agents promise you the moon.
Language models such as GPT consist of a few computation steps that repeat many times. The model on this page has only 344 weights, two decoder blocks, and twelve tokens, so every number fits on the screen. It was trained with backpropagation and runs in your browser without transferring any data.
The model on this page does not know what color the sky is. From its training sentences, it has only learned which words often follow "Der Himmel ist" ("The sky is"), and it computes a probability for each word from that. "blau" (blue) is therefore the most likely next word, not a verified statement. Had the model been trained on sentences in which the sky is mostly called "grün" (green), it would promise you a green sky by the same computation. An AI agent built on a language model plans and acts on the basis of such word predictions.
Interactive computation view of a GPT model
Press "Play" and the computation runs by itself. Use the step list to jump to any point. "Token focus" and "Head" select which row and which attention head are highlighted. The model was trained on German sentences, so its vocabulary is German. "Der Himmel ist blau" means "The sky is blue."
Model Assumptions and Limits
The model is a didactic, GPT-2-style pre-LayerNorm model with learned absolute position vectors, causal multi-head self-attention, a GELU MLP, a final LayerNorm, and tied token and output weights. The default weights come from a training run with backpropagation. The comparison mode uses random weights in the same architecture.
The trained model knows only a tiny, artificial corpus of German sentences. It is not a general-purpose GPT. The computation runs entirely in your browser, with no connection to a service and no data transfer.
The batch size B = 1 is omitted from the matrices, and T denotes the current context length. The computation uses full floating-point precision, while the display shows rounded values. LayerNorm has γ = 1, β = 0, and ε = 10⁻⁵. The projections have no bias, and dropout is switched off during inference.
Training data and training log
- 344 trainable weights, 2 decoder blocks, 2 heads, model width 4, 12 tokens
- PyTorch, AdamW, 1,800 optimization steps, seed 42
- Weighted full-batch cross-entropy over all valid target positions
- Learning rate 0.025, halved twice, gradient clipping at 2
- Training loss from 2.7053 to 0.3446, no test loss
- 10 distinct sentences, 44 weighted sentence examples, every sentence ends with EOS
The sentence frequencies were chosen for teaching purposes:
- Der Himmel ist blau. × 20
- Der Himmel ist heute grau. × 4
- Der Himmel ist sehr hell. × 4
- Der Himmel ist blau und klar. × 3
- Der Himmel ist grau. × 3
- Der Himmel ist hell. × 2
- Der Himmel ist klar. × 2
- Der Himmel ist heute blau. × 2
- Der Himmel ist sehr klar. × 2
- Der Himmel ist heute hell. × 2
All trainable matrices E, P, W_Q, W_K, W_V, W_O, W_up, and W_down were optimized. The LayerNorm parameters stayed fixed. Inference runs in JavaScript, and no answer token is hard-coded.
Training, KV cache, and current GPT variants
During training, the token that actually follows serves as the target at every position. The cross-entropy L = −(1/N) Σ log p(y) measures the error, backpropagation computes the gradients, and an optimizer adjusts the weights. During inference the weights stay unchanged.
With a KV cache, a model reuses the keys and values of earlier positions in each layer. This page deliberately recomputes the entire context in every pass so that all matrices stay visible. Current decoders often use RoPE, RMSNorm, GQA or MQA, and SwiGLU instead of the components shown here.
Sources
Further Reading
If you have a question about this, just give us a call: +49 40 60940415.