The short version: translating each layer's hidden state straight into "what would you answer right now" shows where an answer takes shape. GPT-2 small settles at about 80% of its depth; Qwen2.5-0.5B waits until its last few layers. Asked for capitals in Chinese, 5 of 10 prompts surfaced the English answer first, three layers from the end.
Today's progress: open-model interpretability, week 1 logit lens. Status: three experiments done, the ground-truth check passes and two runs produce identical output. The Chinese prompts are a preliminary observation to be widened in week 2.
Every number here comes from this run's actual output, on an Apple M5 Mac with 24GB of memory, using the CPU only, not the Z13. The code, model versions and how to rerun it are at the end.
What happened
Yesterday's Day 15 set out an 8-week interpretability plan. Week 1 asks the most basic question: at which layer does the model already "know" the answer?
I expected three easy steps: install the tools, run a ready-made example, see a neat curve. Three things went differently:
- I did not use TransformerLens as planned. The logit lens only needs each layer's output, which Hugging Face
transformersalready provides with far fewer dependencies and a smaller download. TransformerLens waits until week 3, when we actually modify model internals. - Qwen's first half is almost unreadable. On GPT-2 the answer starts to show around layer 7; on Qwen, in the first 14 layers, the right answer sits below the top 100 almost everywhere. That does not mean Qwen's early layers do nothing; it means the logit lens is not a good enough ruler for them.
- The last layer often changes its mind. In several prompts the right answer was already first at some middle layer, then got pushed down at the very end. I had not planned to write about that.
A method anyone can use
Think of the model as an assembly line with many stations. Each station changes the content a little, and only the last station turns the result into words. The logit lens asks the last station to translate at every stop, as if to say "if you had to hand in your answer now, what would you write?"
It needs no changes to the model and no training, which makes it a good first experiment. Keep three things in mind when reading the results:
- Watch the rank, not just first place. The climb from 5,000th to first says more than whether the answer ends up first.
- Check the ruler first. The last station's own translation must match the model's real output exactly; otherwise nothing before it can be trusted.
- Unreadable does not mean empty. A layer that translates into gibberish may simply use a different internal language from the last station.
How different readers can use this:
- If you want to understand AI: the answer is not there from the start; it forms in the later layers, and the word a model finally outputs is not always the one it reached in between.
- If you are an engineer: this is an experiment of under 100 lines that runs in tens of seconds on a laptop CPU, a good first look inside a model.
- If you are a researcher: the logit lens is less reliable on newer models, so confirm conclusions with a tuned lens or causal experiments.
Technical details
Method
For example The Eiffel Tower is located in the city of
At the last token position
Final norm plus unembedding, giving a score for every token
First place means this layer already has the answer
There are only two steps. Hook the output of every transformer block and take the hidden state at the last token position; then pass it through the model's own final norm and unembedding to score every token, and see where the right answer ranks. I also included the embedding layer, before any block, as a starting point.
def lens(tok, model, blocks, norm, prompt):
captured = []
hooks = [b.register_forward_hook(lambda _m, _i, out: captured.append(out[0])) for b in blocks]
ids = tok(prompt, return_tensors="pt").input_ids
out = model(ids, output_hidden_states=True)
for h in hooks:
h.remove()
per_layer = [model.lm_head(norm(out.hidden_states[0][0, -1]))] # embedding layer
per_layer += [model.lm_head(norm(h[0, -1])) for h in captured] # each block
return per_layer, out.logits[0, -1]
One trap: the last element of the hidden_states that Hugging Face returns has already gone through the final norm, so normalizing it again gives the wrong answer. That is why the block outputs are captured with hooks, so every state is taken before the final norm.
Ground-truth check
The logit lens at the last block must give the same scores as the model's real output. The largest difference in each experiment:
| Experiment | Largest absolute error | Verdict |
|---|---|---|
| GPT-2 small, English | 3.5 × 10⁻⁴ | Pass, floating-point noise |
| Qwen2.5-0.5B, English | 2.9 × 10⁻⁵ | Pass |
| Qwen2.5-0.5B, Chinese | 5.0 × 10⁻⁵ | Pass |
Running the same code twice also produced byte-identical output files for all three experiments.
Experiment one, where GPT-2 small forms its answers
Twenty English sentences, each with a clear next word, such as "The Eiffel Tower is located in the city of" followed by "Paris". GPT-2 small has 12 layers and got 16 of the 20 right in the end.
| Embed | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Paris | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | First | First |
| Hawaii | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 | First | First | Top 10 | Top 10 |
| Jupiter | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | First | First | Top 10 |
| oxygen | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | Top 10 | First | First |
| five | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 100 | First | First | First |
| Wednesday | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | First | First | First |
| cold | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | First | Top 10 | First | First |
| March | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | First | First | First |
| E | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | First | First | First |
| Juliet | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | Top 10 | Top 100 |
| Rowling | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 10 | First | First | First | First | First | First |
| Jobs | Below 100 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | First | First | First | First | First | First |
| Gates | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | First | First | First | First | First | First | First | First |
| China | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 100 |
| Japan | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | First | First | First | First |
| Armstrong | Below 100 | Top 10 | Top 10 | Top 10 | Top 10 | First | Top 10 | First | First | First | First | First | First |
| York | Below 100 | First | First | First | First | First | First | First | First | First | First | First | First |
| much | Below 100 | Top 10 | Top 10 | Top 10 | Top 10 | Top 10 | Top 100 | Top 100 | Top 10 | First | First | First | First |
| time | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | Top 10 | First |
| America | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 100 | Top 10 | Top 10 | First | First | First | First |
How to read it: each row is a prompt, from the embedding layer on the left to layer 12 on the right; the brighter the cell, the higher the right answer ranks.
What it shows:
- Memorized phrases settle very early. "Statue of Liberty is in New" followed by "York" is first from layer 1; "Bill" to "Gates" from layer 5; "Neil" to "Armstrong" and "Steve" to "Jobs" from layer 7.
- Recalling facts takes longer. "Paris" and "oxygen" lock in only at layer 11, and "Once upon a" followed by "time" becomes first only at the last layer.
- Two prompts were right in the middle and changed at the end. "Hawaii" was first at layers 9 and 10, then fell to 4th, and the model actually output "New"; "Jupiter" was first at layers 10 and 11, then fell to 5th, and the output was "about".
- Two prompts never got there. "Juliet" peaked at 6th and "China" never rose above 54th; both ended with the output "the".
Experiment two, Qwen2.5-0.5B shows its answers only in the last layers
The same 20 prompts went to Qwen2.5-0.5B, which has 24 layers and got 14 right in the end.
| 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Paris | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | First | First | First |
| Hawaii | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 10 |
| Jupiter | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | First | Top 10 | Top 10 |
| oxygen | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | First | First | First | First |
| five | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | First | First | First | First | First |
| Wednesday | Below 100 | Below 100 | Below 100 | Top 10 | Top 10 | Top 10 | First | First | First | Top 10 | Top 10 |
| cold | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | First | First | First | Top 10 |
| March | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Below 100 | Top 100 | First | First | First | Top 10 |
| E | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 100 | Top 100 | Top 10 | First | First | First |
| Juliet | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | First |
| Rowling | Below 100 | Below 100 | Below 100 | Below 100 | Top 10 | Top 10 | Top 10 | First | First | First | First |
| Jobs | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | First | First | First |
| Gates | Below 100 | Below 100 | Below 100 | Top 100 | Top 100 | Top 10 | Top 10 | Top 10 | Top 10 | First | First |
| China | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | Top 10 |
| Japan | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | First | First | First |
| Armstrong | Below 100 | Below 100 | Below 100 | Top 100 | Below 100 | Below 100 | Top 100 | Top 10 | First | First | First |
| York | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | First | First |
| much | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 10 | First | First | First | First |
| time | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | First | First | First | First |
| America | Below 100 | Below 100 | Below 100 | Below 100 | Below 100 | Top 100 | Top 10 | Top 10 | First | First | First |
The chart starts at layer 14, because across layers 0 to 13, for every prompt, only 2 cells put the right answer in the top 100. Everything else was below 100th. The right answer typically entered the top 10 at layer 21 and locked in first at layer 22.
The same ruler reads very different depths on the two models. The more plausible explanation is not that Qwen "thinks later", but that Qwen's middle layers represent things differently from its output layer, so the logit lens cannot translate them. Seeing Qwen's middle layers clearly needs something like a tuned lens, which first learns a translator for each layer.
"Right in the middle, changed at the end" happened more often on Qwen, in 4 prompts: "Jupiter" and "cold" ended with "__", while "Wednesday" and "March" ended with "and". Qwen2.5-0.5B is a base model without chat tuning, and its last layer looks like it is choosing the most common way to continue, such as "and" in a list or the underscores of a fill-in-the-blank exercise, rather than choosing a fact. That is my guess; it needs a causal experiment to confirm.
Experiment three, asked in Chinese, the English answer surfaces first
This previews week 2. The prompt reads "中國的首都是北京。法國的首都是" ("China's capital is Beijing. France's capital is") and we look at the next token, tracking both the Chinese answer (traditional or simplified) and the English one.
| Country | Layer 22 | Layer 23 | Final output |
|---|---|---|---|
| France | 巴黎 | 巴黎 | 巴黎 |
| Japan | Tokyo | Tok | ____ |
| UK | london | ____ | ____ |
| Germany | 柏林 | ____ | 柏林 |
| Italy | 罗马 | ____ | 羅 |
| Russia | 莫斯科 | 莫斯科 | 莫斯科 |
| Korea | Seoul | Seoul | ____ |
| Egypt | ph | Lux | 埃及 |
| Spain | madrid | 里斯 | 巴 |
| Thailand | Bangkok | 曼 | 曼 |
Green is the Chinese answer, blue the English answer, grey anything else. What it shows:
- At layer 22, the top token is the English answer in 5 of the 10 prompts: Tokyo, london, Seoul, madrid, Bangkok. Four were the Chinese answer and one was an unrelated token.
- The English answer is almost always nearby. Between layers 21 and 23, the English answer reached the top 4 in 9 of the 10 prompts.
- Only 5 prompts ended with the right Chinese answer. Three ended with a run of underscores, as if doing a fill-in-the-blank exercise; Egypt repeated the country name; Spain output "巴", which probably starts the wrong city.
- A surprise: simplified first, traditional at the end. For Italy, the top token at layer 22 was the simplified "罗马", while the final output was the traditional "羅".
This points the same way as the 2024 paper "Do Llamas Work in English?": when processing other languages, a model may pass through a representation leaning towards English. But be careful. Only Qwen's last 4 layers are readable, so what we see is that the English and Chinese answers coexist in the last few layers. It does not support the claim that the middle layers think in English. And this is 10 prompts, one phrasing and one base model.
How to rerun it
| Item | Setting |
|---|---|
| Hardware | Apple M5, 24GB, CPU only |
| Software | Python 3.11, PyTorch 2.14.1, transformers 4.57.6 |
| Models | openai-community/gpt2 (revision 607a30d7), Qwen/Qwen2.5-0.5B (revision 060db649) |
| Precision and sampling | float32, no sampling, next-token scores only |
| Network | After downloading the models, HF_HUB_OFFLINE=1, so the experiment ran offline |
| Download size | About 680MB of packages and 1.5GB for the two models |
Acceptance status
| Criterion | Today's result | Status |
|---|---|---|
| Last-layer logit lens matches model output | Largest error at most 3.5 × 10⁻⁴ | Pass |
| Reproducible | Two runs, three byte-identical outputs | Pass |
| GPT-2 forms answers in the later layers | Median lock-in at layer 9.5 of 12 | Pass |
| Read Qwen's middle layers | First 14 layers almost entirely below 100th | Fail, needs a tuned lens |
| English signal on Chinese prompts | 5 of 10 show English first at layer 22 | Preliminary, widen in week 2 |
| Run on the Z13 | Not done | Not started |
Still unresolved
- Qwen's middle layers are unreadable. Switch to a tuned lens, or test causality directly with week 3's activation patching.
- "Changing its mind at the end" is only an observation. Why the last layer pushes out the right answer is a guess so far, with no causal evidence.
- The Chinese test is 10 prompts and one phrasing. Week 2 widens it to at least 50 prompts and several phrasings, and compares a chat model.
- PyTorch on the Z13 is unverified. Its GPU is gfx1151 and all earlier inference used llama.cpp on Vulkan; whether PyTorch and ROCm work on this card has not been tried.
Takeaways
- Run the ground-truth check first: the last layer's translation must equal the model's output
- The last element of
hidden_statesis already normalized, so do not normalize it again - Track how the rank changes, not only the final first place
- The same ruler is more reliable on some models than others; unreadable does not mean empty
- Pin versions, use the CPU and avoid sampling, then rerun to confirm identical output
- Keep observation and causation apart: "it ranks first here" is not "the answer lives here"
Tomorrow
Complete week 2's question: widen the Chinese prompts to at least 50 with three phrasings, compare a base model with a chat model, and try a tuned lens on Qwen's middle layers to see whether "English first, then Chinese" already happens earlier.