Macalinao StudioLearnAll enriched lessons ↗
High school path · 7 sectionsSwitch to college ↗

High school / LONGER LESSON 22

Q, K and V: projections you can differentiate

Separate routing and content; calculate projection and shared-input gradients.

Preparation: Coordinates; matrix calculus for college.

Plan 20–35 minutes with the activities; this is a study estimate, not a timed requirement. Both paths have complete narration. Your notes and progress are kept separately for each level.

Section 01 / 07

Three descriptions of one input

High-school path. Separate routing and content; calculate projection and shared-input gradients.

Preparation: Coordinates; matrix calculus for college. Work through one section at a time. Predict the experiment result before changing its controls, then explain what the example leaves out.

An item has two features: two and one. A learned rule can turn these into a query, another rule into a key, and another into a value. The item is unchanged; the descriptions serve different jobs. Queries and keys decide where information goes. Values decide what information travels. The letters do not represent fixed English meanings. They name roles in a learned calculation.

Worked step 1. Let x=[2,1].

Worked step 2. Use projection columns [1,0], [0,1] and [1,1].

Worked step 3. The scalar query, key and value become two, one and three.

Q=XW_Q; K=XW_K; V=XW_V

Multiply the input by three learned matrices to obtain queries, keys and values.

Try it yourself. Changing only the value projection directly changes which role?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. It changes message content. Query-key scores remain fixed if queries and keys are unchanged.

Section 02 / 07

Use shapes as a contract

A table with three items and two features has three rows and two columns. To produce four query features per item, the rule table needs two input rows and four output columns. The middle sizes match. Every item receives four results, so the output has three rows and four columns. Reading these sizes before multiplying is a practical way to catch a mistake without doing all the arithmetic.

Worked step 1. Input shape: 3×2.

Worked step 2. Projection shape: 2×4.

Worked step 3. Output shape: 3×4.

Try it yourself. Can a 3×2 input directly multiply a 4×2 projection here?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Inner dimensions two and four differ. Transposing that projection gives a compatible 2×4 matrix.

Section 03 / 07

Hold messages fixed and change routing

Workbench fixes three value messages and lets you alter the query projection. Move its scale through zero. At zero, the query cannot prefer one key through these dot products, so the weights are equal. Reversing the sign can reverse the preference. A separate value-gain control changes the messages while leaving the weights alone. This lets you compare two changes that may look similar in the final output but happen at different stages.

Worked step 1. At zero query scale, equal weights average [10,20,30] to twenty.

Worked step 2. Positive and negative scales prefer different keys.

Worked step 3. Doubling value gain doubles the mixture with weights fixed.

Try it yourself. If weights are unchanged and every value doubles, what happens?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. The output doubles. A fixed weighted sum is linear in its values.

Section 04 / 07

Differentiate the learned rule

Suppose a scalar query made from x=[2,1] receives an upstream sensitivity of three. Each weight's sensitivity is its input feature times three, so the two results are six and three. If several items use the same rule, add their contributions. A gradient says how a small change would affect the loss. Gradient descent subtracts a scaled gradient; it does not automatically add it.

Worked step 1. x=[2,1], upstream query sensitivity=3.

Worked step 2. The weight gradient is [6,3] transposed.

Worked step 3. At learning rate 0.1, gradient descent subtracts [0.6,0.3].

G_WQ=XᵀG_Q; G_X(query)=G_QW_Qᵀ

The query-weight gradient is input transpose times upstream query gradient. The input receives upstream gradient times query-weight transpose.

Try it yourself. A second item contributes [1,−2]. What is the combined weight gradient?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. Add contributions to obtain [7,1]. The same parameters were used twice.

Section 05 / 07

Add shared-input paths

The original input can affect an answer through three roads: query, key and value. Its total sensitivity adds the traffic from all three roads. This does not mean the road rules are identical. The query parameters still receive their own update. The addition happens where the three paths meet at the shared input. Positive and negative contributions can reinforce or partly cancel one another.

Worked step 1. The three input contributions are [1,2], [−1,3] and [4,−2].

Worked step 2. Add coordinate by coordinate.

Worked step 3. The total is [4,3].

G_X=G_QW_Qᵀ+G_KW_Kᵀ+G_VW_Vᵀ

Sum the query, key and value contributions at the shared input.

Try it yourself. Can you add the projection matrices themselves to obtain the input gradient?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Each transposed matrix must first be weighted by its own upstream gradient.

Section 06 / 07

Sharing heads saves different things

Several query heads can share the same key and value descriptions. Different questions can still compare with shared labels and mix shared messages differently. This can reduce the information stored during text generation. Sharing keys and values does not make every query identical. Always say how many query heads and how many key-value heads are present instead of assuming one common count.

Worked step 1. Thirty-two query heads share eight KV heads.

Worked step 2. An even grouping assigns four query heads to each KV head.

Worked step 3. Cache storage uses eight key-value heads, not thirty-two.

Try it yourself. Does placing all projections in one packed matrix force equal weights?

Pause the recording and write your reasoning before continuing. The worked solution follows.

Reveal worked solution

Worked solution. No. Independent parameter blocks can share a storage container without being tied.

Section 07 / 07

Mastery and transfer

Bring the pieces together. First answer the checkpoint without the worked solutions. Then explain the mechanism in your own words, using one numerical example from this lesson.

Doubling values with weights fixed… Option 1: Doubles the output. Option 2: Changes the key ranking. Option 3: Always does nothing.

Pause here and choose an answer before continuing. The checkpoint explanation follows.

Reveal worked solution

The correct choice is option 1: Doubles the output. The mixture is linear in values.

Transfer task. Change one assumption in the worked example. State your prediction, calculate or test it in Workbench, then explain whether the result supports your prediction.

Reveal worked solution

Self-check rubric. Name the changed assumption, keep the other inputs fixed, show at least one intermediate calculation, and distinguish what the toy example guarantees from what would require a trained model or a real measurement.

Sources and scope

Original worked examples and teaching text, grounded in these primary references. Numerical fixtures explain mechanisms; model quality and hardware performance require separate measurements. Both levels share key examples, with different explanations and checkpoints.

EXTENDED FIELD NOTES

What a model learns: from numbers to a useful answer

Follow a sentence through learned weights, temporary activations, and the next-token decision.

Additional reading · original lesson audio remains unchanged.

Read the full explanation · 586 words
What changes when you ask a question?

The weights stay fixed during ordinary inference. Activations change with your input.

  1. Text → tokens
  2. Tokens → vectors
  3. Learned transformations
  4. Next-token scores

Text → tokens

A model is a computation with learned settings

A language model does not contain a little librarian choosing a finished answer from a shelf. It contains a structured computation whose numerical settings were learned during training. Those settings are called parameters. Many are weights arranged in matrices; other parameters can include offsets or normalization scales. The architecture determines which operations happen and how information travels. The weights determine the particular transformations performed by those operations. Two models can share an architecture and behave differently because they learned different parameter values.

Consider a tiny operation: y = 0.6x₁ − 0.2x₂ + 0.1. With inputs x₁ = 2 and x₂ = 3, the output is 0.7. Changing the first weight from 0.6 to 0.5 changes the output to 0.5. This is a teaching example, not a miniature intelligent system. Its purpose is to make one idea visible: numerical settings influence the result. In a language model, many such transformations act together across large vectors, nonlinear functions, and layers.

Follow the sentence

First, a tokenizer turns text into a sequence of token identifiers. A token may represent a word, part of a word, punctuation, or another unit. An embedding table supplies a learned vector for each identifier. These vectors are starting representations, not complete dictionary definitions. As they pass through the network, surrounding tokens influence how the current sequence is represented.

In attention, learned projections produce queries, keys, and values. The model compares queries with keys to calculate input-dependent attention scores, then combines value representations. This distinction matters: the projection weights normally remain fixed during a conversation, while the attention scores change with the input. Feed-forward transformations further process the representations, and residual connections carry information around sublayers. Finally, an output transformation supplies scores for possible next tokens. A selection procedure chooses a continuation, which becomes part of the next input step.

Training changes the settings; a conversation changes the state

During training, a loss measures how the predictions compare with the training objective. Gradients estimate how parameter changes would affect that loss. An optimizer uses those gradients to update trainable parameters. A single example does not usually teach an isolated fact to one identifiable weight. Useful patterns emerge through many updates, and knowledge and behavior are distributed across the computation.

During ordinary inference, the parameters stay fixed. Your prompt changes the activations: the temporary numbers produced while the model runs. A cache can retain intermediate information so the system need not repeat earlier work. That cache is not a new permanent education for the model. A product may separately save conversation history or conduct later training, but those are additional mechanisms. Saying that a chatbot remembers your previous sentence does not establish that its weights changed.

Why more parameters is not a complete explanation

A parameter count describes scale, not a guarantee of reliability. Data quality, architecture, training, numerical precision, and the way a model is evaluated all matter. A large model can produce a convincing error; a smaller specialized model can perform a narrow task well. To compare systems, ask what task was tested and under what conditions, rather than treating one number as a universal intelligence score.

Return to the animation and identify three different objects: a stored weight, an activation that changes with the sentence, and an output score. If the diagram uses moving dots, those dots represent information flow; they are not literal particles inside a model. Using the small equation above on paper, change an input while keeping a weight fixed, then change the weight while keeping the input fixed. Explain why these are different experiments. That distinction will help you understand fine-tuning, quantization, caches, and model releases throughout the course.

Sources and further investigation

Source review: October 28, 2026. Model-release claims are attributed to their publishers.

Open the focused reading page →

Reset this high school path?

This removes only this path’s notes, progress and experiments from this browser.