Attention and Paradigms: A Worked Example

How a query, keys, and values can model a Kuhnian revolution (companion to Final Project Option 1)

Author

HON 201 - Week 13

Why add attention?

In the Week 10 simulation and your Week 12 project, the network judged evidence with fixed weights. The epicycle count always got the same weight, whoever was looking and whatever else was on the table. The only way to change a weight was backpropagation: get an answer wrong, send blame backward, and nudge the weights a little, epoch after epoch.

That model misses something Kuhn cares about. In his account, a revolution is not a slow adjustment of how much each fact counts. It is a change in what the community is looking for. After the change, the same observations mean something different. In the Postscript he puts it this way: people who receive the same stimuli can still see different things, because training shapes the route from stimulus to perception (pp. 192-193).

Attention gives us a way to model that. In attention, how much a piece of evidence counts is not fixed. It is computed fresh each time, from how well the evidence matches what the observer is looking for. Change what the observer is looking for, and the same evidence gets weighted differently, all at once.

The three roles

Recall from the attention slides that every item plays three roles. Here is how they translate into the language of paradigms.

Role In a transformer In our model of a revolution
Query what a word is looking for what the paradigm looks for in evidence
Key what a word offers, so others can find it what kind of evidence this is
Value the information a word hands over if chosen how much this evidence strains the old model

The idea in one sentence: the paradigm is the query. An anomaly is evidence whose key does not match the paradigm’s query, so the paradigm pays it almost no attention.

The setup

We use evidence from the Copernican crisis, which you know from Week 10.

Keys: what kind of evidence is it?

Each key is a list of two numbers. Each number scores one feature of the evidence:

  1. Does it threaten the perfect-heavens model? Positive means yes; negative means it seems to support the old model.
  2. Does it depend on the new instrument (the telescope)? 1 means yes, 0 means no.

Values: how much strain does it carry?

Each value is a single number: how much this evidence, if taken seriously, strains the old model. Bigger means more strain.

Evidence Key (threat, telescope) Value (strain) Why these numbers
Calendar drift (0.2, 0) 1 A mild threat, seen without a telescope, modest strain
Jupiter’s moons (1, 1) 5 A direct threat (bodies orbiting something other than Earth), seen only by telescope, large strain
Moon’s mountains (0.8, 1) 4 A strong threat to celestial perfection, seen only by telescope
Epicycle count (−0.5, 0) 0.5 Read by the old paradigm as a sign of precision, so it seems to support the model; little strain

These numbers are chosen by hand to make the example clear. In a real transformer, keys and values are produced by learned weights, not chosen by anyone.

Queries: what is each paradigm looking for?

A query uses the same two features as the keys.

  • Ptolemaic query: (−1, −2). It favors evidence that does not threaten the model (−1 on the first feature) and it strongly distrusts the telescope (−2 on the second). This is the astronomer who suspects the lens is producing illusions.
  • Galilean query: (2, 1). It looks hard for threats to the old model (2) and trusts the telescope (1).

Notice what stays the same in both cases: the four pieces of evidence, their keys, and their values. Only the query changes.

Step 1: Match each key to the query (the dot product)

To measure how well a key matches a query, multiply the two lists number by number and add the results. This is called the dot product.

\[\text{score} = (\text{query}_1 \times \text{key}_1) + (\text{query}_2 \times \text{key}_2)\]

The dot product is large and positive when the two lists “point the same way,” near zero when they are unrelated, and negative when they point in opposite directions.

Ptolemaic query (−1, −2)

Evidence Key Calculation Score
Calendar drift (0.2, 0) (−1)(0.2) + (−2)(0) −0.2
Jupiter’s moons (1, 1) (−1)(1) + (−2)(1) −3.0
Moon’s mountains (0.8, 1) (−1)(0.8) + (−2)(1) −2.8
Epicycle count (−0.5, 0) (−1)(−0.5) + (−2)(0) 0.5

The epicycle count is the only positive match: the old paradigm finds it reassuring. The telescope evidence scores very low.

Galilean query (2, 1)

Evidence Key Calculation Score
Calendar drift (0.2, 0) (2)(0.2) + (1)(0) 0.4
Jupiter’s moons (1, 1) (2)(1) + (1)(1) 3.0
Moon’s mountains (0.8, 1) (2)(0.8) + (1)(1) 2.6
Epicycle count (−0.5, 0) (2)(−0.5) + (1)(0) −1.0

Now the order is reversed. Jupiter’s moons and the Moon’s mountains match best.

Step 2: Turn scores into shares (softmax)

The scores tell us which evidence matches best, but we cannot use them directly as weights. Some are negative, and they do not add up to anything in particular. We want attention shares: numbers that are all positive and add up to 100%, so that each one says what fraction of the paradigm’s attention goes to that piece of evidence.

The standard way to do this is called softmax. It has two steps.

  1. Exponentiate each score. Compute \(e^{\text{score}}\), where \(e \approx 2.718\). This makes every number positive. On a calculator use the \(e^x\) key; in a spreadsheet use =EXP(A1).
  2. Divide each result by the total. This makes the shares add up to 1, or 100%.

As a formula, the share for item \(i\) is

\[\text{share}_i = \frac{e^{\text{score}_i}}{e^{\text{score}_1} + e^{\text{score}_2} + e^{\text{score}_3} + e^{\text{score}_4}}\]

Ptolemaic query

Evidence Score \(e^{\text{score}}\) Share = \(e^{\text{score}} \div 2.5780\)
Calendar drift −0.2 0.8187 0.3176 (32%)
Jupiter’s moons −3.0 0.0498 0.0193 (2%)
Moon’s mountains −2.8 0.0608 0.0236 (2%)
Epicycle count 0.5 1.6487 0.6395 (64%)
Total 2.5780 1.0000 (100%)

Galilean query

Evidence Score \(e^{\text{score}}\) Share = \(e^{\text{score}} \div 35.4089\)
Calendar drift 0.4 1.4918 0.0421 (4%)
Jupiter’s moons 3.0 20.0855 0.5672 (57%)
Moon’s mountains 2.6 13.4637 0.3802 (38%)
Epicycle count −1.0 0.3679 0.0104 (1%)
Total 35.4089 1.0000 (100%)

Why exponentiate instead of something simpler?

  • It handles negative scores. \(e^x\) is positive for every \(x\), so no share can come out negative.
  • It rewards the best matches disproportionately. A score of 3.0 versus 2.6 is a small gap, but \(e^{3.0} \approx 20.1\) versus \(e^{2.6} \approx 13.5\) is a bigger one. Each additional point of score multiplies the weight by about 2.7. That is why attention tends to focus on a few items rather than spreading evenly.
  • Only the differences between scores matter. Adding the same number to every score changes nothing, because the extra factor cancels when you divide by the total. So the Galilean shares would be identical if every score were 10 points higher.

A simpler idea, such as shifting all the scores to be positive and dividing by their sum, breaks down: the lowest-scoring item always gets exactly 0%, and the result changes depending on how you shift. Softmax avoids both problems, which is why transformers use it. Charniak calls this step “probability normalization” (§10.1).

Step 3: Blend the values (a weighted sum)

Each paradigm’s perceived strain is a weighted sum of the four values, using its attention shares as the weights. This is exactly the operation a node performs in your Week 12 network. The difference is where the weights come from.

Ptolemaic query

\[\begin{aligned} \text{strain} &= (0.3176)(1) + (0.0193)(5) + (0.0236)(4) + (0.6395)(0.5) \\ &= 0.3176 + 0.0966 + 0.0944 + 0.3198 \\ &= 0.83 \end{aligned}\]

Galilean query

\[\begin{aligned} \text{strain} &= (0.0421)(1) + (0.5672)(5) + (0.3802)(4) + (0.0104)(0.5) \\ &= 0.0421 + 2.8362 + 1.5209 + 0.0052 \\ &= 4.40 \end{aligned}\]

Step 4: The verdict

We use the rule strain > 3 means paradigm shift; otherwise normal science.

Observer Strain Verdict
Ptolemaic 0.83 Normal science
Galilean 4.40 Paradigm shift

Why a threshold of 3, not the 5 we used in Week 10? Because the shares add up to 100%, the strain is a weighted average of the values. It can never be lower than the smallest value (0.5) or higher than the largest (5). A threshold of 3 sits in that range and means “attention is mostly on high-strain evidence.”

What changed, and what did not

Look at what was the same in both calculations: the evidence, its keys, its values, and the rule for the verdict. Only the query was different. Yet the two observers reached opposite conclusions in a single pass, with no epochs of correction.

That is the point of the model. It captures three ideas from Kuhn:

  • Anomalies are ignored, not refuted. The old paradigm never assigns Jupiter’s moons a negative weight. It simply gives them 2% of its attention, because they do not match what it is looking for. Compare the Week 10 network, where the old paradigm needed a negative weight to cancel inconvenient evidence.
  • The same data, seen differently. Both observers receive identical evidence. They differ in what they look for, which Kuhn says is learned through training and exemplars.
  • Revolutions are switches, not slides. Backpropagation changes weights gradually, which looks like the cumulative progress Kuhn argues against. Changing the query flips the verdict at once, closer to his “gestalt switch.”

Where the analogy is loose

A good poster names the limits of its own model.

  • We chose the query by hand. In a real transformer, the query is produced by learned weights, so a change of query is itself learned gradually by backpropagation. Is a revolution, then, really sudden? That is a good question for your poster.
  • Real models use many attention heads. Each head runs its own query, so a transformer always has several “viewpoints” at once. You could model factions (an astronomer, a calendar reformer, a Church authority) as separate heads.
  • Real models have many more numbers. Keys and queries have hundreds of features, not two, and the scores are divided by a scaling factor before softmax. The method is the same.
  • All the numbers here are invented. They are chosen to show the mechanism clearly, not measured from history.

Try it yourself

A calendar reformer cares about the drift and is mildly suspicious of the telescope. Model this observer with the query (1, −1).

  1. Compute the four dot-product scores.
  2. Apply softmax to get the attention shares.
  3. Compute the perceived strain and give the verdict.

Scores: calendar drift 0.2, Jupiter’s moons 0.0, Moon’s mountains −0.2, epicycle count −0.5.

Exponentials: 1.2214, 1.0000, 0.8187, 0.6065. Total 3.6467.

Shares: 33%, 27%, 22%, 17%.

Strain: (0.3349)(1) + (0.2742)(5) + (0.2245)(4) + (0.1663)(0.5) = 2.69. Just under 3, so normal science, but much closer to a shift than the Ptolemaic observer. This query spreads its attention evenly, so no single piece of evidence dominates. Is this observer a likely convert?

Building your own for Option 1

Start from the revolution and network you built in Week 12.

  1. List your evidence. Use the same inputs as your Week 12 network.
  2. Choose two or three key features that capture what kind of evidence each item is. Good features describe things a paradigm might care about or distrust: does it threaten the core theory, does it come from a new instrument or method, does it come from outsiders?
  3. Give each item a key and a value, and justify each number in a sentence.
  4. Write a query for the old paradigm and one for the new, and explain what each is looking for.
  5. Work through the four steps (dot product, softmax, weighted sum, verdict) and show the arithmetic.
  6. Make a heatmap like the one above for your poster: one row per query, one column per piece of evidence.
  7. Compare with your Week 12 model. Which captures your revolution better: gradual weight correction by backpropagation, or a change of query? What does each one miss?

A spreadsheet handles all of this: one column for keys, one for values, =EXP() for the exponentials, and =SUM() for the totals.