Learn · student

Attention for students

Self-attention computes weighted combinations of value vectors using query–key compatibility.

Reviewed:

Short answer

Attention is how transformers route information between tokens. Self-attention lets every token selectively gather context from others in the sequence.

Why it matters

Attention explains both the power and the cost of long prompts—and why packing better evidence often beats pasting entire databases into context.

Diagram

Diagram of transformer attention flow from tokens through encoder/decoder blocks to output
Diagram of transformer attention flow from tokens through encoder/decoder blocks to output

Article

Mechanics

Queries, keys, and values are linear projections of token representations. Softmax over scaled dot products produces weights. Multi-head attention learns several focus patterns in parallel.

Cross-attention lets decoder tokens attend over encoder outputs in sequence-to-sequence models.

Examples

Coreference

In “The deposit was refunded after the landlord inspected the apartment,” attention helps bind “the deposit” to later references when predicting answers.

FAQ

Is attention unique to transformers?
Attention mechanisms existed earlier (e.g., in RNN seq2seq), but transformers make attention the primary sequence mixer.

Related rankings

  • Best AI for Research in 2026 — Research-oriented AI tools emphasize citations, papers, and source grounding more than casual chat. This ranking…
  • Best AI Developer Tools in 2026 — Developer tools cover IDEs, app builders, and engineer search — adjacent to but broader than “best AI for coding”…

Related topics

  • Transformers — Transformers are neural architectures that use attention mechanisms to model relationships among tokens, forming the…
  • Context Windows — A context window is the maximum amount of text (tokens) a language model can consider at once—including the system…
  • Embeddings — Embeddings are vector representations of text, images, or other objects that place similar items nearby in a geometric…
  • Retrieval-Augmented Generation — Retrieval-augmented generation (RAG) combines a language model with a search or retrieval step so answers can cite or…
  • Prompt Engineering — Prompt engineering is the practice of designing instructions, examples, and context so generative models produce more…

Sources