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