attention-head-output

Analyze layer-wise token predictions in transformer models using the Logit Lens technique.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

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

What problem does it solve? Understanding how large language models like Llama-3.1-8B and Qwen-2.5-7B arrive at their predictions requires inspecting internal hidden states at every transformer layer, which is difficult to do without specialized tooling. ## Core Features & Use Cases - Layer-wise Prediction Analysis: Apply the Logit Lens technique to project hidden states from each transformer layer into vocabulary space and inspect per-layer token predictions and confidence scores. - Component Decomposition: Compare attention mechanism outputs against MLP contributions at each layer to understand which components drive predictions. - Visualization Generation: Produce heatmaps, confidence progression plots, component comparison charts, and summary dashboards from analysis results. - Use Case: A mechanistic interpretability researcher wants to know at which layer Llama-3.1-8B commits to predicting "mat" after "The cat sat on the". Run the analysis script to get per-layer top-k predictions, then generate heatmaps showing how confidence evolves across all 32 layers. ## Quick Start Run the basic analysis script on a prompt like "The cat sat on the" with Llama-3.1-8B and then generate layer-wise prediction heatmaps from the saved JSON results.

Frequently Asked Questions about attention-head-output

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

FAQPage Schema
How do I analyze layer-wise predictions in Llama or Qwen models?

Use the Logit Lens technique to project each transformer layer's hidden states into vocabulary space. The basic analysis script runs a prompt through the model, records top-k token predictions and confidence scores per layer, and saves results to JSON.

What is the Logit Lens technique for interpreting language models?

Logit Lens applies the model's final unembedding matrix to intermediate layer hidden states, revealing what token each layer would predict. This shows how predictions form and refine as information flows through the transformer layers.

Which models does Logit Lens analysis support?

The scripts support Llama-3.1-8B, Qwen-2.5-7B, and Llama-2-7B through a model factory pattern with architecture-specific helper classes. Models load from Hugging Face or local paths, on CUDA or CPU devices.

How do I visualize attention and MLP contributions per layer?

The visualization generator script reads analysis JSON output and produces heatmaps of layer-wise predictions, confidence progression plots, and side-by-side attention versus MLP contribution charts using matplotlib and seaborn.

What are the limitations of Logit Lens analysis?

Logit Lens assumes intermediate representations are directly interpretable in vocabulary space, which may not hold for early layers using different representation bases. It also requires loading full models, so GPU memory limits which models you can probe.