Grades 9–12
The Algorithm Behind Modern AI
Three days, one for each step of training: forward, backward, update.
Day 1
Through the hidden layer
How did AI get so good?
Every AI tool you used this week was trained the same way: three steps, repeated billions of times.
Forward pass
Push the inputs through the network to make a prediction.
Back propagation
Measure the error and send it back through the network.
Weight update
Nudge every weight to make the next error smaller.
One step a day. Today: the forward pass.
High School · Grades 9–12
The forward pass
Each node works out a weighted sum, each input times its weight, added together. Then it adds its bias and applies an activation function.
ReLU turns any negative value into zero.
The nodes in the middle are a hidden layer: their values are never in the data, only worked out on the way.
High School · Grades 9–12
Key vocabulary
- Hidden layer
- Nodes between the inputs and the outputs. Their values are worked out, never given.
- Weighted sum
- Each value coming into a node times its connection's weight, added together.
- Bias
- A number added to a node's weighted sum.
- Activation function
- A function applied to a node's value. Here, ReLU: any negative value becomes zero.
- Forward pass
- Working out every node's value, layer by layer, from inputs to outputs.
High School · Grades 9–12
Activity
Forward through the middle
Each node works out a weighted sum: each input times its weight, added together. Predict each middle node, then the output.
High School · Grades 9–12
Activity
A bias and an activation
The middle node's bias, -10, is the $10 you owe a friend. ReLU holds any negative value at zero.
High School · Grades 9–12
Explore
Read a bigger network
Three inputs, four middle nodes, three outputs. Each road has its own path through a middle node.
- Click on connections to find each road's path.
- What do the 0.8 weights mean?
0.8 of green time for each car waiting.
High School · Grades 9–12
Discussion
- Why does the network need a middle layer at all?
- What did the activation function do in the Birthday Book Predictor?
- If a network gives the wrong answer, which numbers would you change?
High School · Grades 9–12
Day 2
Sending the error back
Who is to blame?
Back propagation sends the error back across each weight. A middle node receives the output's error times the weight connecting them.
A node that feeds several outputs adds up what comes back from each.
The input values never receive an error. Why not?
High School · Grades 9–12
Key vocabulary
- Error
- The output value minus the target value.
- Back propagation
- Sending the error back across each weight, so every node knows its share of the mistake.
- Middle error
- The error a middle node receives: each output's error times the weight between them, added up.
High School · Grades 9–12
Activity
Send the error back
The network predicts $20. The musician really collected $23.
error = output - target
The input values never receive an error, because nothing can change them.
High School · Grades 9–12
Activity
Errors that add up
Two outputs, wrappers and bottles, so each middle node collects two errors and adds them up.
| top middle | bottom middle | |
|---|---|---|
| round 1 | ?-399 | ?-199 |
| round 2 | ?399 | ?199 |
Write each one as a sum of products before you type it.
High School · Grades 9–12
Activity
An error that can't get through
The middle nodes measure the hours of sleep over and the hours short, so at most one is above zero. The other is held at zero, played no part, and receives no error.
| hours over | hours short | |
|---|---|---|
| round 1 | ?4 | ?0 |
| round 2 | ?0 | ?3 |
High School · Grades 9–12
Discussion
- Why does the error travel back across the weights?
- Why did one yawn node receive no error?
- What will the network do with all these errors?
High School · Grades 9–12
Day 3
Gradient descent
Gradient descent
Every connection now knows its share of the error. Now the network uses it to change its weights.
The learning rate keeps each step small. Moving every weight a small step against its error is gradient descent.
High School · Grades 9–12
Key vocabulary
- Weight update
- Subtracting input value × error × learning rate from a weight.
- Learning rate
- A small number that sets how big each weight update is.
- Gradient descent
- Training by moving every weight a small step in the direction that makes the error smaller.
- Training data
- The examples a network learns from.
- Testing data
- Examples the network never learned from, used to check whether it really learned.
High School · Grades 9–12
Activity
Update a weight
2 classes take part. The network predicts 3 bags of cans, but the target is 6. The learning rate is 0.02.
High School · Grades 9–12
Activity
Find the learning rate
At a learning rate of 0.2, this network's weights blow up.
- Watch it train at 0.2. What goes wrong?
- Try the other learning rates, and record what each one does.
- Find the one that settles.
What goes wrong above it? And below it?
High School · Grades 9–12
Together
Train, then test
The Harbor Predictor learns swimmers and sailboats from sunshine and wind, through a middle layer.
- Train it in swift mode across all the training days.
- Switch to the testing data, days it has never seen.
- Which answer did it learn better?
The sailboats: off by about 0.7 a testing day, against about 1.1 for the swimmers.
High School · Grades 9–12
Discussion
- Why multiply by the input value in the update rule?
- What happens when the learning rate is too large? Too small?
- Why judge the Harbor Predictor on testing data?
High School · Grades 9–12
Exit ticket
A weight of 4 connects an input of 3 to an output with a target of 10. The learning rate is 0.1.
- What is the output?
- What is the error?
- What is the adjustment?
- What is the new weight?
High School · Grades 9–12
What is an AI model?
A very large set of weights and biases.
Each one found by repeating the forward pass, back propagation and the weight update until the errors are small.
Keep exploring at iinnoo.app
High School · Grades 9–12