Dil AI KILAVUZU

Logit Lens ve Ara Katman Kod Çözme

The logit lens is an interpretability technique that applies a language model's final output layer to the hidden states of earlier layers, showing which next token each layer is leaning toward.

Bu kılavuzu dinleyinAI tarafından anlatılan · ~8 min

Bu sayfada9 min read
  1. Genel Bakış
  2. Önemli çıkarımlar
  3. Derin Dalış
  4. Running a logit lens on a small open model
  5. Gerçek Dünya Uygulaması
  6. Logit Lens ve Ara Katman Kod Çözmenin Geleceği
  7. Uygulamaya koymak
  8. Kaynaklar ve ek okuma
  9. Keşfetmeye Devam Edin
  10. Sık sorulan sorular

Genel Bakış

Introduced in a 2020 blog post on GPT-2 and refined in 2023 by the tuned lens, it is one of the simplest ways to watch a prediction form layer by layer, though its readouts are approximations rather than proof of what the model knows.

Önemli çıkarımlar

  1. The logit lens applies a model's own final normalization and unembedding to earlier hidden states to see each layer's implied next-token prediction.
  2. It was introduced by the researcher nostalgebraist in an August 2020 analysis of GPT-2 1.5B on LessWrong.
  3. The logit lens works poorly on models such as GPT-Neo, BLOOM and OPT 125M, and is biased toward some tokens even where it works.
  4. The 2023 tuned lens trains one affine translator per layer to match the final output, giving lower perplexity and less bias than the logit lens.
  5. A token ranked highly by a lens at some layer is evidence about the computation, not proof of where the model stores a fact.

Derin Dalış

A transformer language model processes text as a stack of layers. Each token position carries a vector of numbers, called the hidden state or residual stream, that every layer reads and then adds an update to. Only after the last layer does the model convert this vector into a prediction: it applies a final normalization and multiplies by the unembedding matrix, a learned table that turns the vector into one score, or logit, per vocabulary token. A softmax turns those logits into probabilities for the next token. Intermediate layer decoding asks what would happen if that final readout were applied early, at layer 5 or layer 20, instead of at the end.

The logit lens is the simplest answer. Take the hidden state after some layer, apply the model's own final layer normalization and unembedding, and read off the top tokens. No training is needed, because it reuses the model's own weights. Doing this at every layer and every position produces a grid showing the most likely token at each depth, which researchers call a prediction trajectory. If the trajectory settles on the final answer early, the later layers are mostly refining or sharpening that answer; if it changes late, the decision is made near the end.

The technique was introduced in a LessWrong post by the pseudonymous author nostalgebraist on August 31, 2020. Running GPT-2's 1.5 billion parameter version on the abstract of the GPT-3 paper, the post reported that intermediate layers already produce plausible guesses, moving from nonsense or shallow guesses with the right part of speech in early layers to refined predictions later. It also reported a surprise: the input token itself was not preserved in early layers, as the hidden state moved almost at once toward something closer to the output. The author added caveats in the post, including that top tokens show only part of what the activations contain.

The logit lens did not generalize well. In 2023, Nora Belrose and colleagues at EleutherAI, FAR AI, the University of Toronto, Boston University and UC Berkeley reported that it fails to produce plausible predictions for model families such as GPT-Neo, BLOOM and OPT 125M. For BLOOM and OPT 125M, its top prediction was often just the input token in more than half the layers. Even where it worked, it was biased, systematically giving more probability to some vocabulary items than the final layer does. One cause is representational drift: a feature can be encoded differently at different depths, so the final layer's readout is the wrong decoder for earlier layers.

Their fix, the tuned lens, trains one small affine transformation, a matrix plus a bias called a translator, for each layer of a frozen model. Each translator maps that layer's hidden state into the coordinate system the final readout expects, and is trained so that its decoded distribution matches the model's real final output as closely as possible, measured by Kullback-Leibler (KL) divergence, a standard measure of how different two probability distributions are. Tested on models with up to 20 billion parameters, the paper reports that tuned lens predictions have substantially lower perplexity, meaning they predict the next token better, and are less biased than the logit lens. On GPT-Neo-2.7B, the logit lens produced uninterpretable output before layer 21, while the tuned lens gave sensible predictions throughout.

These lenses have been used for several research questions. Halawi, Denain and Steinhardt (2023) found that when a few-shot prompt contains wrong labels, middle-layer predictions are often more accurate than final outputs, and traced the late switch to attention heads that copy the false labels. The tuned lens paper reproduced this on models where the logit lens fails. Wendler and colleagues (2024) used the logit lens to argue that Llama-2 passes through a concept space closer to English when processing other languages. Patchscopes, from Google researchers in 2024, generalizes the idea by patching a hidden state into a separate prompt and letting the model describe it in words, and its authors argue that vocabulary-projection methods are special cases of their framework.

The main limitation is interpretive. A lens is a probe, a separate readout attached to the model, and what it shows depends on how it is built. A token that a lens ranks highly at layer 12 does not prove the model represents that fact at layer 12, and a token that does not appear may still be encoded in a form the readout cannot decode. The tuned lens is trained to imitate the final output, so it may reveal what later layers will do with the state rather than what the current layer computes. Belrose and colleagues partly addressed this with causal experiments, removing the directions the lens relies on and showing that this also changes the model's own output, but such checks are evidence, not a complete causal account. Both lenses were designed for pre-normalization transformers, the common modern layout, and work less cleanly on other designs.

In practice the logit lens costs almost nothing: a few lines of code that reuse the model's own weights, run on any open-weights model whose hidden states can be accessed. It cannot be applied to models available only through an API that hides internal activations. The tuned lens requires training one translator per layer on text similar to the model's pretraining data; the authors trained theirs on a slice of the Pile validation set, initialized each translator to the identity and used stochastic gradient descent with Nesterov momentum for 250 steps, a small cost compared with training the model itself.

04Çalışılan örnek

Running a logit lens on a small open model

  1. Load an open model such as GPT-2 small with a library that returns hidden states for every layer.

  2. Feed the prompt The Eiffel Tower is located in the city of and keep the hidden state at the last position for each layer.

  3. For each layer, apply the model's final layer normalization and multiply by the unembedding matrix to get logits.

  4. Apply softmax and record the top 5 tokens and the probability of the token Paris at each layer.

  5. Compute the KL divergence between each layer's distribution and the final layer's distribution.

  6. Plot the probability of Paris and the KL divergence against layer number.

Ne gösteriyor?

The learner gets a curve showing at which depth the model's implied prediction approaches its final answer. KL divergence should fall toward zero at the last layer by construction; if early layers show only noise or the input token, that is the known weakness a tuned lens is designed to fix.

Gerçek Dünya Uygulaması

The original analysis: in August 2020 the pseudonymous researcher nostalgebraist decoded every layer of the 48-layer GPT-2 1558M model and found that next-token guesses become sensible well before the final layer and converge gradually.

Multilingual research: a 2024 study of Llama-2 used the logit lens on non-English prompts, such as translating the French word fleur into Chinese, and found that middle layers often favor the English version of the correct word before the output shifts to the input language.

Few-shot prompting: Halawi and colleagues (2023) decoded intermediate layers and found that models given deliberately wrong examples often predict correctly at middle layers, then switch to copying the false pattern after a critical layer.

Attack detection: the tuned lens paper ran Pythia 12B on nine multiple-choice tasks with and without a prompt injection, and fed the layer-by-layer answer probabilities to standard outlier detectors to flag attacked inputs, often with near-perfect accuracy.

Tooling: EleutherAI and FAR AI's tuned-lens package, installed with pip install tuned-lens and released under the MIT license, trains and applies per-layer lenses to open models.

Logit Lens ve Ara Katman Kod Çözmenin Geleceği

Intermediate layer decoding has become a standard first tool in mechanistic interpretability, the study of how trained networks compute their outputs, but research has moved toward methods that ask the model to explain more than a single next token. Patchscopes (Ghandeharioun and colleagues, ICML 2024) inserts a hidden state into a separate prompt and lets the model describe it in natural language, and its authors report that this can inspect early layers where vocabulary projections fail, use a stronger model to read a smaller model's states, and help correct multi-step reasoning errors. Open questions remain. Lens readouts show a distribution over output tokens, so they say little about intermediate computations that never resemble a word, such as numerical or positional features. It is also unresolved how faithfully any learned probe reflects the model rather than the probe's own fitting, which is why causal tests that change the model's hidden states are increasingly paired with decoding. Findings such as an English-leaning concept space in Llama-2 (Wendler and colleagues, 2024) raise further questions about bias in multilingual models, and whether they hold across architectures and training mixes needs testing model by model. Applied uses are also being explored, including the tuned lens paper's 2023 finding that prediction trajectories can flag prompt-injection attacks. Whether such signals stay reliable against attackers who know about them, and whether they work on much larger models, has not been established.

Uygulamaya koymak

Neden önemli?

  • Hız ve ölçek. Dil iş akışları tutarlılıktan ödün vermeden daha hızlı ilerleyebilir.
  • Erişim ve erişim. Diller ve iletişim tarzları arasında erişimi genişletir.
  • Daha net kararlar. Otomasyon tekrarlamayı yönetirken ekipler karar vermeye daha fazla zaman ayırabilir.

Dikkat edin

  • Halüsinasyonlu gerçekler sessizce raporlara, destek akışlarına veya araştırma çıktılarına girebilir.
  • İstem hassasiyeti, benzer istekler arasında tutarsız sonuçlar yaratabilir.
  • Erişim kontrolleri zayıfsa hassas metin verileri açığa çıkabilir.

Sonraki adımlar

  1. Kullanıma sunmadan önce çıktı formatını, tonunu ve kalite standartlarını tanımlayın.
  2. Doğruluğun önemli olduğu durumlarda güvenilir kaynaklarla zemin müdahaleleri.
  3. Yüksek riskli çıktılar için insan incelemesi kontrol noktası bulundurun.
  4. Arıza modellerini takip edin ve istemleri veya iş akışlarını düzenli olarak yeniden eğitin.

Kaynaklar ve ek okuma

  1. LessWronginterpreting GPT: the logit lens
  2. arXivEliciting Latent Predictions from Transformers with the Tuned Lens
  3. GitHub (AlignmentResearch)tuned-lens
  4. arXivOverthinking the Truth: Understanding how Language Models Process False Demonstrations
  5. arXivDo Llamas Work in English? On the Latent Language of Multilingual Transformers
  6. arXiv (ICML 2024)Patchscopes: A Unifying Framework for Inspecting Hidden Representations of Language Models

Keşfetmeye Devam Edin

Ücretsiz bülten

Günlük AI brifingini alın

Hafta içi her sabah sade İngilizce yazılmış, doğrulanmış üç yapay zeka hikayesi. Sonsuza kadar ücretsiz, reklam yok.

Hafta içi her gün bir e-posta. Tek tıklamayla aboneliğinizi iptal edin. Adresinizi asla satmayız veya paylaşmayız.

Kendinizi test edin

Take the Logit Lens and Intermediate Layer Decoding quiz

Her yanıtla ilgili anında geri bildirim ve bir kursu geçtiğinizde doğrulanabilir bir kimliğe sahip paylaşılabilir bir sertifika.

Testi başlat

Ücretsiz AI eğitimini destekleyin. AI Understanding, bir 501(c)(3) kâr amacı gütmeyen kuruluştur; hiçbir zaman reklam yoktur, ödeme duvarı yoktur. Bağış yap

Sık sorulan sorular

What is Logit Lens and Intermediate Layer Decoding?

The logit lens is an interpretability technique that applies a language model's final output layer to the hidden states of earlier layers, showing which next token each layer is leaning toward. Introduced in a 2020 blog post on GPT-2 and refined in 2023 by the tuned lens, it is one of the simplest ways to watch a prediction form layer by layer, though its readouts are approximations rather than proof of what the model knows.

What readout does a plain logit lens reuse to obtain vocabulary scores from an intermediate state?

The projection maps a compatible hidden-width state into vocabulary logits, while its reliability on intermediate states still needs assessment.

Why can the same output projection be applied mathematically at multiple residual-stream depths?

Dimensional compatibility permits the readout; it does not make every layer's representation equivalent to the final one.

'Ayarlı mercek' düz logit merceğe göre hangi sorunu çözer?

Ayarlanan mercek, katman başına küçük bir afin haritayı eğitir, böylece ara durumlar daha güvenilir bir şekilde kodlanır ve düz merceğin erken katman önyargısı ve gürültüsü azalır.

If an intermediate lens readout favors a correct factual token, what has been directly observed?

The observation is a descriptive probe result. Causal interpretation needs additional evidence and interventions.

Logit lens en doğrudan ne işe yarar?

Temel değeri yorumlanabilirliktir: modelin tahmin edilen token dağılımının katman katman evrimini ortaya çıkarmak.