Grades 6–8

Teaching a Network to Learn

This week we open up a neural network, then watch one learn.

Day 1

Positive and negative weights

Where did AI predict for you today?

πŸ—ΊοΈ

Maps

Your arrival time.

πŸ“Ί

Videos

The next video to watch.

πŸ’¬

Texting

The rest of your sentence.

Each of these comes from a neural network. Let's find out what is at its core.

Middle School Β· Grades 6–8

Let's make a prediction

A zoo gets about 240 visitors for every hour of sunshine. How many on a day with 3 hours?

3 Γ— 240 = ?720

The 240 is the network's weight.

Middle School Β· Grades 6–8

Key vocabulary

Neural network
A kind of AI that makes predictions by passing numbers along connections, multiplying and adding them.
Input value
The number that goes into the network, such as the hours of sunshine.
Weight
The number on a connection. The input is multiplied by it.
Output value
The number that comes out: the network's prediction.
Target output
The real answer. The output should match it.

Middle School Β· Grades 6–8

Activity

Change the weight

The Zoo Visitors Predictor 02 Forward Propagation tab β†—

The network thinks each hour of sun brings 200 visitors. The targets say 240.

  1. Click the weight and change it.
  2. Step through all four inputs.
  3. When an output matches its target, the lines turn green.

Middle School Β· Grades 6–8

Activity

A negative weight

The Mountain Climb Calculator Forward Propagation tab β†—

The air gets 6 degrees colder for every kilometer you climb, so the weight is -6.

km climbed1234
change in degrees?-6?-12?-18?-24

What weight would you use for something that gets warmer as you climb?

Middle School Β· Grades 6–8

Make a table

For each network, list the inputs in one column and the outputs in the other.

Describe each pattern in words.

The zoo goes up by 240 each row. The mountain goes down by 6.

Middle School Β· Grades 6–8

Discussion

  1. What does the sign of a weight tell you?
  2. What would the mountain network say after 2.5 km?
  3. What would a weight of 0 mean?

Middle School Β· Grades 6–8

Day 2

The bias is the starting value

Ride the bus

A bus costs $2.00 to board and $0.75 for each mile. A weight alone can't do it: the $2.00 is paid whatever the distance.

0.75 Γ— 4 + 2 = ?$5.00
fare =0.75Γ—4 miles+2
y =mΓ—x+b
output =weightΓ—input+bias

Middle School Β· Grades 6–8

Key vocabulary

Bias
A number added after multiplying, like the starting value b.
Slope
How much the output changes for each unit of input. In a network, the weight.
y-intercept
The output when the input is zero. In a network, the bias.

Middle School Β· Grades 6–8

Activity

Add a bias

The Bus Fare Calculator 01 Forward Propagation tab β†—

Weight 0.75, bias 2. Predict each fare before you step to it.

miles1234
fare?$2.75?$3.50?$4.25?$5.00

What would a 0-mile ride cost? Why?

$2.00, the bias: the starting value.

Middle School Β· Grades 6–8

Activity

Graph the network

Plot the four fares: miles on the x-axis, dollars on the y-axis. Draw the line through them.

  1. Where does it cross the y-axis?
  2. How much does it rise for each mile?

$2.00, the bias, and $0.75, the weight.

Middle School Β· Grades 6–8

Activity

Design a fare

Invent a fare of your own, a taxi or a bike rental, with a starting price and a price per mile.

  1. Write it as weight Γ— input + bias.
  2. Draw its line on the same grid as the bus.
  3. Which is cheaper for a short ride? For a long one?

Middle School Β· Grades 6–8

Discussion

  1. Where on the graph do you see the weight, and where the bias?
  2. What happens to the line if the bias goes up by $1?
  3. Where do two fares' lines cross, and what does that mean?

Middle School Β· Grades 6–8

Day 3

Making a decision

Nobody sells negative ice creams

On a freezing day, weight Γ— input + bias can give a negative number of ice creams.

An activation function fixes that: after the weight and the bias, it turns any negative value into zero.

Now a network can make a decision: switch an output off until something is true.

Middle School Β· Grades 6–8

Key vocabulary

Activation function
A rule applied to a node's value. Here, it turns any negative value into zero.
Node
A circle in the network that holds a value. Each output is a node.
Threshold
The input where an output switches on, such as the temperature where sales begin.

Middle School Β· Grades 6–8

Activity

Hold it at zero

The Ice Cream Sales Predictor Forward Propagation tab β†—

Weight 1, bias -60, and an activation function that turns any negative value into zero.

70 degrees: 1 Γ— 70 - 60 = 10 ice creams
50 degrees: 1 Γ— 50 - 60 = ?-10 β†’ 0

No one sells negative ice creams!

At what temperature do sales begin?

Middle School Β· Grades 6–8

Challenge

Set the frost warning

The Frost Warning Detector Forward Propagation tab β†—

This time, you set both the weight and the bias. The warning should grow as it gets colder, and switch off when it's warm.

  1. As the temperature goes up, does the warning go up or down?
  2. So is the weight positive or negative?
  3. What bias makes the warning switch off at the right temperature?

Middle School Β· Grades 6–8

Test the edge

The frost warning: weight -1, bias 4.

6 degrees: -1 Γ— 6 + 4 = ?-2 β†’ 0
-5 degrees: -1 Γ— -5 + 4 = ?9

Sketch the frost warning's graph. Where is it flat?

Middle School Β· Grades 6–8

Discussion

  1. Why does the frost warning need a negative weight?
  2. What does the bias of 4 mean for the frost warning?
  3. Where else might a network need to switch something off?

Middle School Β· Grades 6–8

Day 4

Measuring the error

How wrong is the network?

Real AI has millions of weights, so it has to find them by itself. First, it measures how wrong it is.

error = output value - target value
+

Positive error

The network guessed too high.

βˆ’

Negative error

The network guessed too low.

The network says 15. The target is 11. Error: ?4

Middle School Β· Grades 6–8

Key vocabulary

Error
The output value minus the target value: how far off the prediction is, and which way.
Positive error
The output is higher than the target: the network guessed too high.
Negative error
The output is lower than the target: the network guessed too low.

Middle School Β· Grades 6–8

Activity

Read the error

The Bean Plant Predictor Back Propagation tab β†—

The network guesses 3 cm a day. Watch the error for each plant.

plant1234
error?1?3?2?4

Every error is positive. What does that say about the weight?

Middle School Β· Grades 6–8

Activity

Predict the error

The Arcade Ticket Predictor Back Propagation tab β†—

The weight is 3 tickets a coin. Predict each error before the network works it out.

round1234
error?4?3?2?6

Take turns: one predicts, the other checks.

Middle School Β· Grades 6–8

Activity

Fix it by hand

  1. Use the errors to choose a better weight for the bean plant.
  2. Test it on paper against the four plants.
  3. Add up the size of each error, ignoring the sign.

The smallest total wins. Can any weight make every error zero?

Middle School Β· Grades 6–8

Discussion

  1. If every error is positive, should the weight go up or down?
  2. Why can't any weight make every bean plant error zero?
  3. Why ignore the sign when adding up the errors?

Middle School Β· Grades 6–8

Day 5

A network that learns

The network does it by itself

Yesterday you used the errors to choose a better weight. Today the network does it by itself.

+

Positive error

Pushes the weight down.

βˆ’

Negative error

Pushes the weight up.

!

Bigger error

Pushes it further.

Middle School Β· Grades 6–8

Key vocabulary

Weight update
Changing a weight after an error, so the next error is smaller.
Learning
Updating the weights and bias, over and over, until the errors are small.
Training data
The inputs and targets the network learns from.
Testing data
Inputs and targets the network never learned from, to check whether it really learned.

Middle School Β· Grades 6–8

Together

Watch it learn

The Delivery Time Predictor 01 Weight & Bias Update tab β†—

This network updates its own weight after every error. It starts at 0.5 minutes a kilometer.

first delivery's error: ?-5.4
new weight: ?2.66
after all 8 deliveries: ?about 3

Record the weight after every delivery. Where does it settle?

Middle School Β· Grades 6–8

Activity

A bias that learns

The Cookie Jar Predictor Weight & Bias Update tab β†—

The Cookie Jar Predictor learns its bias as well as its weight. The bias is the cookies in a fresh jar.

bias at the start: 6
bias after 16 jars: ?about 9.6

Record the bias every four jars. Which way is it heading?

Middle School Β· Grades 6–8

Activity

Test what it learned

The Tree Growth Predictor 02 Sample Networks tab β†—

This network learns its weight, from 1 to 1.27.

  1. Train it on the training data.
  2. Switch to the testing data: heights it has never seen.
  3. Do its predictions still hold?

Done early? The Recycling Sorter learns to tell glass from plastic.

Middle School Β· Grades 6–8

Discussion

  1. Why did the delivery weight never land exactly on 3?
  2. Why test a network on data it never trained on?
  3. What could go wrong if a network learned from bad data?

Middle School Β· Grades 6–8

A neural network learns by…

Write a network for something in your life with a weight and a bias. Draw it, graph it, and invent three targets that don't fit exactly.

Calculate the errors. Which way should the weight and bias be nudged?

Finish the sentence: "A neural network learns by…"

Middle School Β· Grades 6–8