Applied AI · beginner · Session 11
Exercises with solutions — How a model learns from examples
← Back to courseFrançaisMarkdown source

Exercises with solutions — How a model learns from examples

General instruction: every answer must show data, transformation, result, one check, and one limitation. A bare number or copied definition is insufficient.

Starting data: 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.

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

Exercise 1 — Calculated trace — An example and a target

Reproduce and annotate the chain error = target − prediction. Replace input 2 with 2.4 while keeping weight 0.4 and target 1. Predict whether error increases or decreases, then recompute prediction and error before any update.

Deliverable: a data → operation → result → interpretation table, plus two sentences about the changed value.

Worked solution

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.

Solved variant: Prediction becomes 0.4×2.4=0.96 and target-minus-prediction error falls from 0.20 to 0.04. The update keeps the same direction but should be smaller because the model is already closer to 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. 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. The minimum check covers dimensions, sign, and order of magnitude. If the observed change contradicts the prediction, locate the first operation whose direction changes instead of fixing only the final line.

Rubric Exercise 1 — /10

Criterion Points
Explicit data and shapes 2
Traceable calculation 3
Prediction before variation 2
Interpretation and check 2
Named limitation 1

Exercise 2 — Diagnose a seductive explanation — Measure the error

A colleague claims: « Measure the error proves the system will be accurate, fast, and stable in every context. »

  1. Separate mechanism, assumption, observation, and conclusion.
  2. Name two correct lesson elements and two unsupported extrapolations.
  3. Propose a bounded experiment with controlled variable, metric, and stop threshold.
  4. Rewrite the claim as one defensible sentence.
Reasoned solution

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. 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. This one-weight loop is a teaching model. Real models have many parameters, gradients, and optimizers.

The claim mixes a local relation with a global guarantee. A defensible version states only the observed mechanism, test conditions, and measured metric. Stop the test if shapes become invalid, the metric crosses the declared degradation threshold, or another variable changes.

Rubric Exercise 2 — /10

2 points per element: separation, lesson grounding, extrapolations, protocol, and rewrite.

Exercise 3 — Transfer test between two procedures — Repeat across many examples

You must reproduce the 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.” under two conditions. Option A uses the full chain through “Repeat across many examples.” Option B is a transparent baseline that retains “An example and a target,” calculates the expected output directly, and does not use the compression or adjustment mechanism studied. Build a decision record containing:

Elements of a strong solution

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. 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. Established mechanisms; numerical simplifications are pedagogical.

A strong answer does not make the newer mechanism the default winner. It retains a measurable baseline, sets thresholds before testing, and separates component cost from whole-system behavior. The verdict names what remains uncertain and the next evidence that could change it.

Rubric Exercise 3 — /15

Criterion Points
Framing and baseline 3
Compared causal chains 4
Protocol and metrics 4
Rollback threshold 2
Bounded verdict 2

Extension

Repeat Exercise 3 with a new input and target. Double or halve the adjustable value, predict the direction of change, then state which observation would make you abandon the procedure.

Review before submission

Review the packet as if another group had to reproduce it without speaking to you. Are all starting values or assumptions present? Are shapes or roles stated before operations? Does the prediction truly precede the observation? Is the result translated into behavior rather than left as an isolated number? Did you test a boundary value and identify a stop condition? Does the procedure or architecture choice retain a measurable baseline and a rollback threshold set before the test? Finally, highlight one sentence that states what is established, one that remains a hypothesis, and one measurement that could change your verdict. If any element is missing, the work is not reproducible.

Reference appendix for correction

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

Working formula: error = target − prediction

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

Working formula: new weight = old weight + learning rate × error

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

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

Sources and evidence boundary

Scope: Established mechanisms; numerical simplifications are pedagogical. These references support the session frame; they do not turn a reported product choice into an independently verified result.