{"course":{"slug":"ai-actually-explained","title":"AI, Actually Explained","url":"https://addaly.com/learn/ai-actually-explained","level":"beginner","track":"start"},"lesson":{"slug":"attention-what-it-does","title":"Attention, without a single equation","url":"https://addaly.com/learn/ai-actually-explained/attention-what-it-does","position":23,"of":92,"minutes":9,"answer":"Self-attention combines information across allowed positions. In a causal decoder it cannot use a future token at an earlier position. Transformer training can process known positions in parallel; autoregressive output steps remain sequential.","keyIdea":"Self-attention combines information across allowed positions. In a causal decoder it cannot use a future token at an earlier position. Transformer training can process known positions in parallel; autoregressive output steps remain sequential, and dense whole-sequence attention has a roughly quadratic pair count."},"body":{"format":"markdown","text":"## The problem it solves\n\nRead this sentence: *The trophy would not fit in the suitcase because it was too big.*\n\nWhat does \"it\" refer to? The trophy. Now change one word: *...because it was too small.* Now \"it\" is the suitcase. Nothing about the position of the word changed; the meaning of a nearby word flipped the reference.\n\nA language system needs ways to connect related parts of a sentence. Attention is one important mechanism for doing that. The 2017 Transformer combined self-attention with other components in an architecture that made highly parallel training practical; it was not the first use of attention or the sole cause of later progress.\n\n## What attention does, in plain terms\n\nIn causal self-attention, a position can combine information from allowed positions in its prefix, including itself. Learned query and key representations produce weights, which mix value representations. Those weights depend on the input and layer. Other attention patterns, such as a bidirectional encoder’s, allow different connections.\n\nIn the trophy example, a causal decoder processing the earlier word “it” cannot attend to the later word “big”. Once the whole sentence is in its input, a later position used to answer the question can draw on both nouns and the adjective. This illustrates what information is available; it is not a measurement of any particular attention head’s weights.\n\nParallel attention operations using separately learned projections are called **heads**. Particular heads in studied models can show recognisable patterns, including syntactic relationships. That does not give every head a fixed job or make one weight map a complete explanation of the model’s answer.\n\nTransformer layers repeatedly transform these representations. Their number and organisation vary by model, and they include components besides attention. It is useful to picture successive refinement, but not to assign grammar to all early layers and meaning to all later ones.\n\n## Why it replaced what came before\n\nMany earlier sequence models used recurrent networks, which carry a state from one position to the next. They were not the only alternative: convolutional and bidirectional designs also existed. Recurrence creates a sequential dependency that is especially relevant when comparing training speed.\n\nIn a recurrent chain, a distant relationship can require information to pass through many steps. Within a sequence, the next recurrent state depends on the preceding one, limiting how much that part of the work can be parallelised. Other operations and separate sequences can still run in parallel.\n\nSelf-attention provides shorter connections between positions, and during training the known sequence positions can be processed in parallel, with a mask preventing access to future targets where needed. Generating a new autoregressive response is still sequential across output steps. This training advantage helped scaling; it does not guarantee perfect use of distant information or remove the need for data, hardware and other engineering.\n\nThe original paper is [Attention Is All You Need](https://arxiv.org/abs/1706.03762), published in 2017 by Vaswani and colleagues. It describes the architecture, causal masking and translation experiments, and is freely available.\n\n## The cost, which you feel every day\n\nFor a dense attention calculation across a whole sequence, the number of token pairs grows roughly with the square of its length. Doubling the length gives about four times as many pairs. This is a scaling illustration for that operation, not a benchmark of total runtime, memory or the cost of every decoding step.\n\n> Figure: Dense attention: a scaling illustration. Line chart of Relative n-squared pair-count proxy against Tokens in the context: Comparisons between tokens (1000, 1) (2000, 4) (4000, 16) (8000, 64) (16000, 256). The plotted values use a simple squared-length proxy: one thousand tokens is the reference, and doubling length multiplies the proxy by four. Dense causal whole-sequence attention has a roughly quadratic pair count. These are illustrative values, not runtime or billing measurements. Caching, other model operations, attention variants and hardware affect actual costs.\n\nThis helps explain some long-context engineering trade-offs:\n\n- In dense attention, processing longer inputs increases work; the actual latency and memory use depend on the implementation and hardware.\n- Engineers develop efficient exact implementations as well as sparse or approximate attention, caching and other architectures. These solve different parts of the cost problem.\n- Larger advertised windows also depend on training, positional methods, memory and product design. They did not grow because of one approximation alone.\n\n## The limitation: a window is not comprehension\n\nAn advertised context limit describes a capacity, subject to the model and API’s input and output rules. It does not establish that every position is used equally well, or that every supplied document was included by the application.\n\n[Lost in the Middle](https://aclanthology.org/2024.tacl-1.9/), first circulated in 2023 and published in 2024, tested selected models on multi-document question answering and key-value retrieval. Performance often fell when relevant information was in the middle rather than at an end. It is a result for those models and tasks, not a universal accuracy curve for every current model.\n\nFor a fifty-page contract, first check that the relevant text was actually supplied. Even when page twenty-seven is within the window, a correct answer about clause thirty-four is not guaranteed. The model’s answer and a diagram of its architecture do not establish which passage it used.\n\n**What to try:** supply the relevant passage directly, test different placements where useful, and ask about one section at a time. These are evaluation strategies, not guaranteed fixes. Check each material answer against the contract itself, using qualified help when the decision requires it."},"check":{"question":"What was an important training advantage of the Transformer over a recurrent chain?","options":[{"text":"It reduced the number of parameters needed, so models became cheaper to store and run.","correct":false,"tempting":"Parallelism is a property of how computation is organised, not a guarantee of fewer parameters or lower storage."},{"text":"It let the model read text in both directions, doubling the information available per word.","correct":false,"tempting":"Describes bidirectional reading, which some models do, rather than the property that changed training economics."},{"text":"It removed the need for training data to be labelled by people.","correct":false,"tempting":"Credits attention with self-supervised training on raw text, which predates it and is a separate idea."},{"text":"Known sequence positions can be processed in parallel during training rather than waiting for a recurrent state at each step. This does not make autoregressive output generation simultaneous.","correct":true}]},"prev":{"slug":"the-next-word-game","title":"One chunk at a time, and it cannot take it back","url":"https://addaly.com/learn/ai-actually-explained/the-next-word-game"},"next":{"slug":"embeddings-meaning-as-position","title":"Meaning as a position in space","url":"https://addaly.com/learn/ai-actually-explained/embeddings-meaning-as-position"},"authorship":"Founder and series editor: Dr Mustafa Mun. Written by AI models to a written standard. Source and assessment review continues. Academic review invited.","review":{"status":"Draft, open for academic review"},"cite":"Addaly (2026) 'Attention, without a single equation', in AI, Actually Explained. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/ai-actually-explained/attention-what-it-does (Accessed: 29 November 2026).","licence":{"name":"CC BY-NC-SA 4.0","url":"https://creativecommons.org/licenses/by-nc-sa/4.0/"},"reader":{"schema":1,"title":"Attention, without a single equation","courseTitle":"AI, Actually Explained","module":{"index":3,"slug":"how-a-chatbot-works","title":"What a chatbot is actually doing"},"answer":null,"keyIdea":"Self-attention combines information across allowed positions. In a causal decoder it cannot use a future token at an earlier position. Transformer training can process known positions in parallel; autoregressive output steps remain sequential, and dense whole-sequence attention has a roughly quadratic pair count.","hero":{"kind":"figure","figure":{"t":"figure","label":"Figure","figure":{"type":"line","title":"Dense attention: a scaling illustration","caption":"The plotted values use a simple squared-length proxy: one thousand tokens is the reference, and doubling length multiplies the proxy by four. Dense causal whole-sequence attention has a roughly quadratic pair count. These are illustrative values, not runtime or billing measurements. Caching, other model operations, attention variants and hardware affect actual costs.","xLabel":"Tokens in the context","yLabel":"Relative n-squared pair-count proxy","series":[{"label":"Comparisons between tokens","points":[[1000,1],[2000,4],[4000,16],[8000,64],[16000,256]]}]},"alt":"Figure: Dense attention: a scaling illustration. Line chart of Relative n-squared pair-count proxy against Tokens in the context: Comparisons between tokens (1000, 1) (2000, 4) (4000, 16) (8000, 64) (16000, 256). The plotted values use a simple squared-length proxy: one thousand tokens is the reference, and doubling length multiplies the proxy by four. Dense causal whole-sequence attention has a roughly quadratic pair count. These are illustrative values, not runtime or billing measurements. Caching, other model operations, attention variants and hardware affect actual costs."}},"blocks":[{"t":"h2","id":"the-problem-it-solves","runs":[{"text":"The problem it solves"}]},{"t":"p","runs":[{"text":"Read this sentence: "},{"text":"The trophy would not fit in the suitcase because it was too big.","i":true}]},{"t":"p","runs":[{"text":"What does “it” refer to? The trophy. Now change one word: "},{"text":"...because it was too small.","i":true},{"text":" Now “it” is the suitcase. Nothing about the position of the word changed; the meaning of a nearby word flipped the reference."}]},{"t":"p","runs":[{"text":"A language system needs ways to connect related parts of a sentence. Attention is one important mechanism for doing that. The 2017 Transformer combined self-attention with other components in an architecture that made highly parallel training practical; it was not the first use of attention or the sole cause of later progress."}]},{"t":"h2","id":"what-attention-does-in-plain-terms","runs":[{"text":"What attention does, in plain terms"}]},{"t":"p","runs":[{"text":"In causal self-attention, a position can combine information from allowed positions in its prefix, including itself. Learned query and key representations produce weights, which mix value representations. Those weights depend on the input and layer. Other attention patterns, such as a bidirectional encoder’s, allow different connections."}]},{"t":"p","runs":[{"text":"In the trophy example, a causal decoder processing the earlier word “it” cannot attend to the later word “big”. Once the whole sentence is in its input, a later position used to answer the question can draw on both nouns and the adjective. This illustrates what information is available; it is not a measurement of any particular attention head’s weights."}]},{"t":"p","runs":[{"text":"Parallel attention operations using separately learned projections are called "},{"text":"heads","b":true},{"text":". Particular heads in studied models can show recognisable patterns, including syntactic relationships. That does not give every head a fixed job or make one weight map a complete explanation of the model’s answer."}]},{"t":"p","runs":[{"text":"Transformer layers repeatedly transform these representations. Their number and organisation vary by model, and they include components besides attention. It is useful to picture successive refinement, but not to assign grammar to all early layers and meaning to all later ones."}]},{"t":"h2","id":"why-it-replaced-what-came-before","runs":[{"text":"Why it replaced what came before"}]},{"t":"p","runs":[{"text":"Many earlier sequence models used recurrent networks, which carry a state from one position to the next. They were not the only alternative: convolutional and bidirectional designs also existed. Recurrence creates a sequential dependency that is especially relevant when comparing training speed."}]},{"t":"p","runs":[{"text":"In a recurrent chain, a distant relationship can require information to pass through many steps. Within a sequence, the next recurrent state depends on the preceding one, limiting how much that part of the work can be parallelised. Other operations and separate sequences can still run in parallel."}]},{"t":"p","runs":[{"text":"Self-attention provides shorter connections between positions, and during training the known sequence positions can be processed in parallel, with a mask preventing access to future targets where needed. Generating a new autoregressive response is still sequential across output steps. This training advantage helped scaling; it does not guarantee perfect use of distant information or remove the need for data, hardware and other engineering."}]},{"t":"p","runs":[{"text":"The original paper is "},{"text":"Attention Is All You Need","href":"https://arxiv.org/abs/1706.03762"},{"text":", published in 2017 by Vaswani and colleagues. It describes the architecture, causal masking and translation experiments, and is freely available."}]},{"t":"h2","id":"the-cost-which-you-feel-every-day","runs":[{"text":"The cost, which you feel every day"}]},{"t":"p","runs":[{"text":"For a dense attention calculation across a whole sequence, the number of token pairs grows roughly with the square of its length. Doubling the length gives about four times as many pairs. This is a scaling illustration for that operation, not a benchmark of total runtime, memory or the cost of every decoding step."}]},{"t":"p","runs":[{"text":"This helps explain some long-context engineering trade-offs:"}]},{"t":"ul","items":[[{"text":"In dense attention, processing longer inputs increases work; the actual latency and memory use depend on the implementation and hardware."}],[{"text":"Engineers develop efficient exact implementations as well as sparse or approximate attention, caching and other architectures. These solve different parts of the cost problem."}],[{"text":"Larger advertised windows also depend on training, positional methods, memory and product design. They did not grow because of one approximation alone."}]]},{"t":"h2","id":"the-limitation-a-window-is-not-comprehension","runs":[{"text":"The limitation: a window is not comprehension"}],"role":"limit"},{"t":"p","runs":[{"text":"An advertised context limit describes a capacity, subject to the model and API’s input and output rules. It does not establish that every position is used equally well, or that every supplied document was included by the application."}]},{"t":"p","runs":[{"text":"Lost in the Middle","href":"https://aclanthology.org/2024.tacl-1.9/"},{"text":", first circulated in 2023 and published in 2024, tested selected models on multi-document question answering and key-value retrieval. Performance often fell when relevant information was in the middle rather than at an end. It is a result for those models and tasks, not a universal accuracy curve for every current model."}]},{"t":"p","runs":[{"text":"For a fifty-page contract, first check that the relevant text was actually supplied. Even when page twenty-seven is within the window, a correct answer about clause thirty-four is not guaranteed. The model’s answer and a diagram of its architecture do not establish which passage it used."}]},{"t":"p","runs":[{"text":"What to try:","b":true},{"text":" supply the relevant passage directly, test different placements where useful, and ask about one section at a time. These are evaluation strategies, not guaranteed fixes. Check each material answer against the contract itself, using qualified help when the decision requires it."}]}],"check":{"question":[{"text":"What was an important training advantage of the Transformer over a recurrent chain?"}],"options":[{"text":[{"text":"It reduced the number of parameters needed, so models became cheaper to store and run."}],"correct":false,"tempting":[{"text":"Parallelism is a property of how computation is organised, not a guarantee of fewer parameters or lower storage."}]},{"text":[{"text":"It let the model read text in both directions, doubling the information available per word."}],"correct":false,"tempting":[{"text":"Describes bidirectional reading, which some models do, rather than the property that changed training economics."}]},{"text":[{"text":"It removed the need for training data to be labelled by people."}],"correct":false,"tempting":[{"text":"Credits attention with self-supervised training on raw text, which predates it and is a separate idea."}]},{"text":[{"text":"Known sequence positions can be processed in parallel during training rather than waiting for a recurrent state at each step. This does not make autoregressive output generation simultaneous."}],"correct":true,"tempting":null}],"order":[2,0,1,3],"why":null},"prev":{"slug":"the-next-word-game","title":"One chunk at a time, and it cannot take it back","minutes":9},"next":{"slug":"embeddings-meaning-as-position","title":"Meaning as a position in space","minutes":10}}}