Module 3 · Lesson 1 18 min read Both tracks

What a neuron actually computes

Strip away the biology metaphors and the diagrams with glowing circles. An artificial neuron is one multiplication, one addition, and one squash. That is the entire thing. Everything else in deep learning is that operation, repeated.

What you'll be able to do

By the end of this lesson you will be able to compute a neuron's output by hand, explain what its weights and bias mean geometrically, draw the line it separates data with, and say precisely why a single neuron can never learn XOR.

The one equation

A neuron takes some numbers in and produces one number out. Here is the whole computation, for a neuron with two inputs:

y = f( w₁·x₁ + w₂·x₂ + b )

Four ingredients, and every one of them has a plain meaning:

The part inside the brackets, w₁x₁ + w₂x₂ + b, is called the weighted sum or pre-activation, usually written z. It is a dot product plus a constant, nothing more.

A worked example you should do by hand

Suppose we are building a neuron that decides whether to recommend a film. Two inputs:

Say the neuron has learned w₁ = 4.0 (rating matters a lot), w₂ = −1.5 (long films are a mild negative), and b = −2.0 (start out sceptical). Now a film rated 8.5/10 that runs three and a half hours:

z = 4.0 × 0.85 + (−1.5) × 1 + (−2.0) = 3.4 − 1.5 − 2.0 = −0.1

Pass that through a sigmoid activation, f(z) = 1 / (1 + e^−z), and you get 0.475. The neuron says: 47.5% — a marginal no. Shorten the film to under three hours (x₂ = 0) and z becomes 1.4, giving 0.80. A confident yes.

Notice what just happened

Nobody wrote a rule saying "long films are worse". That −1.5 was learned from data. The entire job of training is finding good values for w₁, w₂ and b. The equation never changes.

Lab: draw the boundary yourself

Here is the geometric truth that most explanations skip. Because z is a linear function of the inputs, the set of points where z = 0 — where the neuron is exactly undecided — is a straight line. Everything on one side gets classified as "yes", everything on the other as "no".

Move the sliders below. The line is the neuron's decision boundary. Try to separate the orange dots from the blue ones.

Perceptron decision boundary interactive
Accuracy
Correct
Boundary

Shaded background = what the neuron predicts everywhere in the plane. Dots outlined in red are currently misclassified.

Three things the lab should have shown you

1. The weights control the angle of the line. The vector (w₁, w₂) points perpendicular to the boundary, in the direction of "more yes". Double both weights and the line does not move at all — only the sharpness of the transition changes.

2. The bias slides the line without rotating it. That is its only job. Without a bias term, the boundary would be forced through the origin, and a huge number of problems would become unsolvable for no good reason.

3. XOR cannot be done. Select the XOR dataset and try every combination you like. You will not exceed 75% accuracy. The four points are arranged so that no single straight line separates them — and a single neuron only ever gives you one straight line.

The 1969 problem

Minsky and Papert published exactly this observation about the perceptron, and AI funding collapsed for over a decade. The fix turned out to be almost embarrassingly simple: use two layers. A hidden layer bends the space so that a straight line in the new space is a curved boundary in the original one. What was missing in 1969 was not the idea of layers — it was a practical way to train them, which arrived with backpropagation in 1986.

Why the activation function is not optional

Here is a proof you can follow in three lines. Suppose we drop f and stack two layers:

layer 1: h = W₁x + b₁   |   layer 2: y = W₂h + b₂

Substitute the first into the second:

y = W₂(W₁x + b₁) + b₂ = (W₂W₁)x + (W₂b₁ + b₂)

Let W* = W₂W₁ and b* = W₂b₁ + b₂. You are left with y = W*x + b* — a single linear layer. A hundred stacked linear layers collapse into one. The depth buys you literally nothing.

Insert any non-linear f between the layers and that collapse becomes impossible. That is the entire reason activation functions exist. They are not a biological flourish; they are what makes depth mean something.

The code

Twenty lines, no framework. Open the playground and run it.

# A single neuron, from scratch
import numpy as np

def sigmoid(z):
    return 1 / (1 + np.exp(-z))

def neuron(x, w, b):
    z = np.dot(w, x) + b       # weighted sum
    return sigmoid(z)          # squash to (0, 1)

# the film-recommender from earlier
w = np.array([4.0, -1.5])
b = -2.0

for rating, is_long in [(0.85, 1), (0.85, 0), (0.40, 0)]:
    x = np.array([rating, is_long])
    p = neuron(x, w, b)
    print(f"rating={rating}, long={is_long} -> {p:.3f}")

# rating=0.85, long=1 -> 0.475
# rating=0.85, long=0 -> 0.802
# rating=0.4,  long=0 -> 0.401

Check yourself

  1. A neuron has w = [2, −1] and b = 0.5. What is z for the input x = [1, 3]? What does the sigmoid of that come to, roughly? (z = −0.5; σ ≈ 0.38)
  2. If you multiply every weight and the bias by 10, does the decision boundary move? Does anything change at all? (The line stays put; predictions become far more confident — the transition from 0 to 1 gets much sharper.)
  3. Why can a neuron with a bias of 0 never classify the point (0, 0) as "yes" with confidence above 0.5? (Because z = 0 there, and σ(0) = 0.5 exactly.)
  4. Sketch, on paper, a two-neuron hidden layer that solves XOR. Hint: one neuron learns OR, the other learns NAND, and the output neuron learns AND.

Where this goes next

You now understand a single unit. The next lesson stacks them into layers and shows what the forward pass looks like as matrix multiplication. After that comes backpropagation — the algorithm that finds good weights automatically instead of you dragging sliders.