attention-analysis

attention-analysis is a skill for Claude Code from ndif-team/skills. It costs 131 tokens per session (3,219 once invoked), scanned A, original, MIT.

A model-inspection guide for examining attention patterns in transformer language models. It distinguishes where each attention head looks from what that head writes into the model.

In plain words
What is it for?
Use it to read attention matrices, measure individual heads, identify behaviours such as copying or focusing on recent tokens, and edit or inspect head outputs.
Why use it?
It helps you avoid mistaking a striking attention pattern for useful work, and checks that the values you inspect are really probabilities.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the nnsight plugin — 19 skills shipped together

Good fit Use it to read attention matrices, measure individual heads, identify behaviours such as copying or focusing on recent tokens, and edit or inspect head outputs.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ndif-team/skills/attention-analysis
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ndif-team/skills --skill attention-analysis
Clone the repo
git clone --depth 1 https://github.com/ndif-team/skills

Made for: Claude Code.

Or install nnsight, the plugin that ships this one along with the rest of its 19 skills.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for attention-analysis

README.md
[![agentmods](https://agentmods.dev/badge/skills/ndif-team/skills/attention-analysis/github.svg)](https://agentmods.dev/skills/ndif-team/skills/attention-analysis)
Your own site
<a href="https://agentmods.dev/skills/ndif-team/skills/attention-analysis"><img src="https://agentmods.dev/badge/skills/ndif-team/skills/attention-analysis/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for attention-analysis

Your own site · 80×15
<a href="https://agentmods.dev/skills/ndif-team/skills/attention-analysis"><img src="https://agentmods.dev/badge/skills/ndif-team/skills/attention-analysis.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 131 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,219 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00131 $0.03219
Opus 5.5 $0.00052 $0.01288
Sonnet 5.5 $0.00026 $0.00644
Haiku 4.5 $0.00013 $0.00322

Measured today against content hash 32dc9c3654b8, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

attention-analysis scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured today.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/nnsight/skills/attention-analysis/SKILL.md · 278 lines

How it starts

The opening of the file, as written. The whole thing — 278 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Attention Analysis

Two different objects get called "attention", and you need both:

  • The pattern — softmax(QK^T/√d), a [batch, heads, query, key] matrix saying where each head looks. Under eager the attention module hands it back as attn.output[1]; .source reaches the raw softmax inside.
  • The per-head output — what each head writes into the residual stream. A slice of the output projection's input.

Patterns tell you about routing; outputs tell you about content.

import torch
import nnsight
from nnsight import TransformersModel

# eager is required — sdpa/flash never materialize the probability matrix
model = TransformersModel("openai-community/gpt2", dispatch=True,
                          attn_implementation="eager")

prompt = "When Mary and John went to the store, John gave a drink to"
n_layers = len(model.transformer.h)
n_heads = model.config.n_head
head_dim = model.transformer.h[0].attn._module.head_dim   # not n_embd // n_heads
tokens = [model.tokenizer.decode([i]) for i in model.tokenizer(prompt).input_ids]

Getting patterns

Every layer in one pass (model.output.attentions also works, but only with output_attentions=True; the loop lets you pick layers):

with torch.no_grad():                     # a trace runs with autograd on
    with model.trace(prompt):
        patterns = nnsight.save([block.attn.output[1] for block in model.transformer.h])

print(len(patterns), patterns[0].shape)   # 12 x [batch, heads, query, key]

If the weights are None, the model was not loaded with attn_implementation="eager" — sdpa and flash_attention_2 never materialize the matrix, and model.output.attentions is the empty tuple rather than an error.

Anchor before you score. Two properties are cheap and both must hold, or you are holding something that is not a probability matrix:

first_layer = patterns[0]
seq = first_layer.shape[-1]
upper = torch.triu(torch.ones(seq, seq, dtype=torch.bool), diagonal=1)

assert torch.allclose(first_layer.sum(-1), torch.ones_like(first_layer.sum(-1)))
assert (first_layer[..., upper] == 0).all()      # causal mask: exactly zero, not small

Read the full file on GitHub · 278 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. today Changed · -55 lines · +7 tokens per session 32dc9c3654b8
  2. 1mo ago First seen · 333 lines · 124 tokens per session scan A 716da33bc88b

Subscribe to this mod's changes

attention-analysis is a skill published in the GitHub repository ndif-team/skills (14 stars, last pushed yesterday), licensed MIT. It adds 131 tokens to every session and 3,219 once invoked, about $0.0005 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-10.

Related

Other skills, from other repositories

torchdrug

Builds and troubleshoots TorchDrug 0.2.1 workflows for molecular graphs, property prediction, self-supervised pretraining, molecule generation, retrosynthesis, protein representation learning, and knowledge graph reasoning. Use when code imports torchdrug or needs its datasets, models, tasks, or Engine.

K-Dense-AI/scientific-agent-skills · 64 tokens

arboreto

Infers candidate gene regulatory networks from bulk or single-cell expression data using AertsLab Arboreto GRNBoost2 and GENIE3. Use for transcription factor-target association ranking, compatible Dask execution, sparse expression inputs, and network stability checks.

K-Dense-AI/scientific-agent-skills · 55 tokens

deepspot-m

Generates transcriptome-wide virtual spatial transcriptomics from H&E histology with DeepSpot-M. Used for predicted log1p-CPM expression from 224x224 tiles at about 20x, querying the released protein-coding gene panel by symbol, and whole-slide prediction after resolution-aware tiling with histolab.

K-Dense-AI/scientific-agent-skills · 70 tokens

pyhealth

Builds and validates PyHealth clinical machine-learning pipelines for EHR, signals, imaging, and medical codes. Use for PyHealth dataset loading, MIMIC-III/IV, eICU or OMOP prediction tasks, patient-level evaluation, mortality/readmission/length-of-stay modeling, medication recommendation, sleep staging, Trainer…

K-Dense-AI/scientific-agent-skills · 84 tokens

ml-training-recipes

Battle-tested PyTorch training recipes for all domains — LLMs, vision, diffusion, medical imaging, protein/drug discovery, spatial omics, genomics. Covers training loops, optimizer selection (AdamW, Muon), LR scheduling, mixed precision, debugging, and systematic experimentation. Use when training or fine-tuning…

Orchestra-Research/AI-Research-SKILLs · 88 tokens

nemo-mbridge-perf-expert-parallel-overlap

Validate and use MoE expert-parallel communication overlap in Megatron-Bridge, including overlapmoeexpertparallelcomm, delaywgradcompute, and flex dispatcher backends such as DeepEP and HybridEP.

NVIDIA/skills · 56 tokens