Week 09 · lesson

Investigation: Attention Is a Calculated Allocation

system flow

From Query and Keys to a Bounded Attention Claim

  1. Ordered Tokens

    Begin with declared tokens and positional information.

  2. Query and Keys

    Use supplied vectors for one simplified attention head.

  3. Dot Products

    Calculate one query-key score per position.

  4. Softmax

    Exponentiate and normalize scores into weights summing to one.

  5. Query Comparison

    Change only the query and measure allocation change.

  6. Claim Boundary

    Do not infer probability, causal explanation, reasoning, or safety.

Read this concept flow as plain text
  1. Ordered Tokens. Begin with declared tokens and positional information. LAB: 3 TOKENS.
  2. Query and Keys. Use supplied vectors for one simplified attention head. BOUNDARY: INVENTED VECTORS.
  3. Dot Products. Calculate one query-key score per position. SCORE: Q DOT K.
  4. Softmax. Exponentiate and normalize scores into weights summing to one. CHECK: SUM = 1.
  5. Query Comparison. Change only the query and measure allocation change. RISK: QUERY DEPENDENCE.
  6. Claim Boundary. Do not infer probability, causal explanation, reasoning, or safety. ACTION: REPAIR CLAIM.

A generative model repeatedly scores possible next tokens and selects or samples one. Attention solves a different problem inside the model: it builds a context representation by weighting input positions for a particular query.

For one simplified attention head:

score_i = query · key_i
weight_i = exp(score_i) ÷ sum(exp(all scores))

Softmax makes the weights positive and forces them to sum to 1. Real transformers also use learned projections, scaling, multiple heads, value vectors, residual connections, and additional layers.

Completed calculation

Use query object = [1,0] and these invented keys:

robot   = [0.9,0.1]  score 0.9  exp(score) 2.460
battery = [0.8,0.2]  score 0.8  exp(score) 2.226
safely  = [0.1,0.9]  score 0.1  exp(score) 1.105
sum = 5.790

Normalized weights are approximately:

robot 0.425, battery 0.384, safely 0.191

The weights sum to 1. They show allocation under this query and these supplied vectors. They do not prove why a trained model produced an answer.

Generation temperature is a separate control

In generation, temperature reshapes next-token scores before sampling. Lower temperature concentrates selection; higher temperature spreads it. It does not verify accuracy, creativity, or safety, and it does not repair a weak model or bad context.

Investigation

  1. Reproduce every object-query attention weight.
  2. Change the query to action = [0,1] and calculate new dot products.
  3. Predict which key will receive the highest action-query weight.
  4. Explain why positional encoding is still needed when tokens are processed in parallel.
  5. Repair: “The largest attention weight explains the model's decision.”

Vocabulary lab

Flip the idea, not just the card

Explain the term before you reveal the back. Then compare your explanation with the definition, example, and warning.

1 / 5
Read all terms without animation
query
A vector representing what one attention calculation is seeking. Example: The object query is 1,0. Do not confuse it with: It is not necessarily a human-language question.
key
A vector used to calculate how strongly a position matches a query. Example: Robot has the supplied key 0.9,0.1. Do not confuse it with: A key is not the same as the value information later combined.
softmax
A normalization that converts scores into positive weights summing to one. Example: The three object-query weights sum to 1. Do not confuse it with: A softmax weight is not automatically a calibrated probability.
self-attention
Attention whose queries, keys, and values come from the same sequence. Example: Each token position can weight other positions in its sentence. Do not confuse it with: It does not process order without positional information.
positional encoding
Information added so a transformer can distinguish sequence positions. Example: Two identical token embeddings at different positions receive different position signals. Do not confuse it with: It is separate from token identity.