Attention Mechanism

The Power of Attention

Discover how transformers focus on what matters when processing language.

Attention Visualizer

The
30.0%
cat
15.0%
sat
25.0%
on
10.0%
the
12.0%
mat
8.0%

What is Attention?

Attention is a mechanism that allows models to focus on different parts of the input when producing each part of the output. It computes a weighted sum of all input positions, where the weights determine how much each position contributes.

Self-Attention Formula

Attention(Q, K, V) = softmax(
QKT√dk
)V
🎯

Why It Matters

  • • Captures long-range dependencies in text
  • • Parallel computation (unlike RNNs)
  • • Interpretable - we can visualize what the model focuses on
  • • Foundation of modern NLP (BERT, GPT, T5)