Thinking Replay: what each layer of a small language model guesses before it answers
One prompt, read layer by layer. A baseline on GPT-2, in English and Swahili, with its limits stated.
In plain terms
A language model writes one word at a time. To choose the next word, the model passes the text through a stack of steps, called layers. GPT-2, the model we studied, has 12 of them, and each layer refines the guess made by the one before it.
We stopped after every layer and asked a simple question: if the model had to answer now, which word would it pick? In the figure below, each sheet is one layer, with its current guess written beside it. The blue point is the place at the very end of the prompt where the next word is produced. The lines from that point to the words show which earlier words the layer was looking at, and a thicker line means more attention.
What we saw in English is that the layers from 4 to 11 all leaned toward the word Yes, and the last layer changed to I. The early guess and the final answer were different. This is one small model and one question, so it shows that the tool works and what it can show. It is not a general finding.
Summary
We built a tool that records, for a single prompt, what every layer of a language model would predict as the next word and which earlier words the last position attends to. We ran it on GPT-2 with one English and one Swahili prompt. In English, the layers from 4 to 11 all ranked the word Yes first, while the model's output at layer 12 was I. In Swahili, the model answered in English and its guesses were English words. Both results are specific to one small model and two prompts, and the method is approximate. They show that the tool works and what it can and cannot tell us.
1. Question
How a model uses the words that came earlier in its input is central to designing models that stay efficient as inputs grow. Before changing a design we want to see what an existing model does. The first question is a narrow one: at which layer does the word a model finally chooses first become visible, and which earlier words does the last position look at on the way there?
2. Method
We used the model gpt2 with the text-generation library versions listed in Section 6. For each prompt we ran one forward pass and took the hidden state at the last position after every layer, including the word embeddings, which we call layer 0. Each state was decoded into a probability over words with the model's own output head. This is the logit lens. It is a rough view, because the early layers were not trained to be read this way.
For attention, we took the weights from the last position to every earlier position at each layer, averaged them over the heads, and kept the three largest. We also recorded the model's final first word, the probability and rank of that word at every layer, and the first layer from which it is the top guess.
The prompts were Question: Do you think the world is a simulation?\nAnswer: and its Swahili form Swali: Je, unadhani ulimwengu ni uigaji wa kompyuta?\nJibu:. The model generated 60 new words, once greedily and three times by sampling with seeds 0 to 2. Only the first word is analysed in the figure below.
3. Results
Each sheet is one layer of the model, and the blue point is the last position of the prompt rising through them. Press Play, drag the figure to turn it, choose a layer, or switch the prompt language. Every value is read from the data file listed in Section 6.
:
Sheet shade: probability of the final word. Blue outline: it is the top guess. Drag to turn, click a sheet to choose a layer.
3.1 English
The model's first word was I. The word started at rank 17,179 at layer 0, reached rank 7 at layer 1, fell back to rank 97 at layer 5, and returned to rank 1 only at layer 12, where its probability was 0.221. From layer 4 to layer 11 the top-ranked word was Yes, with probability 0.35 at layer 4, 0.94 at layer 9 and 0.72 at layer 11. At layer 12 the output was I (0.221), Yes (0.115) and No (0.109). The layers before the last therefore favoured a different word from the one the model gave.
From layer 6 onward the largest share of the last position's averaged attention went to the first word, Question, between 0.50 and 0.73. This is where the attention goes. It does not show that the model reads that word for its meaning, and attention to the first position is a known pattern in many transformers that we did not test here.
3.2 Swahili
From layer 3 to layer 10 the decoded guesses were English words (Yeah, Yes, Oh). At layer 11 the top guess was Je, the first word of the Swahili question, with probability 0.54. The model's first word was I, at probability 0.063 against 0.059 for Je, and it became top-ranked only at layer 12. The greedy continuation was English (I'm not sure.), and the sampled continuations drifted into unrelated text or invented words. GPT-2 was trained mostly on English, so this prompt shows the limit of the model and does not describe how language models handle Swahili in general.
4. Limits
- One model, two prompts, one run each. We draw no general conclusion about language models.
- The logit lens is approximate. A word ranked low at an early layer does not mean the model has not represented it.
- Attention is averaged over heads and only the top three positions are kept. Averaging can hide heads that behave differently.
- A small base model continues text. It does not reason in steps, and the sampled continuations are not answers to the question.
- We have not used this tool on models with long context or on models with other memory designs, and it has not been peer reviewed.
5. What this is for
The tool gives us a repeatable way to look at one model before we change its design. The next steps are to run it over many prompts instead of one, to separate attention patterns that carry meaning from those that do not, and to compare models with different ways of storing earlier input. We will publish those results in the same form, with their limits.
6. Data
Every number and figure on this page comes from one file, thinking-replay-v0.json. It was produced with Python 3.13.16, torch 2.11.0+cu130 and transformers 5.20.2, with 60 new words per sample.