Mansori

A Perceptron Learns to Draw a Line

About this lesson, for parents and teachers

Inside every AI is a huge pile of tiny decision makers called neurons. Here is the very first one ever invented, the perceptron. Watch it nudge a line, one mistake at a time, until it gets everything right.

Ages 12–14 · about 9 minutes · builds on AI Guesses by Looking at Neighbours · leads to Gradient Descent: Rolling Downhill to Learn, Inside a Neural Network

Try this

  1. Press Train 1 point a few times. Read the maths: when a point is on the wrong side, the weights change.
  2. Press Auto-train until the mistakes badge says 0.
  3. Drag a point to the wrong side of the line, then train again. Tap empty space to add new points.
  4. Make a checkerboard: purple in two opposite corners, orange in the other two. Can the perceptron ever win?

How it works

A perceptron takes inputs, here a point's x and y, and multiplies each by a weight: z = w1*x + w2*y + b. The b is the bias, which shifts the line. If z is above 0 the perceptron answers 1 (purple), otherwise 0 (orange). Every point where z is exactly 0 forms a straight line, the decision boundary you see on screen.

Learning means changing the weights. The perceptron looks at one point at a time and computes its error: err = label - yhat. If it was right, err is 0 and nothing changes. If it said 0 but the answer was 1, err is 1, so it adds a little of the point to the weights: w1 += lr * err * x. That tilts and slides the line toward getting that point right.

The learning rate lr controls how big each nudge is. Each pass through all the points is called an epoch. In 1962 it was proven that if a straight line can separate the two groups, this simple rule is guaranteed to find one eventually. That is the perceptron convergence theorem.

But one perceptron can only ever draw one straight line. A checkerboard pattern, also called XOR, cannot be split by any straight line, so the perceptron keeps flipping forever. This limit, pointed out in 1969, slowed AI research for years. The fix is to connect many neurons in layers, a neural network, which can draw curved boundaries.

Where engineers use this

Every modern neural network, from photo tagging to chatbots, is built from millions or billions of units that compute a weighted sum plus a bias, just like this perceptron, then pass the result to the next layer.

Words to know

Perceptron
The simplest artificial neuron: a weighted sum of inputs plus a bias, then a yes-or-no decision.
Weight
A number that says how much an input matters. Learning means adjusting the weights.
Bias
An extra number added to the sum that shifts the decision line without tilting it.
Learning rate
How big a step the model takes each time it corrects a mistake.
Linearly separable
When two groups of points can be split perfectly by one straight line.

Talk about it

Goal: Watch the simplest artificial neuron adjust its weights until it separates two groups.

  • Why does the perceptron only change its weights when it makes a mistake?
  • What happened with a very large learning rate compared to a small one?
  • Why can't one straight line split the checkerboard? What shape would you need?

Without a screen: Scatter red and blue buttons on a table and use a ruler as the perceptron's line. Point at one button at a time: if it is on the wrong side, nudge the ruler a little toward it. Count how many nudges it takes. Then arrange a checkerboard and try again.

Curriculum links: CSTA K-12 3B-AP-08 (how artificial intelligence drives software), 2-DA-09 (refine computational models); AI4K12 Big Idea 3 (Learning: computers learn from data); Common Core 8.EE (linear equations)

Questions

What is a perceptron in simple terms?
A perceptron is the simplest artificial neuron. It multiplies its inputs by weights, adds them up with a bias, and says yes if the total is above zero. Learning means adjusting those weights when it gets an answer wrong.

How does a perceptron learn?
It looks at examples one at a time. When it gets one wrong, it adds the learning rate times the error times the input to each weight, which moves its decision line toward the correct answer.

Why can't a perceptron solve XOR?
A single perceptron can only draw one straight line, and XOR's pattern of opposite corners cannot be separated by any straight line. Neural networks with hidden layers combine several lines to solve it.