02 · Attention
📝 My Notes
Topic 02 · Understand Context

Attention is
selective focus.

A language model needs more than the words themselves. It needs to decide which other words matter for the token it is processing right now. Attention makes that focus dynamic.

13 guided subtopicsIntuition → mechanismInteractive example
LIVE ATTENTION EXPLORERSentence: “Adavitha is playing with Charan in the park.” Select a word to inspect the context it may use.● INTERACTIVE
ATTENTION LINKS · CONCEPTUAL EXAMPLE
playing is the current focus. Attention may connect it to Adavitha, with, and Charan.
SELECT ANY WORD TO CHANGE FOCUSIllustrative relationship · not model scores
LIVE CONCEPT MODEL · WORD BY WORD

One sentence, different attention relationships

Sentence: “Adavitha is playing with Charan in the park.” Choose a word in the sentence above or in this table. The selected row and its attention words will be highlighted together.

WordAttention wordsWhy?
playing, CharanWho is playing, and with whom?
playingConnects the subject to the action.
Adavitha, with, CharanIdentifies the action and participants.
playing, CharanConnects the action to the person joining in.
Adavitha, playingIdentifies the playmate.
playing, parkConnects the action to the location.
parkHelps specify the place.
playing, inIdentifies where the action happens.

Specific attention example: When processing “playing,” the model may pay strong attention to “Adavitha” and “Charan” to understand who is playing and with whom. The word “with” also helps express their relationship in this sentence.

Teaching illustration only: these links explain plausible context relationships. They are not attention weights measured from a trained model.

INTERACTIVE LAB · THREE.JS + D3 + GSAP

See attention in 3D.

Explore the orbital token field from Attention-Lab-3D: glowing token spheres, floating labels, a central geometric core, orbital rings, and animated weighted connections. The matrix, focus token, and explanation stay synchronized.

8 tokens · 3 illustrative heads
01 / 3D ATTENTION MAPSCENE READY
Loading the 3D scene…
Three.js is initializing. An internet connection is needed for the visualization libraries.
CURRENT QUERY TOKEN

playing

The current token can draw useful context from the subject, the relationship word, and the other participant.

02 / ATTENTION MATRIX
LOWHIGHCell = illustrative weight
HOW TO READ THIS

Rows ask. Columns contribute.

Each row is the focus token (query). Each column is a possible source of information (key/value position). Brighter cells mean a larger illustrative weight for this teaching example. Select any cell to inspect that relationship in 3D.

Teaching model only: weights are hand-authored to demonstrate the idea. They are not measured from a trained model, and the “heads” are conceptual lenses—not real learned attention heads.

01 / THE BIG PICTURE

Where attention fits in the journey

Attention is not the whole language model. It is a mechanism inside the Transformer that helps each token build a representation informed by other tokens. Follow the flow below; later subtopics unpack each step.

01 · INPUT

Tokens in a sequence

The sentence is represented as token pieces, each with a position and an initial vector.

02 · MATCH

Compare relevance

Query and key vectors produce scores that indicate which tokens are relevant to the current token.

03 · WEIGHT

Turn scores into weights

Softmax converts scores into normalized attention weights for the chosen focus token.

04 · CONTEXT

Mix useful information

The weights combine value vectors to create a context-aware representation.

02 / CORE INTUITION

One sentence. Different questions. Different focus.

Attention is contextual: the useful evidence for one word may differ from the evidence needed for another. This is the key idea to understand before diving into Q, K, V, scores, and matrices.

Try it above

Choose a token in the live example. The highlighted token is the one whose context we are imagining. The other highlighted words represent possible sources of useful information.

contextᵢ = Σⱼ weightᵢⱼ × valueⱼ

The equation says: for the current token i, take information from tokens j, scale each contribution by its attention weight, then add the contributions together.

What to notice

01
Focus is local to a query

The model calculates a separate attention distribution for each token position.

02
Weights control contribution

A larger weight means that source contributes more to this weighted mixture.

03
It is learned, not hand-written grammar

The mechanism learns useful patterns from training; these weights are not automatically human explanations.

03 / WHY IT MATTERS

The problem attention helps solve

A sequence contains relationships spread across positions. A single fixed-size summary can become a bottleneck. Attention provides a way for a token to retrieve and combine relevant information from other positions as needed.

Without dynamic attention

Earlier sequence models often had to carry information forward through a recurrent state. Important details could become harder to preserve as sequences grew longer.

With attention

A token can directly compare with other token representations and build a context-aware mixture. In Transformers, this operation can be applied across positions in parallel during training.

04 / STUDY PATH

Explore the subtopics

Start with the intuition, then inspect the mechanism and examples. Each card opens the existing lesson file in this folder.

🧠Attention Lab — From Sentence to AI Assistant

Interactive end-to-end walkthrough: tokens → embeddings → Q·K·V → scores → softmax → context → Transformer.

INTERACTIVE LAB · 19 STAGES
↗
NEXT IN THE JOURNEY

Next: Self-Attention — turn focus into a mechanism

Move from the intuition to the mechanism: each token compares itself with other tokens in the same sequence, then combines useful information. Query, Key, and Value are explored in the next layer of this path.

Continue to Self-Attention ↗
▶LIVE DEMOAttention Simulator →
This page 0:00
This session 0:00
Total (all pages) 0:00
Today 0:00
▶ Running
📊 View all study stats →
0:00 studying