BeginnerCoder

Lesson 11 — A tiny training step

Learning = nudging a number to reduce error

A model has weights — numbers it can adjust. Here the model is pred = w * x. Training means: make a prediction, measure the error (pred − target), then nudge w a little in the direction that shrinks the error. The size of the nudge is the learning rate (lr). The direction comes from the gradient, which for this model is error × x.

weight = weight - rate * miss * inp   # one training step

Why it matters: this one line — repeated millions of times on millions of weights — is how every neural network, including ChatGPT, is trained.

Want it another way?
Task

Write the update line inside the loop. You should see w climb toward 2 (because 2 * 3 = 6).

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.