Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Glossary › Attention

What is attention?

The operation that lets each token gather information from other tokens. Scores are dot products of queries with keys, softmax turns them into weights, and the output is a weighted mix of values.

Where it is taught

Attention. Attention lets each token ask a question of every token before it and take a weighted mix of the answers. It is built from dot products and softmax.

What the lesson leaves you with

  • Each token produces a query, a key and a value.
  • Scores are dot products of queries with keys. Softmax turns them into weights. The output is a weighted mix of values.
  • The causal mask stops tokens from attending to later positions.
Open the lesson

Questions

What is attention?
The operation that lets each token gather information from other tokens. Scores are dot products of queries with keys, softmax turns them into weights, and the output is a weighted mix of values.
Where is attention used in AI?
Attention lets each token ask a question of every token before it and take a weighted mix of the answers. It is built from dot products and softmax.
What is the key idea to remember about attention?
Each token produces a query, a key and a value.
Where can I learn attention step by step?
In the lesson “Attention” in Gradient’s course on the maths behind AI, with interactive diagrams and questions.

See it in 3D on the blog

  • How does ChatGPT work? The maths for Class 108 min
  • How does attention work in transformers?3 min

Related terms

  • Attention head
  • Autoregressive
  • Byte-pair encoding
  • Causal mask
  • Context length
  • Layer normalisation