Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

attention (in a Transformer)

A mechanism letting each token look at every other token in context and weight how much each one matters to it.

Given a query vector, a set of key vectors, and a set of value vectors, attention computes \text{softmax}\left(\frac{QK^\top}{\sqrt{d_k}}\right)V: a similarity score between the query and each key, turned into weights by softmax, used to form a weighted sum of the values. Self-attention uses the same sequence for queries, keys, and values, so every token can attend to every other token in its context.

Examples

  • In "the animal didn't cross the street because it was tired," attention lets "it" weight "animal" heavily when forming its contextual meaning.

Read the full section →
Graph settings

Calculator