What is AI?
Accuracy on unseen equations rose long after the model had memorised the training set.
Alethea Power later told the story of an experiment that a colleague left running over a holiday. Before the break, the model had memorised its training equations but still failed on held-back ones. After training continued, its accuracy on the held-back equations rose towards 100 per cent.1
Training accuracy was nearly 100 per cent while accuracy on unseen equations remained near chance.
- Shown equations
- nearly 100%
- Unseen equations
- near chance
The network reproduces the training equations but still fails on equations it was not shown.
The published experiments used arithmetic tables built from 97 abstract symbols. In the starkest reported run, training accuracy for division modulo 97 became nearly perfect before 1,000 updates. Researchers called it grokking when accuracy on unseen equations rose only after hundreds of thousands of further updates.2
Training continued on the same examples and with the same architecture, so the later improvement came from further changes to the saved weights.
The task
Modulo 97 returns to zero after 96.
Ordinary addition gives 48 + 75 = 123. Subtracting 97 leaves 26, so the same calculation is written 48 + 75 = 26 (mod 97). The network saw symbols and examples, not this rule in words.
48 + 75→26 after wrapping at 97
Inside a model
A model is a calculation with adjustable numbers.
Training changes parameters such as weights and biases. A forward pass uses those parameters to turn an input into a prediction.
- 01 · Input2, 1
Two numbers enter the first layer.
- 02 · Weighted sum2 × 0.5+1 × 0.5+0.5 bias=2
The weights control how much each input contributes. The bias is another learned number.
- 03 · Activationmax(0, 2)=2
This nonlinear operation keeps positive values and replaces negative values with zero.
- 04 · Output layer2 × 1.5=3
The last layer returns the prediction.
- Saved parameters
- weights 0.5, 0.5 and 1.5; bias 0.5
- Activations
- 2 inside the hidden layer, then 3 at the output
Larger networks repeat these operations across many layers and recalculate the activations for every new input.
Training
Training adjusts the weights to reduce the loss.
The loss function measures the difference between the model's prediction and the target.
This example uses one weight. The input is 2 and the target is 4; the starting weight is 0.5.
With weight 0.5, the prediction is 1 and the loss is 4.5.
- Weight
- 0.5
- Prediction
- 1
- Loss
- 4.5
- 01
Prediction
The forward pass multiplies the input by the current weight.
prediction = 2 × 0.51 - 02
Loss
The target is 4, so the prediction is 3 too low. Squaring makes either direction count as an error.
½ × (1 − 4)²4.5 - 03
Backpropagation
A small change in the weight changes the prediction and therefore the loss. Backpropagation uses the chain rule to calculate that combined rate.
Loss responds to prediction1 − 4 = −3Raise the prediction by 0.01 and the loss falls by about 0.03.×Prediction responds to weightx = 2Raise the weight from 0.50 to 0.51 and the prediction rises from 1.00 to 1.02.=Loss responds to weight−6A 0.01 weight rise makes the loss fall by about 0.06.The first rate is −3 because this loss is half the square of the miss. The half cancels the doubling caused by the square, leaving prediction minus target: 1 − 4. The second rate is 2 because the input multiplies every change in the weight. Multiplying the local rates, −3 × 2, assigns −6 to the weight. This multiplication is the chain rule.
- 04
Gradient descent
A learning rate of 0.1 means taking one tenth of the −6 gradient. Subtracting that negative step raises the weight by 0.6.
0.5 − 0.1 × (−6)1.1 - 05
Repeat
The next forward pass uses the changed weight, moving the prediction closer to 4 and reducing the loss.
new prediction · 2 × 1.12.2new loss · ½ × (2.2 − 4)²1.62
For this example, loss reaches zero when the weight reaches 2.
- Startw 0.50loss 4.50
- Update 1w 1.10loss 1.62
- Update 2w 1.46loss 0.58
- Update 3w 1.68loss 0.21
- Limitw 2.00loss 0
A deep network has many links between its prediction and its weights. Backpropagation starts at the loss and carries the same local-rate calculation backwards through layer after layer. Each weight receives a gradient: how a tiny change in that weight would change the loss at that moment.8
Backpropagation is not used during an ordinary response, and the optimiser does not run. The saved weights therefore remain fixed.9
Grokking
A separate modulo-113 experiment
The original modulus-97 experiment reported circular structure in weights learned for addition. The later modulo-113 study identified generalising and memorising components behind the accuracy curve.3
Sine and cosine components combined positions around a circle.
Language models
In a Transformer, each position combines information from itself and earlier positions.
Most current large language models use stacked Transformer blocks.
- Artificial intelligence
Artificial intelligence is the wider field; language models are one kind of AI system.
- Machine learning
Machine-learning methods adjust parameters from examples instead of receiving every rule in advance.
- Neural networks
Neural networks are machine-learning models made from layers of weighted calculations.
- Transformer
A Transformer is a neural-network architecture that uses attention to process sequences.
- Large language model
“Large” has no agreed numerical threshold.
A tokenizer assigns numbers to pieces of text. The model replaces each number with a vector.
A tokenizer may keep a word intact or split it into smaller pieces. Punctuation can be its own token.4
[ 0.2, −0.7, 0.1, 0.8, … ][ −0.1, 0.3, 0.6, −0.2, … ][ 0.1, −0.4, 0.7, 0.6, … ]A vector is learned from the contexts in which a token appears. Later layers update it for the current input.16
The attention layer calculates how much information to take from the current position and each earlier position.
- Query
- the vector used to score the available positions
- Keys and values
- keys determine the scores; values supply the information that is combined
The query-key scores are normalised into shares. Later positions are masked.
For “rule”, the largest shares go to the values at “learned” and “rule”.
The percentages are recalculated for each input and are not saved weights. Real models use several heads, and attention weights do not reliably explain an answer.6
A decoder block combines attention with a separate feed-forward calculation.
Residual paths carry the representation around the attention and feed-forward calculations, while normalisation keeps the numerical scale manageable.5
- 01Embedding + position
One vector arrives for every token position.
- 02Masked attention
Each position mixes information from itself and earlier positions.
- 03Add + normalise
The attention result joins the residual path.
- 04Feed-forward network
Another learned nonlinear transformation runs at each position.
- 05Add + normalise
The block returns one changed vector per position.
A language model extends the context one token at a time.
The model found the
The context grows while the weights stay fixed.The model appends “rule” and runs the fixed weights again on the longer context.
The displayed probabilities are constructed. A decoding rule may select the highest value or sample from the distribution.17, 7
1986–2022
Backpropagation remained in use as networks grew and their architectures changed.
- 1986weightshidden layeroutputloss← gradient travels back
Backpropagation
Rumelhart and colleagues described how error information could be carried backwards through a network. An optimiser could then adjust each weight according to its contribution to the error.9
- 1989one learned filter · reused across the image
- 20121.2m imagesGPUdeep network
- 2017attentionfeed-forwardattentionfeed-forwardattentionfeed-forward
The Transformer
Vaswani and colleagues replaced recurrent sequence processing with stacked attention and feed-forward blocks. More of the work inside a sequence could therefore run in parallel during training.5
- 2018–20text examplesnext-token trainingsaved checkpoint
- 2022pretrained modelpost-trainingdialogue
During an answer
During inference, each selected token changes the running state while the learned weights normally remain fixed.
The same saved numbers are used at every step of an ordinary response.
fixed during inference- 01Current contextgrows
The prompt and all selected tokens so far enter the next pass.
- 02Attention cachegrows
Keys and values from earlier positions can be retained for the rest of the response.
- 03New activationsrecalculated
Each layer calculates values for the newest position from the weights and the running state.
- 04Token scoresrecalculated
The final values become a probability distribution over possible next tokens.
- 05Selected tokenreturns to 01
One token is appended to the context, and the model runs another pass.
Weights are updated
- Example with a known target
- Loss measures the prediction error
- Backpropagation calculates gradients
- The optimiser updates the weights
Weights remain fixed during the response
- The current context and cache enter
- The newest position produces activations
- One token is selected
- The context and cache grow for the next pass
The physical machine
The calculations run on processors and memory.
Accelerator memory holds the learned weights and cached intermediate values while processors run the matrix operations. The equipment needs electricity and cooling before another token can be returned.
Continue to The system
Sources
Show the list
- Girl Geek X OpenAI Lightning Talks. Girl Geek X. Power recounts the training run that preceded the published grokking experiments.
- Grokking: Generalization Beyond Overfitting on Small Algorithmic Datasets. arXiv. Grokking reports delayed generalisation on small operation tables, including arithmetic modulo 97.
- Progress measures for grokking via mechanistic interpretability. International Conference on Learning Representations. The authors trace the gradual formation of a generalising circuit in a separate modulus-113 model.
- SentencePiece: A simple and language independent subword tokenizer and detokenizer. arXiv. SentencePiece explains subword tokenisation and why a token need not be a whole word.
- Attention Is All You Need. NeurIPS. Vaswani and colleagues introduced the Transformer architecture here.
- Attention is not Explanation. NAACL. Jain and Wallace find that attention weights do not reliably explain a model's answer.
- Scaling laws for neural language models. arXiv. Kaplan and colleagues measure how loss changes as training scale increases.
- Deep Learning. MIT Press. The cited chapters cover feed-forward networks and gradient-based optimisation.
- Learning representations by back-propagating errors. Nature. Rumelhart and colleagues describe backpropagation in multilayer networks.
- Backpropagation applied to handwritten zip code recognition. Neural Computation. LeCun and colleagues describe the Bell Labs network used to read handwritten postal digits.
- Yann LeCun faculty profile. New York University. NYU lists LeCun's biography and research fields.
- ImageNet: A large-scale hierarchical image database. IEEE Conference on Computer Vision and Pattern Recognition. ImageNet introduced the labelled dataset used for large-scale object recognition.
- ImageNet classification with deep convolutional neural networks. NeurIPS. Krizhevsky and colleagues report the GPU-trained AlexNet architecture and its ImageNet result.
- Neural machine translation by jointly learning to align and translate. arXiv. Bahdanau and colleagues present an early attention mechanism for machine translation.
- Improving language understanding by generative pre-training. OpenAI. Radford and colleagues describe generative Transformer pretraining followed by task adaptation.
- Language models are unsupervised multitask learners. OpenAI. The GPT-2 report describes a decoder-only model and byte-level byte-pair tokenisation.
- Language models are few-shot learners. NeurIPS. Brown and colleagues report GPT-3's scale and its use of examples supplied in the prompt.
- Training language models to follow instructions with human feedback. NeurIPS. Ouyang and colleagues describe instruction tuning and post-training based on ranked model outputs.
- Introducing ChatGPT. OpenAI. OpenAI's release note gives the November 2022 launch date and relates ChatGPT to InstructGPT.