Copy Mechanism › Attention Visualization for Copy

Michael BrenndoerferUpdated May 19, 20253 min read
Language AI HandbookAll chapters
Part 12 of 67Sequence-to-Sequence
Chapter 89Copy Mechanism › Attention Visualization for Copy
Reading section 9 of 14 · Attention Visualization for Copy · 3 minSection 9 of 14 · 3 min

Book contents

Section 9 of 14 · 3 min read

Copy Mechanism › Attention Visualization for CopyOne section · Sections in this chapter9 / 14 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Visualizing attention patterns reveals when and what the model copies. High attention on specific source positions often indicates copying, especially when pgenp_{\text{gen}} is low.

The visual signature of copying is distinctive: when the model copies a token, attention concentrates sharply on the corresponding source position, often with more than 80% of the probability mass on a single position. When the model generates a token, attention is typically more diffuse, spread across several source positions that provide context without any single position being the "source" of the output token. This difference in attention sharpness is not just visually useful; it can be used diagnostically to understand what the model is doing at each step, and it has been used in research to study how well the model's copy decisions align with human judgments about which tokens should be copied.

Out[26]:
Visualization
Heatmap showing attention weights between generated summary tokens and source document tokens.
Attention heatmap during summarization with copy mechanism. Each row shows attention weights when generating a summary token. High attention (darker cells) on source tokens like 'Chen' and 'Stanford' indicates copying, while diffuse attention during generation of common words like 'announced' shows the model drawing context from multiple positions.