Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

What a neural network is

After this lesson: I can say what a neural network is, in words.

40 min lessonNo commands

Reading a crumpled receipt

An expenses app reads photos of receipts. It finds the shop, the date and the total, even on a crumpled receipt in bad light.

Nobody wrote a rule for every font and every crease. There are too many.

The app uses a kind of model built from many small, simple parts. Each part does a little sum. Together they do something no one part could.

By the end of this lesson

Note

I can say what a neural network is, in words.

Key words

WordWhat it means
Neurona small part that adds up weighted inputs and decides
Weighta number saying how much an input matters
Layera row of neurons working side by side
Neural networklayers of neurons, each feeding the next
Deep learningtraining a neural network with many layers

The cells students fill in are left blank in this preview.

A neuron is a small weighted sum

A neuron takes in a few numbers. It multiplies each one by its weight, then adds the results.

If the total is big enough, the neuron switches on. If not, it stays off.

A big weight means "this input matters a lot". A weight of 0 means "ignore this input".

One neuron, worked out

InputValueWeightValue times weight
Angry words found326
Times the customer has rung236
Order value (tens of pounds)515
Total17, which reaches 15, so: send to a person

The cells students fill in are left blank in this preview.

Run one neuron

Code: python
# One neuron deciding: should this support ticket go to a person?
# Inputs: angry words found, times the customer has rung, order value in tens of pounds.
inputs = [3, 2, 5]
weights = [2, 3, 1]   # How much each input matters.
threshold = 15

total = 0
for i in range(len(inputs)):
    total = total + inputs[i] * weights[i]

print("Weighted total:", total)
if total >= threshold:
    print("Send to a person")
else:
    print("The chatbot can answer")

# Change the first weight from 2 to 0, then press Run.
# The neuron now ignores angry words. What does it decide?

A network is layers of neurons

One neuron can only make a simple choice. So we join many.

The first layer takes in the raw numbers, such as the brightness of each dot in a photo. Its answers feed the next layer, and so on. The last layer gives the answer.

Early layers spot simple things, like edges. Later layers combine them into shapes, then letters, then words.

Training nudges the weights

At first the weights are random, so the answers are poor.

In training, the network sees an example and gives an answer. If it is wrong, every weight is nudged a little, so the answer would have been closer. Then the next example.

This repeats millions of times. It needs a lot of examples and powerful chips, which is why deep learning costs real money to train.

A common mistake

Warning

Many people think a neural network thinks like a human brain and understands what it sees. It does not. It is sums and weights, tuned on examples. It can be confidently wrong on anything unlike its training data.

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.