Zubnet AI学习Wiki › Attention Visualization
基础

Attention Visualization

Attention Maps, Attention Heatmap
通过把注意力权重显示成热图,来可视化一个 Transformer 模型“注意”什么。对每个 query token,注意力图展示它给每个其他 token 分配多少权重。高权重(亮点)表示强注意力 — 模型认为那些 token 对当前计算高度相关。

为什么重要

注意力可视化是往 Transformer 内部瞥一眼并理解它的推理最直观的方式。当一个模型把“le chat noir”翻译成“the black cat”,注意力图显示“black”强烈关注“noir”,“cat”关注“chat”。这帮助调试模型行为、理解失败、建立对注意力如何工作的直觉。

Deep Dive

The attention weight matrix is (seq_len × seq_len) for each head and layer. To visualize: pick a layer and head, display the matrix as a heatmap where row i shows which tokens token i attends to. Bright cells mean high attention. For multi-head attention, you can visualize individual heads (each specializes in different patterns) or average across heads (overall attention distribution).

What Attention Maps Show (and Don't)

Attention maps show which tokens a head considers when computing its output, but they don't directly show what the model "understands" or why it made a decision. High attention doesn't mean "important" — some heads attend to punctuation or positional patterns without semantic meaning. Attention maps are descriptive (what the model looked at) not explanatory (why it made its decision). They're a useful debugging tool, not a complete explanation.

工具

BertViz provides interactive attention visualizations for Transformer models. Ecco and Captum offer attention-based interpretability for PyTorch models. For LLMs accessed via API, some providers return attention weights or log-probabilities that enable partial visualization. In image generation, cross-attention maps show which image regions correspond to which prompt words — useful for understanding why the model placed objects where it did.

相关概念

← 所有术语
ESC