Skip to content

From Neurons to Networks

The perceptron

One artificial neuron, and its limits

Weighted inputs, a bias, a threshold - the smallest unit that can learn to draw one decision line, and the atom every neural network is built from.

Strip a neural network down to a single cell and you get the perceptron: it multiplies each input by a weight, adds them up with a bias, and fires a yes/no depending on whether the total clears a threshold. That's the whole machine. Yet this one tiny unit can learn - nudging its own weights every time it's wrong until it carves the plane into two clean halves. Understand this atom completely and you understand what every layer of every large language model is quietly doing, billions of times over.

The picture to hold in your head

A neuron is a weighted voting booth. Each input casts a vote; the weight says how loudly that vote counts and in which direction (a negative weight votes against). The bias is a standing head start - the booth's baseline lean before any votes arrive. Add it all up, and if the tally clears zero, the neuron says "yes" (fires a 1); otherwise "no" (a 0).

One neuron, in math

Give the neuron two inputs, and . It holds two weights and one bias . First it computes a single number - the weighted sum, or pre-activation - which is just a plus the bias:

Weighted sum, then activation

Then is squashed through an activation function. The original perceptron uses the hardest possible one - a step (Heaviside) threshold that outputs a flat 1 or 0:

Swap that hard step for a smooth -curve and you have exactly the logistic regression unit from last lesson - the perceptron is its sharp-edged ancestor.

A neuron is a line

Here is the geometric heart of it. The neuron flips from "no" to "yes" precisely where crosses zero. The set of all inputs that sit exactly on that knife-edge - where the neuron is perfectly undecided - is

,

and in two dimensions that equation is a straight line (in higher dimensions, a flat hyperplane). The weight vector is the line's normal - it points perpendicular to the line, toward the "yes" side - and the bias slides the line toward or away from the origin. So the three knobs have crisp meanings: rotate the boundary; shifts it. A single neuron can only ever draw one straight cut through the world.

Teaching the line to place itself

The magic is that the neuron doesn't need us to pick good weights - it can find them. Show it a labelled point, let it guess , and if it's wrong, shove the weights a little toward getting that point right. Correct guesses are left untouched. That single sentence is the perceptron learning rule:

The perceptron update (fires only on mistakes)

The error is , , or . When the neuron is right it is , so nothing moves. When it wrongly says "no" to a "yes" point, the error is and the weights step toward that point ; when it wrongly says "yes", they step away. The learning rate (eta) sets how big each nudge is. Repeat over the data and, if a separating line exists, the boundary rotates itself into place - a fact called the perceptron convergence theorem.

Drive it yourself. Drag the three sliders to aim the line by hand, then hit Train to let the rule take over: it hunts for a misclassified point (ringed in amber), nudges the weights toward fixing it, and you watch the line pivot. Press Run to animate the whole descent to zero mistakes. Then switch the data to XOR and try again.

A single neuron carving the plane. Drag the sliders to aim the line, press Train for one nudge, Run to animate the descent, or switch the data to XOR and watch it fail forever.
x₁x₂
class 1 (should be "yes")class 0 (should be "no")decision linepoint being corrected
weight w₁-1
weight w₂-1
bias b0
mistakes12

decision rule: fire 1 when z = -1·x₁ − 1·x₂ + 0 ≥ 0

12 points on the wrong side. Press Run to fix them.

Switch the data to XOR - and watch it fail forever

XOR labels a point "yes" only when its two coordinates disagree in sign, so the yes-points sit in opposite corners (top-left and bottom-right) and the no-points in the other two. No single straight line can put both yes-corners on one side. Hit Run on the XOR set and the line thrashes back and forth, never settling - the mistake count refuses to reach zero. This isn't a bug or a bad learning rate: it's a hard mathematical wall. XOR is not linearly separable, and a lone neuron only ever draws one line.

This exact failure, published in 1969, froze neural-network research for over a decade. The escape was not a cleverer single neuron but more of them: stack a hidden layer of neurons and each one draws its own line, then a second neuron combines their yes/no answers. Two lines can box in a corner; XOR falls instantly. That's the entire reason deep networks need depth and non-linear activations - the subject of Lessons 20 to 21.

import numpy as np

def step(z):
    return 1 if z >= 0 else 0

w = np.array([-1.0, -1.0])         # weights w1, w2 (a deliberately bad start)
b = 0.0                          # bias
eta = 0.15                       # learning rate

for epoch in range(100):             # sweep the data repeatedly
    mistakes = 0
    for x, y in data:              # x = [x1, x2],  y = 0 or 1
        y_hat = step(w @ x + b)     # z = w·x + b, then threshold
        err = y - y_hat            # +1, 0, or -1
        if err != 0:
            w += eta * err * x     # nudge weights toward this point
            b += eta * err         # and shift the bias
            mistakes += 1
    if mistakes == 0:
        break                      # separated - the line is done
The whole learner, in a dozen lines of Python.

Check yourself

What shape is the decision boundary a single two-input neuron can draw?

Why can a lone perceptron never solve the XOR problem?

Recall: state the perceptron learning rule, and say when it changes the weights.

Tie the update equation to the fact that it fires only on mistakes. Try to state it, then check.

Lock it in

  • A perceptron is one cell: weighted sum , then a step threshold fires 1 or 0.
  • is a straight line; rotates it and shifts it.
  • The learning rule moves weights only on mistakes, toward the point it got wrong.
  • One neuron draws one line, so XOR (not linearly separable) needs a hidden layer.

Primary source

Michael Nielsen builds neurons up from perceptrons with unmatched clarity in Neural Networks and Deep Learning (Chapter 1). For the visual intuition of how these units stack into a network, 3Blue1Brown's Neural Networks series is the canonical companion - watch it right after this lesson.

Ask your teacher

Sit with this: the neuron you just trained is the entire building block. Stack millions of them across many layers and you have a deep network - the literal substrate of every LLM, where each "weight" is one of the model's hundreds of billions of parameters. And the XOR failure you watched isn't a footnote - it is precisely why we need depth and non-linear activations (Lessons 20 to 21): one line can't bend, but many neurons composed together can carve any shape at all. Ask me how a second layer turns two lines into an XOR solver, or why a smooth activation (not the hard step) is what makes the whole stack trainable by gradient descent.