See what the model sees

Trace a transformer prediction

Follow one token through embeddings, attention, transformer blocks, and output scores without hiding the prediction behind a chat interface.

Open Anatomy of a Transformer in the app.

Start with a short tokenized prompt such as [the, cat, sat]. At every position, a decoder-only transformer predicts the following token.

Each token ID becomes an embedding and receives position information. Masked self-attention lets a position combine earlier context without looking at future target tokens. A feed-forward network transforms each position. Residual paths carry information around both operations.

At the end, the model produces one score for every token in the vocabulary. Softmax turns those scores into probabilities.

Suppose three candidate scores become these probabilities:

" on"   0.60
" near" 0.25
" blue" 0.15

Training compares this distribution with the actual next token. Generation chooses one candidate using the configured sampling rule, appends it, and runs the prediction path again.

Write one sentence in your notebook for each stage: input IDs, embeddings, attention, blocks, output scores, next-token choice.

Change one prompt token and inspect the next-token distribution again. Replace cat with dog and watch whether " on" stays at 0.60 or drops. The difference shows context affecting computation. It does not prove that one attention head alone caused the final choice.

The model stores parameters, not completed answers. A generated paragraph is many repeated conditional predictions.

If every candidate probability looks flat near 0.001, you are probably looking at an untrained checkpoint or a broken vocabulary mapping. Flat distributions early in training are normal. Flat distributions late in training are a problem worth noting.

Step through the anatomy view one layer at a time. Pause after attention and read the top three candidate tokens. Write them down before you advance to the next block. That slow pass beats clicking through the whole stack once and remembering nothing.

What to observe: the model produces a distribution of possible next tokens, not one stored answer.

Lesson completed