Session 03 · AI Coding Agents for Engineering Research

Nobody writes the weights.

This demo is a complete transformer: embeddings, one attention head, unembedding, 1,152 parameters in all. It predicts the next word in a small made-up language, and it is simple enough to train entirely in this browser: real forward pass, real backpropagation, real gradient descent.

the machine→ the task→ ask it→ train it, live→ ask it again
its whole world is 16 words: animals sounds adjectives “says” function words
01 · The shape of the machine

A word goes in as a vector. Matrices do the rest.

The point: the whole model is a short chain of matrix multiplications. A word becomes a vector of 16 numbers; that vector is multiplied through a handful of matrices (with a softmax or two along the way); the final vector is read out as a probability for every word in the vocabulary. Stay at this altitude for now; the names come on the next screen.
the word
cat
→
its vector
(16 numbers)
×
a matrix
×
another
×
…a few more
→
output vector
→
softmax → p(next word)
02 · The matrices, named

Seven matrices hold the model's 1,152 numbers.

The point: here are the abstract matrices from the last screen with their real names and jobs. Two read the input, four form the attention head you met in session 2, one scores the vocabulary. Training exists to fill in their entries.
03 · The task

One task: predict the next token.

The point: the text itself supplies the supervision, with no labels and no teacher. At every position the model guesses the next word, and cross-entropy L = −log p(correct) scores the guess. Every parameter, embeddings included, exists only to push that number down.
The vocabulary — all 16 words
animals
catdogcowduck
their sounds
meowwoofmooquack
adjectives
smallbighungrysleepy
verb
says
function
thea.
grammar the/a (adj)* ANIMAL says SOUND .each animal owns one sound
The training corpus — 48 sentences sampled from the grammar
04 · Ask it something

Type a sentence. It predicts the next word.

The point: the machine already runs: vector in, matrices, probabilities out. Its 1,152 numbers are still random, so this screen shows what an untrained language model produces. We will return to this exact screen after training.
05 · Training, live

Loss falls toward the entropy floor.

The point: one rule does everything: θ ← θ − η·∂L/∂θ, applied to all 1,152 parameters at once, step after step. Watch it push the loss to the entropy floor, pull the random embedding cloud into meaningful clusters, and teach “says” to look back at the animal. None of this is programmed anywhere.
optimizer
learning rate η 0.05
seed 11
Cross-entropy loss per batch (8 sentences) · dashed = irreducible entropy of the corpus (— nats)
Attention probe on “” — where each token looks
Token embeddings — rows of WE, live PCA · trails = recent motion
p(correct sound after “says”) over training · watch for the sudden jump
06 · Ask it again

The same machinery with new numbers.

The point: the code is unchanged since screen 04; gradient descent rewrote only the 1,152 matrix entries. Ask it the same questions and compare.
Extra 1 (key 8) · One update, under the microscope

Backpropagation assigns the blame.

The point: “training” repeats one procedure: run forward, measure the loss, let the chain rule (backpropagation) assign each weight its share of the blame, then nudge every weight against its gradient. Here is that story for one single number you choose.
The whole model — every parameter, live · click any cell to put that weight under the microscope
Blame flows backwards — gradient magnitude ‖∂L/∂·‖ at each stage, one example, live
Your watched weight
WU[ , ]
The two cleanest links in the chain

Multiply this story by 1,152 weights per step (124 million for GPT-2, ~10¹¹ for a frontier model) and by millions of steps. Every weight in every LLM is written this way.

Extra 2 (key 9) · The test

Did it learn the rule or memorise the corpus?

The point: four sentences were deliberately deleted from the corpus before training. If the model completes them correctly anyway, it must have learned the rule: find the animal, whatever surrounds it, and emit its sound.
prompt:
—
The model's distribution for the next token — at the moment of the first generated word
Extra 3 (key 0) · Scale

From 1,152 parameters to 10¹¹.

Everything you just watched scales without changing its nature. GPT-2 small is this exact loop with d=768, 12 heads × 12 layers, LayerNorm and MLPs in the stack, AdamW instead of Adam, trained on ~8 billion tokens instead of 48 sentences. Frontier models add orders of magnitude and keep the same ideas: the loss is still −log p(next token), the update is still θ ← θ − η·∂L/∂θ.

The embeddings and attention lenses we studied in session 2 are just rows and columns of θ that this loop wrote. What scale adds is what those simple parts compose into: induction heads and in-context learning, which is where we go next.

Sources: Rumelhart, Hinton & Williams (1986), backpropagation · Bengio et al. (2003), neural LM · Kingma & Ba (2015), Adam · Vaswani et al. (2017), attention · Radford et al. (2019), GPT-2 · Elhage et al. (2021), transformer circuits. Model, loss and every gradient computed live in this tab; backward pass verified against finite differences.
step 0 · paused ← → screens  ·  space trains from any screen  ·  8 9 0 extras 1 / 6