Part VIII — Neural Network Fundamentals, Backpropagation & Optimizers · Chapter 2

Multi-Layer Perceptrons (MLP)

Hook

Last chapter's perceptron draws exactly one straight line. Here are four points — (0,0)(0,0) and (1,1)(1,1) in one class, (0,1)(0,1) and (1,0)(1,0) in the other — that no single line can ever separate. Does adding a second perceptron help, or does the problem just double?

Intuition
x10.0x20.0A: z = -0.500.00B: z = 1.501.00
hidden layer: hA = 0, hB = 1
hA0.0hB1.0out: z = -0.500.00
output: y = 0

This is XOR, the classic case no line can separate. Click through all four corners: two small perceptrons — labeled A and B — look at the same (x1,x2)(x_1,x_2) and disagree, feeding their two answers into a third perceptron that combines them. Every corner comes out correct, something neither A nor B could do alone with a single line.

Formalize

Stack perceptrons into a hidden layer, then feed their outputs into another perceptron:

hi=step(wix+bi),y=step(vh+c)h_i = \text{step}(w_i \cdot x + b_i), \qquad y = \text{step}(v \cdot h + c)
  • hih_i — hidden perceptron ii's output, itself a 0/10/1 decision.
  • wi,biw_i, b_i — hidden perceptron ii's own weights and bias.
  • v,cv, c — the output perceptron's weights and bias, applied to the hidden layer's outputs hh instead of the raw input.
  1. Two lines, not one
    • Perceptron A fires like OR(x1,x2)\text{OR}(x_1,x_2): on for every corner except (0,0)(0,0).
    • Perceptron B fires like NAND(x1,x2)\text{NAND}(x_1,x_2): on for every corner except (1,1)(1,1).

    Two different lines, two different opinions.

  2. A third perceptron combines their opinions

    Feed hAh_A and hBh_B into an output perceptron wired like AND(hA,hB)\text{AND}(h_A, h_B): it fires only when both hidden neurons agree the point is "in." That happens at exactly the two corners XOR calls true.

  3. Depth bought a new kind of boundary

    No single one of these three perceptrons can solve XOR. Stacked, they draw a boundary that's the intersection of two lines — a shape one line could never make.

Play
x10.0x20.0A: z = -0.500.00B: z = 1.501.00
hidden layer: hA = 0, hB = 1
hA0.0hB1.0out: z = 1.001.00
output: y = 1

(0,0)→1✗ (0,1)→1✓ (1,0)→1✓ (1,1)→1✗2/4 correct

The hidden layer's weights are fixed at the OR/NAND solution above — only the output perceptron's bias cc is yours to drag. Watch the truth table: most values of cc get 2 of the 4 rows right by accident, since hAh_A and hBh_B already agree on those two corners. Getting all 4 takes finding the exact bias that reproduces AND.

Worked example

Weights fixed at wA=(1,1)w_A=(1,1), bA=0.5b_A=-0.5, wB=(1,1)w_B=(-1,-1), bB=1.5b_B=1.5, v=(1,1)v=(1,1):

  1. Try c = 0 (a plausible-looking guess)
    • At (0,0)(0,0): hA=step(0.5)=0h_A=\text{step}(-0.5)=0, hB=step(1.5)=1h_B=\text{step}(1.5)=1, so zout=0+1+0=1z_{\text{out}}=0+1+0=1 and y=step(1)=1y=\text{step}(1)=1 — but the target is 00. Wrong.
    • At (1,1)(1,1) by symmetry: hA=1h_A=1, hB=0h_B=0, zout=1z_{\text{out}}=1, y=1y=1 against a target of 00.

    Both "same-input" corners fail — c=0c=0 only gets 2 of 4 rows right.

  2. Try c = -1.5 instead

    At (0,0)(0,0): zout=0+11.5=0.5z_{\text{out}} = 0+1-1.5=-0.5, so y=step(0.5)=0y=\text{step}(-0.5)=0 — correct. At (1,1)(1,1): zout=1+01.5=0.5z_{\text{out}}=1+0-1.5=-0.5, y=0y=0 — correct.

  3. Check it didn't break the other two

    At (0,1)(0,1) and (1,0)(1,0): hA=1h_A=1, hB=1h_B=1, so zout=1+11.5=0.5z_{\text{out}}=1+1-1.5=0.5, y=1y=1 — still correct, matching the target of 11 at both.

  4. All four, from one bias

    c=1.5c=-1.5 is the exact bias an AND gate uses on (hA,hB)(h_A,h_B) — fire only when both hidden neurons agree — and that alone solves every row of XOR.

Checkpoint

Drag the output neuron’s bias until the network gets all 4 of 4 XOR rows right.

x10.0x20.0A: z = -0.500.00B: z = 1.501.00
hidden layer: hA = 0, hB = 1
hA0.0hB1.0out: z = 1.001.00
output: y = 1

(0,0)→1✗ (0,1)→1✓ (1,0)→1✓ (1,1)→1✗2/4 correct

Drag the slider to try it
Summary
hi=step(wix+bi),y=step(vh+c)h_i = \text{step}(w_i \cdot x + b_i), \qquad y = \text{step}(v \cdot h + c)

A hidden layer doesn't add a fundamentally new kind of unit — it's perceptrons feeding perceptrons, the exact same building block from last chapter, just composed. That composition is what turns "one straight line" into "the intersection of several," and it's the whole reason depth matters at all. The next chapters ask what happens once these hand-picked weights get replaced with weights a network learns on its own.