Vocabulary Projection

Interpret internal transformer states by projecting them through the unembedding matrix into vocabulary distributions.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill vocabulary-projection-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Vocabulary Projection
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/vocabulary-projection
Command: npx skills add https://github.com/zjunlp/Mechanist --skill vocabulary-projection-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, transformers, matplotlib, numpy, pandas, seaborn, datasets, psutil, and includes scripts (resource) and references (resource) components.

What problem does it solve? Understanding what information is encoded inside a large language model's internal states is difficult because hidden vectors are not human-readable. Vocabulary Projection decodes residual stream states, attention head outputs, and FFN neuron value weights into distributions over the model's vocabulary, letting researchers read semantic content directly from intermediate computations without training probes or collecting labeled datasets. ## Core Features & Use Cases - Residual Stream Projection: Trace layer-by-layer prediction evolution with tuned lens analysis to identify where specific concepts emerge in the network. - Attention Head Output Projection: Decode individual head outputs to reveal what information (e.g., copied names, next-token candidates) each head transmits, supporting functional head identification. - Neuron Value Weight Projection: Treat FFN layers as key-value memories and project value vectors to see which token clusters individual neurons promote. - Use Case: A mechanistic interpretability researcher analyzing Llama-3.1-8B can apply logit lens analysis across all layers, visualize confidence heatmaps per generation step, and pinpoint the layers where a factual prediction crystallizes. ## Quick Start Ask the agent to run a logit lens analysis on a prompt with your chosen model and visualize how the predicted tokens evolve across transformer layers.

Frequently Asked Questions about Vocabulary Projection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I apply logit lens analysis to a transformer model?

Logit lens analysis multiplies intermediate hidden states by the model's unembedding matrix and applies softmax to get vocabulary distributions at each layer. The included scripts extract hidden states via HuggingFace Transformers and decode top-k token predictions per layer.

What is the difference between logit lens and tuned lens?

Logit lens directly applies the final unembedding matrix to intermediate states, assuming basis alignment. Tuned lens trains affine translator layers per layer to better map intermediate representations into the output space, correcting for representational rotation across layers.

Can I use vocabulary projection on attention heads and FFN neurons?

Yes. Projecting attention head outputs reveals what information each head writes to the residual stream, and projecting FFN value weight vectors shows which token clusters a neuron promotes, treating feed-forward layers as key-value memories.

Which models does this analysis support?

The scripts demonstrate GPT-2 for tuned lens training and Llama-3.1-8B, Qwen-2.5-7B, and Llama-2-7B for layer-wise logit lens analysis. Any HuggingFace causal language model exposing hidden states and an unembedding matrix works.

What are the limitations of vocabulary projection methods?

The method assumes intermediate states share the output vocabulary's vector space, which holds best for residual streams. Results for sub-layer components like FFN and attention internals are approximations, since representation spaces may rotate across layers.

How much memory does key-value agreement analysis require?

Full key-value agreement analysis on transformer feed-forward layers requires approximately 150GB of RAM. The scripts include subset creation utilities to test with a limited number of keys on smaller machines.