How a model learns from examples

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

Applied AI · beginner · Session 11

Mechanism map

ONE EXAMPLE                       THE MODEL
 input  x = 2                      weight w = 0.4
 target y = 1
      │                                 │
      └────────────────┬────────────────┘
                       ▼
               ┌────────────────┐
               │  prediction    │   p = w × x = 0.8
               └───────┬────────┘
                       ▼
               ┌────────────────┐
               │  error         │   e = y − p = 0.2
               └───────┬────────┘
                       ▼
               ┌────────────────┐
               │  update        │   w ← w + 0.1 × e = 0.42
               └───────┬────────┘
                       │
      ┌────────────────┘  repeat over millions of examples
      ▼
 TRAINING: w changes       ‖   CONVERSATION: w is frozen, only context varies

The problem — An example and a target

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 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.

Why / at what price — An example and a target

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.

Check: The target for “the sky is…” is “blue”. Propose a second example with a different target, and say what comparing the two teaches the model that one example alone cannot.

The problem — The prediction

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 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.

Why / at what price — The prediction

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.

Check: With w = 0.4 and x = 2, the prediction is 0.8. Which value of w would give exactly the target 1, and how do you find it without running the loop?

The problem — Measure the error

“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 — 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.

error = target − prediction

Why / at what price — Measure the error

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.

Check: Here e = 1 − 0.8 = 0.20. What would e be if the prediction were 1.3? Give the sign and say which way the weight must then move.

Visual support — Measure the error

prediction axis
0 ─────────── 0.8 ───────────── 1 ───────────── 1.3 ─────▶
               p              target             p′

e = 1 − 0.8 = +0.20   → w must go up
e = 1 − 1.3 = −0.30   → w must go down

rule: the sign of e always points toward the target

The problem — Adjust one parameter

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 — 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.

new weight = old weight + learning rate × error

Why / at what price — Adjust one parameter

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.

Check: With a rate of 0.1, w goes from 0.4 to 0.42. Redo the computation with a rate of 3, then the new prediction. Did the model get better or worse?

The problem — Repeat across many examples

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 — Repeat across many examples

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 — Repeat across many examples

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.

Check: After converging on example A, w = 0.5. Example B has x = 1 and target 0.7. Compute prediction and error with that “perfect” weight: what does the result show?

Visual support — Repeat across many examples

example A (x = 2, y = 1)    wants w = 0.5
example B (x = 1, y = 0.7)  wants w = 0.7

     pull of A                      pull of B
 w = 0.5 ◀─────────  w ≈ 0.54  ─────────▶ w = 0.7
                       │
         error A ≈ 0.08   error B ≈ 0.16

 neither error is zero — but both stay small

The problem — Training ≠ conversation

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 — Training ≠ conversation

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 — Training ≠ conversation

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.

Check: You correct the model in chat and its next answer improves. Did the weight 0.42 change? If not, where does the correction live, and what happens when you open a new conversation?

Visual support — Training ≠ conversation

TRAINING (the factory)            CONVERSATION (the counter)
┌──────────────────────┐          ┌──────────────────────┐
│ examples in bulk     │          │ your message         │
│ w moves: 0.4 → 0.42  │          │ w frozen: 0.42       │
│ cost: GPUs, weeks    │          │ context varies       │
└──────────────────────┘          └──────────────────────┘

 the chat correction lives on the right: it vanishes with
 the window; the engraving on the left is what persists

Worked case — full trace

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.

Data: x = 2, target y = 1. Start: w = 0.4, learning rate = 0.1

step 1  p = 0.4 × 2 = 0.8      e = 1 − 0.8 = 0.20
        w = 0.4 + 0.1 × 0.20 = 0.42
step 2  p = 0.42 × 2 = 0.84    e = 1 − 0.84 = 0.16   ✅ error went down
        w = 0.42 + 0.1 × 0.16 = 0.436
step 3  p = 0.872              e = 0.128             ✅ converging toward w = 0.5

SAME EXAMPLE, RATE = 3 (step too large)
step 1  w = 0.4 + 3 × 0.20 = 1.00   p = 2.00   e = 1 − 2.00 = −1.00
step 2  w = 1.00 + 3 × (−1.00) = −2.00   p = −4.00   e = 5.00
        ❌ error explodes: the step overshoots the good zone every round

SCALE CHECK: every quantity in this toy model is dimensionless.
The step 0.1 × 0.20 = 0.02 moves w by 5% of its own value (0.4 → 0.42),
which is 1% of x, or 2% of the target.

Choosing the learning rate on this example

Rate w after one step (from 0.4) What you observe
0.001 0.4002 Progress nearly invisible: thousands of steps needed
0.1 0.42 Steady error decrease: healthy regime
1.0 0.60 Jumps past 0.5 then back: oscillation
3.0 1.00 Divergence: error grows at every step

Causal lab

Predict → change one variable → run → explain the delta

/interactives/curriculum/training-step.html?lang=en

Common errors

“The model memorizes the right answer once you give it the answer.”

The target is never stored: it only produces the number e = 0.20, which moves w from 0.4 to 0.42. No trace of “blue” enters the model — only a setting moves.

“A bigger step means faster learning.”

The trace contradicts it: at rate 3, w jumps to 1.00 then −2.00 and the error goes from 0.20 to 5.00. Useful speed stops where the step overshoots the target.

Boundary, evidence, and sources

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

Evidence status: Established mechanisms; numerical simplifications are pedagogical.

  • Rumelhart, Hinton & Williams, “Learning representations by back-propagating errors”, Nature (1986).
  • Course source packet supplied by the owner; named-product details remain source-reported until primary verification.

Transfer challenge

Rerun the loop on example B (x = 1, target 0.7) starting from w = 0.42.

  1. Predict the sign of e before any computation.
  2. Take two steps at rate 0.1 and record w after each.
  3. Decide: which rate would you keep to learn A and B together, and which observation would make you roll back?

Synthesis and exit ticket

  • An example and a target
  • The prediction
  • Measure the error
  • Adjust one parameter
  • Repeat across many examples
  • Training ≠ conversation

Ticket: mechanism · trace · observation · boundary · evidence · next experiment

Instructor notes: Frame the problem before naming the mechanism. Collect an initial prediction and retain it for the exit ticket.

Instructor notes: Connect every step to the next with a causal verb. Flag any merely decorative arrow.

Instructor notes: Open with: “write the rule that completes any English sentence”. Sixty seconds is enough to make the rule-catalogue dead end felt; keep one proposed rule to compare with the (x, y) pair on the next beat. Record the room’s opening prediction for the exit ticket.

Instructor notes: Have the room write “what I give” and “what I expect” side by side for three of their own examples. Do not judge quality: the point is that they see the target as data, not an instruction.

Instructor notes: Target answer: an example whose target differs, e.g. “the grass is… → green”. Comparing the two teaches that the output depends on the input, not on one globally favorite word. Frequent miss: changing the sentence but keeping “blue”, which contrasts nothing. Two minutes in pairs, one wrong answer repaired on the board.

Instructor notes: Flash question: “what does a model that knows nothing answer?”. Target answer: anything — but a number. Many will say “nothing”: show that a zero output is still an output, and that only numbers can be corrected. Two minutes at most.

Instructor notes: Have them compute 0.4 × 2 before revealing the result, then ask by show of hands whether 0.8 is “wrong”. Harvest the hesitation: it shows an imperfect prediction is not a failure.

Instructor notes: Answer: w = 0.5, by solving 1 = w × 2. Frequent miss: 0.4 + 0.2 = 0.6 — adding the error to the weight without the rate or x. Close with: here we can solve directly; with millions of weights we cannot, and that is exactly why the loop exists.

Instructor notes: Take a show-of-hands vote: is 0.8 “too high” or “too low”? Voting forces everyone to locate the target before the formula. Keep the tally on the board: the sign errors voted here resurface on the update beat.

Instructor notes: Ask for the sign of the error before its value. Have them test a prediction above the target (1.3) so the negative sign emerges in the room rather than on the slide.

Instructor notes: Answer: e = 1 − 1.3 = −0.30; w must go down. Frequent miss: announcing +0.30 by flipping target − prediction, which would push w up. Have them verify the sign on the visual-support number line before correcting anyone.

Instructor notes: Have them place a third prediction (e.g. 0.95) on the line and state its error without written computation. The line then serves as the referee for every sign error in the session.

Instructor notes: Ask for a number: “how far would you move w?”. Collect three typical values (0.1, 0.5, “straight to the perfect value”) and post them without comment — the rate table two slides ahead will settle the debate.

Instructor notes: Have them run the update by hand three times at rate 0.1, then rerun at 3. The 0.42 / 1.00 contrast must be lived on the board; do not hand them the conclusion.

Instructor notes: Answer: w = 0.4 + 3 × 0.20 = 1.00, then p = 2.00 and e = −1.00: the model got worse. Expected wrong answer: “bigger = faster”. Point back to the rate table: the 3.0 row diverges and the 1.0 row already oscillates. Three minutes, individual computation then comparison.

Instructor notes: Set the trap before the answer: “the model is perfect on A; what will it do on B?”. Let the room predict “it will be good there too” — that is precisely the misconception this beat dismantles. Collect two written predictions.

Instructor notes: Ask how many steps it would take to reach w = 0.5 at rate 0.001. Let the order of magnitude surprise them: it is the best entry point to pre-training corpus scale.

Instructor notes: Answer: p = 0.5 × 1 = 0.5 and e = 0.7 − 0.5 = +0.20 — the weight that is perfect on A is off by 0.20 on B; no single w cancels both errors, hence the compromise w ≈ 0.54. Expected wrong answer: “just keep looping on A”. Callback: this compromise becomes the batch-average loss in intermediate session 11.

Instructor notes: Verify on the board: with w = 0.54, A predicts 1.08 (gap 0.08) and B predicts 0.54 (gap 0.16). Ask why the compromise sits closer to 0.5 than 0.7 — A pulls harder because its x is larger.

Instructor notes: Poll lived experience: who has “corrected” an assistant in chat? Have someone recount the relapse in a fresh conversation before any explanation: the lived anecdote makes the distinction stick. Keep it for the live demo on the next beat.

Instructor notes: Run it live: correct the assistant in a chat, then open a fresh conversation and ask the same question. The observed relapse settles the debate better than any explanation.

Instructor notes: Answer: no, w = 0.42 did not move; the correction lives in the context window and vanishes with it. Frequent miss: “it learned from me”. If the room’s hardware allows, run the live demo — corrected chat, then fresh conversation — before giving the answer.

Instructor notes: Have them sort three events — “the model answers”, “the model is retrained”, “you correct it in chat” — into the right column. The third is the trap: it belongs on the right, not the left.

Instructor notes: Walk line by line. Locate an inconsistency at the first faulty step, not only on the final line.

Instructor notes: Have learners fill the final row before revealing it: that trade-off is what decides in production.

Instructor notes: Retain initial and final values. Do not allow simultaneous changes that make the delta impossible to attribute.

Instructor notes: For each claim, have the group produce the smallest counterexample before giving the correction.

Instructor notes: Separate verifiable mechanism, reported implementation choice, and experimental result. Evidence precision must match claim precision.

Instructor notes: Answers: e = +0.28; w moves to 0.448 then 0.4732. Expected misconception: “the model will reach both 0.5 AND 0.7” — have them observe that every step on B degrades A (callback to the compromise w ≈ 0.54). A reasonable rollback threshold: error on A exceeding 0.2. Eight to ten minutes in pairs, calculators allowed.

Instructor notes: Rebuild the chain without looking at the slides, then fill the ticket in at most six lines. Compare with the opening prediction and name what actually changed.