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.

1

Forward pass

Push the inputs through the network to make a prediction.

2

Back propagation

Measure the error and send it back through the network.

3

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.

node = ReLU( x₁ × w₁ + x₂ × w₂ + bias )

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

The Talent Show Predictor Forward Propagation tab ↗

Each node works out a weighted sum: each input times its weight, added together. Predict each middle node, then the output.

top: 2 × 1 + 3 × 2 = ?8
bottom: 2 × 2 + 3 × 1 = ?7
audience: 8 × 5 + 7 × 10 = ?110
1221510 2 acts 3 posters ?8 ?7 ?110 audience

High School · Grades 9–12

Activity

A bias and an activation

The Birthday Book Predictor Forward Propagation tab ↗

The middle node's bias, -10, is the $10 you owe a friend. ReLU holds any negative value at zero.

$5: 5 - 10 = -5 → ?0 books
$30: 30 - 10 = 20 → ?4 books
10.2 30 dollars ?20 bias -10 ?4 books

High School · Grades 9–12

Explore

Read a bigger network

The Traffic Light Decider Sample Networks tab ↗

Three inputs, four middle nodes, three outputs. Each road has its own path through a middle node.

  1. Click on connections to find each road's path.
  2. What do the 0.8 weights mean?

0.8 of green time for each car waiting.

High School · Grades 9–12

Discussion

  1. Why does the network need a middle layer at all?
  2. What did the activation function do in the Birthday Book Predictor?
  3. 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?

error = output value - target value

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 Street Musician Predictor Back Propagation tab ↗

The network predicts $20. The musician really collected $23.

error = output - target

output: 20 - 23 = ?-3
middle: -3 × 0.5 = ?-1.5

The input values never receive an error, because nothing can change them.

10200.5 2 morning hrs 1 evening hrs 40 error -1.5 20 dollarserror -3

High School · Grades 9–12

Activity

Errors that add up

The City Park Predictor Back Propagation tab ↗

Two outputs, wrappers and bottles, so each middle node collects two errors and adds them up.

top middlebottom 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 Yawn Predictor Back Propagation tab ↗

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 overhours short
round 1?4?0
round 2?0?3

High School · Grades 9–12

Discussion

  1. Why does the error travel back across the weights?
  2. Why did one yawn node receive no error?
  3. 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.

adjustment = input value × error × learning rate
new weight = weight - adjustment

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

The Recycling Drive Predictor Weight & Bias Update tab ↗

2 classes take part. The network predicts 3 bags of cans, but the target is 6. The learning rate is 0.02.

output error: 3 - 6 = ?-3
middle errors: -3 × 1 and -3 × 0.5 = ?-3 and -1.5
adjustment = input × error × learning rate = 2 × -3 × 0.02 = ?-0.12
new weight = weight - adjustment = 1 - (-0.12) = ?1.12

High School · Grades 9–12

Activity

Find the learning rate

The Test Score Predictor 02 Weight & Bias Update tab ↗

At a learning rate of 0.2, this network's weights blow up.

  1. Watch it train at 0.2. What goes wrong?
  2. Try the other learning rates, and record what each one does.
  3. 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 Weight & Bias Update tab ↗

The Harbor Predictor learns swimmers and sailboats from sunshine and wind, through a middle layer.

  1. Train it in swift mode across all the training days.
  2. Switch to the testing data, days it has never seen.
  3. 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

  1. Why multiply by the input value in the update rule?
  2. What happens when the learning rate is too large? Too small?
  3. 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.

  1. What is the output?
  2. What is the error?
  3. What is the adjustment?
  4. 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