Reproduce “Attention is Not Only a Weight: Analyzing Transformers with Vector Norms” on OpenResearch

Run Claude Code, Codex or any coding agent as a research agent: literature, hypotheses and experiments on your laptop, cluster or cloud GPUs.

Universal app for Apple silicon and Intel. Requires macOS 11 or later.

About this paper

Goro Kobayashi, Tatsuki Kuribayashi, Sho Yokoi, Kentaro Inui

The authors analyze Transformer attention by measuring the norm of each attention-weighted, transformed input vector, rather than relying on attention weights alone. In BERT, special tokens can receive large weights yet have small measured contributions. For German-to-English word alignment, norm-based extraction lowers AWI AER to 25.0 ± 1.5 from 29.8 ± 3.7, in this setup; it does not improve translation quality.

Key insights

  • The magnitude (norm) of the linearly transformed input vector, ||f(x)||, is a critical and often overlooked factor in determining a token's actual contribution to the attention output, alongside the attention weight.
  • Attention weights and transformed vector norms can have opposing effects, leading to a "cancellation effect" where high weights result in minimal actual contribution, as observed with BERT's special tokens.
  • Transformers, such as BERT, can utilize the norm of transformed vectors to modulate information flow, for instance, by discounting the contribution of highly frequent, less informative words.

Summary by alphaXiv.

Tip: change arxiv.org to autoarxiv.org in any arXiv abstract link to open the paper here.