Grades 9–12

Building a Network That Learns

This week: the full algorithm behind modern AI, ending on a network that predicts the next word.

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.

By Friday, you'll have done all three by hand.

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

Done early?

Draw it

Draw the City Park network on paper.

Label every connection with the error that travels back along it in round 1.

Then check your labels against the app.

High School · Grades 9–12

Discussion

  1. Why does the error travel back across the weights?
  2. Why do the input values never receive an error?
  3. A City Park middle node got a large error from one output and a small one from the other. Which matters more?

High School · Grades 9–12

Day 3

Where the error stops

No error gets through

A middle node that the activation function held at zero played no part in the output, so no error reaches it.

Changing a weight into that node wouldn't change the output: it would still be held at zero.

In calculus terms: ReLU's slope is zero there, and the error is multiplied by that slope.

High School · Grades 9–12

Key vocabulary

ReLU
A negative value becomes zero, and a positive one passes through unchanged.
Inactive node
A node the activation function holds at zero. It receives no error.
Slope
How much a function's output changes for a small change in its input. ReLU's is 0 below zero, 1 above.

High School · Grades 9–12

Activity

One node at a time

The Yawn Predictor Back Propagation tab ↗

The middle nodes measure the hours of sleep over and the hours short. Only the one above zero receives an error.

hours overhours short
round 1: 10 slept, 8 needed?4?0
round 2: 7 slept, 11 needed?0?3

High School · Grades 9–12

Activity

A node that never wakes

The Pet Rescue Predictor Back Propagation tab ↗

The bottom middle node's bias, -20, is more than any day's dogs and cats can make up, so it is held at zero every day.

top middlebottom middle
round 1?-3.5?0
round 2?3.5?0

For each zero, write one sentence saying why that node got no error.

High School · Grades 9–12

Discussion

  1. Why did one yawn node receive no error in each round?
  2. The pet rescue's bottom node never receives an error. What does that mean for its weights?
  3. Why is it useful that only the active nodes get an error?

High School · Grades 9–12

Day 4

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.
Overshoot
Stepping past the best weight, so the error grows instead of shrinking.

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

Watch it settle

The Recycling Drive Predictor Weight & Bias Update tab ↗

Keep stepping through the 8 drives, and note the output error each time.

Why does it never reach zero?

It shrinks to within about 1 bag and stays there: the bags are never exactly 3 a class.

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

Sketch the error

Sketch the error against the weight as a valley. Draw each learning rate as steps down it.

·

Too small

Tiny steps that never reach the bottom.

✓

Just right

Steps that land at the bottom.

↯

Too large

Steps that jump across and climb the other side.

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 is it called gradient descent?

High School · Grades 9–12

Day 5

Training, testing and the next word

Thousands of steps at once

This week you did every step by hand. Today the networks do thousands of steps at once, in swift mode.

A network can fit its training data without learning the pattern, like memorizing answers without understanding them. That's overfitting.

So we judge it on testing data it has never seen.

High School · Grades 9–12

Key vocabulary

Training data
The examples a network learns from.
Testing data
Examples the network never learned from, used to check whether it really learned.
Overfitting
Fitting the training data so closely that the network does worse on new data.
Swift mode
Running the network's steps quickly, without showing each calculation.
Language model
A network that predicts the next word from the words before it.

High School · Grades 9–12

Activity

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

Activity

A deeper network

The Air Quality Monitor Sample Networks tab ↗

Two hidden layers, and 255 steps a round.

  1. Train it in swift mode.
  2. Switch to the testing data.
  3. Did it learn correctly?

High School · Grades 9–12

Together

Predict the next word

The Next Word Predictor Sample Networks tab ↗

A tiny language model that learns from 7 short sentences, like "the dog is cute" and "the sky is blue".

After training, which words does it expect after "is"?

cute, big, blue and hot: the words that followed "is" in its training sentences.

High School · Grades 9–12

Discussion

  1. Why did the Harbor Predictor learn the sailboats better than the swimmers?
  2. The Next Word Predictor only knows 10 words. What would change for a real language model?
  3. The Next Word Predictor only says what it saw in training. What does that mean for real AI?

High School · Grades 9–12

How does an AI model learn?

Draw a network of your own: two inputs, two middle nodes, one output. Choose its weights.

  1. Run one forward pass.
  2. Invent a target and send the error back.
  3. Do one weight update at a learning rate of 0.1.

In a paragraph: how does an AI model learn?

High School · Grades 9–12