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?
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 network thinks each hour of sun brings 200 visitors. The targets say 240.
- Click the weight and change it.
- Step through all four inputs.
- When an output matches its target, the lines turn green.
Middle School Β· Grades 6β8
Activity
A negative weight
The air gets 6 degrees colder for every kilometer you climb, so the weight is -6.
| km climbed | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 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
- What does the sign of a weight tell you?
- What would the mountain network say after 2.5 km?
- 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.
| 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
Weight 0.75, bias 2. Predict each fare before you step to it.
| miles | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 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.
- Where does it cross the y-axis?
- 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.
- Write it as weight Γ input + bias.
- Draw its line on the same grid as the bus.
- Which is cheaper for a short ride? For a long one?
Middle School Β· Grades 6β8
Discussion
- Where on the graph do you see the weight, and where the bias?
- What happens to the line if the bias goes up by $1?
- 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
Weight 1, bias -60, and an activation function that turns any negative value into zero.
No one sells negative ice creams!
At what temperature do sales begin?
Middle School Β· Grades 6β8
Challenge
Set the frost warning
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.
- As the temperature goes up, does the warning go up or down?
- So is the weight positive or negative?
- 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.
Sketch the frost warning's graph. Where is it flat?
Middle School Β· Grades 6β8
Discussion
- Why does the frost warning need a negative weight?
- What does the bias of 4 mean for the frost warning?
- 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.
Positive error
The network guessed too high.
Negative error
The network guessed too low.
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 network guesses 3 cm a day. Watch the error for each plant.
| plant | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| 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 weight is 3 tickets a coin. Predict each error before the network works it out.
| round | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| error | ?4 | ?3 | ?2 | ?6 |
Take turns: one predicts, the other checks.
Middle School Β· Grades 6β8
Activity
Fix it by hand
- Use the errors to choose a better weight for the bean plant.
- Test it on paper against the four plants.
- 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
- If every error is positive, should the weight go up or down?
- Why can't any weight make every bean plant error zero?
- 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
This network updates its own weight after every error. It starts at 0.5 minutes a kilometer.
Record the weight after every delivery. Where does it settle?
Middle School Β· Grades 6β8
Activity
A bias that learns
The Cookie Jar Predictor learns its bias as well as its weight. The bias is the cookies in a fresh jar.
Record the bias every four jars. Which way is it heading?
Middle School Β· Grades 6β8
Activity
Test what it learned
This network learns its weight, from 1 to 1.27.
- Train it on the training data.
- Switch to the testing data: heights it has never seen.
- Do its predictions still hold?
Done early? The Recycling Sorter learns to tell glass from plastic.
Middle School Β· Grades 6β8
Discussion
- Why did the delivery weight never land exactly on 3?
- Why test a network on data it never trained on?
- 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