beginner · Session 11

How a model learns from examples

Follow a complete learning loop without advanced math: example, prediction, error, small adjustment, repetition.

120 min6 mechanismscausal lab

What you will be able to do

Open the lab

Study method

Study this session as a causal investigation. Before every formula or interaction, write what you expect to change and what must remain fixed. During the calculation, retain units, shapes, and intermediate values so an error can be located without restarting at random. After the result, translate the number or state into one sentence about system behavior. Always finish with a counterexample or boundary value. This discipline separates understanding a mechanism from merely recognizing its vocabulary and makes the lab reproducible by another learner. Record the evidence that changed your initial prediction.

Build the mechanism step by step

1. An example and a target

The problem: You want a program to complete “the sky is…”. Without examples you would need one hand-written rule per possible sentence: 10,000 sentences, 10,000 rules, and sentence 10,001 still fails. Nobody can maintain that catalogue.

The idea: An example replaces the rule with a signal: an input plus the expected answer. For “the sky is…”, the target “blue” explains nothing — it gives a point of comparison. Our toy model keeps only the numbers: input x = 2, target y = 1.

Why / at what price: It works because comparison signals can be collected by the million, while rules must be written one at a time. The price: the target never says why. A wrong example — “the sky is… → green” — would be learned just as obediently as a right one.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

2. The prediction

The problem: How do you correct a model that knows nothing yet? “It guesses badly” cannot be measured. Without a numeric output to compare against the target there is no computable gap and no direction of progress: the loop cannot even start.

The idea: The model applies whatever its current setting is: p = w × x. With w = 0.4 and x = 2 it proposes p = 0.8. That 0.8 is neither good nor bad in itself: it is the raw material for the comparison with the target 1.

Why / at what price: Why this is enough: even a bad numeric prediction makes the gap measurable, hence correctable. The price: a prediction commits to nothing — 0.8 can be nearly right for one (x, y) pair and absurd for another. Never judge a model on a single output.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

3. Measure the error

The problem: “The prediction is bad” — bad by how much, and in which direction? If you do not know whether 0.8 is too high or too low relative to 1, you cannot tell whether w should go up or down. A verdict without a sign guides nothing.

The idea: The error turns the verdict into a signed number: e = 1 − 0.8 = +0.20, so predict higher. A prediction of 1.3 would give e = −0.30: predict lower. The sign gives the direction, the magnitude gives the size of the move.

error = target − prediction

Why / at what price: Why it works: a signed number is exactly what the update step can consume. The price: e measures one example only. A model can be perfect on (2, 1) and wrong everywhere else — it is a local compass, not a general certificate.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

4. Adjust one parameter

The problem: You know the model must predict higher. By how much should w = 0.4 move? Jumping straight to the perfect value over-reacts to one possibly atypical example; not moving at all learns nothing. You need a measured step between those extremes.

The idea: The update sizes the step with the learning rate: w ← 0.4 + 0.1 × 0.20 = 0.42. The new prediction 0.84 moves toward the target 1 without reaching it: each example pulls the setting a little, none dictates it.

new weight = old weight + learning rate × error

Why / at what price: The cost of sizing shows in the rate table: at 0.001 progress is invisible, at 3 the error explodes from 0.20 to 5.00. The learning rate is not an implementation detail: it is the speed/stability trade-off, and a human chooses it.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

5. Repeat across many examples

The problem: Trained on (2, 1) alone, the model converges to w = 0.5 — perfect on that example. Then example B arrives: x = 1, target 0.7. It would need w = 0.7. No single weight satisfies both: the one-example specialist fails on the next case.

The idea: Pre-training repeats the loop over millions of varied examples, served in batches. Pulled in turn toward 0.5 and toward 0.7, w settles near a compromise (≈ 0.54) that lowers the average error — no example is perfect, all are approximated.

Why / at what price: That compromise is exactly what generalizes: it captures the shared pattern, not one isolated case. The price: the average leans toward the majority. If 99% of examples say one thing and 1% another, the final weight nearly ignores the minority — corpus composition decides.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

6. Training ≠ conversation

The problem: You correct the assistant in chat and its next answer improves… then a fresh conversation repeats the same mistake. If it “learns”, why did it forget? Confusing the two regimes makes people expect from chat what only training can do.

The idea: They are two distinct regimes. During training, w changes: 0.4 → 0.42. During a conversation, w is frozen; only the contents of the context window vary. Your correction lives in the context, not in the weights.

Why / at what price: A useful image: context is a sticky note, weights are the engraving. The sticky note vanishes with the window; re-engraving requires a costly, controlled retraining run. The freeze is a design choice — it protects the model from every single conversation — not a malfunction.

Understanding check

Name the input, transformed state, output, and one required assumption. Then compare your chain with the explanation above.

Complete worked case

With weight 0.4, input 2, and target 1: prediction 0.8, error 0.2. With learning rate 0.1, the weight increases slightly. The lab shows the new prediction moving closer to 1.

Reading method: write the data, state every object shape, perform one transformation, and interpret the result before continuing.

Validity boundary

This one-weight loop is a teaching model. Real models have many parameters, gradients, and optimizers.

Evidence status: Established mechanisms; numerical simplifications are pedagogical.

Quick checks

1. What does An example and a target?

An example replaces the rule with a signal: an input plus the expected answer. For “the sky is…”, the target “blue” explains nothing — it gives a point of comparison. Our toy model keeps only the numbers: input x = 2, target y = 1.

2. What does The prediction?

The model applies whatever its current setting is: p = w × x. With w = 0.4 and x = 2 it proposes p = 0.8. That 0.8 is neither good nor bad in itself: it is the raw material for the comparison with the target 1.

3. What does Measure the error?

The error turns the verdict into a signed number: e = 1 − 0.8 = +0.20, so predict higher. A prediction of 1.3 would give e = −0.30: predict lower. The sign gives the direction, the magnitude gives the size of the move.

4. What does Adjust one parameter?

The update sizes the step with the learning rate: w ← 0.4 + 0.1 × 0.20 = 0.42. The new prediction 0.84 moves toward the target 1 without reaching it: each example pulls the setting a little, none dictates it.

Sources and evidence boundary

Scope: Established mechanisms; numerical simplifications are pedagogical.