3.1.2 · D2Neural Network Fundamentals

Visual walkthrough — Multi-layer perceptron architecture

1,672 words8 min readBack to topic

We assume you know nothing but this: a weight is a number that says "how much do I care about this input", and a bias is a number that shifts a decision. Every other symbol is earned below.


Step 1 — What a single neuron actually draws

WHAT. A single perceptron takes two inputs and , multiplies each by a weight, adds a bias, and asks "is the total positive or negative?"

Read left to right: is " scaled by how much it matters", is the same for , and nudges the whole thing up or down. The neuron outputs 1 if , else 0.

WHY. We want the simplest possible decision-maker so we can see its limit clearly. This is it.

PICTURE. Set . That equation is a straight line on the plane. One side of the line is "1", the other side is "0". A single neuron can only draw a straight line.

Figure — Multi-layer perceptron architecture

Step 2 — The problem no line can solve

WHAT. Meet XOR ("exclusive or"). Four points, two classes:

class
0 0 0
0 1 1
1 0 1
1 1 0

The two "1" points sit on opposite corners of a square. The two "0" points sit on the other two opposite corners.

WHY. This is the smallest problem that breaks a single line, so it is the perfect stress test.

PICTURE. Try to draw ANY straight line that puts both orange dots on one side and both blue dots on the other. You physically cannot — the classes interlock diagonally. This is the wall a single neuron hits.

Figure — Multi-layer perceptron architecture

Step 3 — The trick: bend space, don't bend the line

WHAT. Instead of one clever line, use two ordinary lines as helper questions, then a third neuron that combines their answers.

  • Neuron asks: "am I above line A?" → answer
  • Neuron asks: "am I above line B?" → answer

These two neurons are the hidden layer. They don't touch the final answer directly — they build new coordinates.

WHY. Each helper is still just a line (Step 1). But their answers form a new space. If XOR becomes separable in that new space, a single output neuron finishes the job. We are not making the line smarter — we are moving the points to where a line suffices.

PICTURE. Below, line A separates "top-left corner" and line B separates "bottom-right corner". Together they carve the plane into regions.

Figure — Multi-layer perceptron architecture

Step 4 — Concrete weights that work

WHAT. Pick these hidden neurons (using the step function: output 1 if ):

  • fires () whenever at least one input is on (). This is OR.
  • fires () whenever both inputs are on (). This is AND.

WHY. XOR = "at least one, but NOT both" = OR minus AND. So we want the output neuron to say "fire when and ".

PICTURE. Watch the four points land in the new space. Three of the four map to distinct spots; crucially the two "1"-class points collapse to while the two "0"-class points go elsewhere.

Figure — Multi-layer perceptron architecture

Mapping table (the heart of the whole page):

(OR) (AND) class
0,0 0 0 0 0
0,1 1 1 0 1
1,0 1 1 0 1
1,1 2 1 1 0

Step 5 — In the new space, a single line finishes the job

WHAT. In the transformed space, the two class-1 points both sit at , class-0 points sit at and . Now build the output neuron:

  • : reward "at least one input on".
  • : strongly punish "both on" (the overpowers the ).
  • : keeps the all-zero case negative.

WHY. These weights are exactly "OR and not AND". A single line now separates the points — because we already re-shaped them in Step 4.

PICTURE. One clean straight line in space splits the orange point from the two blue points. The wall of Step 2 is gone.

Figure — Multi-layer perceptron architecture

Check all four cases:

output correct?
0,0 0 ✓ (class 0)
1,0 1 ✓ (class 1)
1,1 0 ✓ (class 0)

Every row matches. XOR solved by a 2-neuron hidden layer + 1 output neuron.


Step 6 — Why the bend was essential (the degenerate case)

WHAT. Suppose we delete the non-linearity — the hidden neurons just pass straight through (no step, no activation). Then each hidden output is a linear combo of inputs, and the output is a linear combo of those.

WHY. Two matrices multiplied together are still one matrix. So a "deep" linear network collapses back to Step 1 — a single line. No number of linear layers escapes the XOR wall.

PICTURE. The stacked linear layers fold flat into one line — the same failing line from Step 2. The kink (the step / ReLU / sigmoid) is the only thing that keeps the layers from collapsing.

Figure — Multi-layer perceptron architecture

The one-picture summary

Figure — Multi-layer perceptron architecture

The full journey on one canvas: left — XOR unsolvable by any line; middle — two hidden neurons re-shape the four points into a new space; right — in that new space, one line cleanly separates them. Depth + non-linearity = the ability to reshape space until a line works.

Recall Feynman retelling — explain it to a friend

Imagine four coins on a table: two blue on one diagonal, two orange on the other. Your only tool is a single straight ruler, and you must put both blues on one side, both oranges on the other. Impossible — they interlock. So instead you hire two assistants. Assistant One raises a flag if at least one coin near you is heads-up. Assistant Two raises a flag only if both are. Now you stop looking at the coins — you look only at the two flags. In flag-world, the orange cases all say "flag-1 up, flag-2 down", and the blue cases say something different. Suddenly one ruler separates them perfectly. That's an MLP: the assistants are the hidden layer, their yes/no bends are the activation function, and you with the final ruler are the output neuron. The magic isn't a smarter ruler — it's moving the coins into a room where a plain ruler already works. And the twist: if the assistants only ever add and scale (no yes/no flag, no bend), their room is just the old table rotated — the coins still interlock. The bend is everything.

Recall

A single neuron can only draw what shape? ::: A straight line (a linear decision boundary). Why can't a single perceptron solve XOR? ::: XOR's two classes interlock on opposite corners — no single straight line separates them; XOR is not linearly separable. What does the hidden layer actually do geometrically? ::: It maps the input points into a new coordinate space where the classes become linearly separable. If you remove all activation functions, what does a deep MLP collapse to? ::: A single linear transformation (one matrix), equivalent to one perceptron — still just one line. In the XOR solution, what two logic gates do the hidden neurons compute? ::: OR (, threshold at ) and AND (, threshold at ); XOR = OR minus AND.

Related: 3.1.01-SinglePerceptron-and-Linear-Separability · 3.1.03-Backpropagation-Algorithm · 3.1.04-Activation-Functions · 3.2.01-Gradient-Descent-Optimization · 2.1.05-Feature-Engineering · 4.1.01-Convolutional-Neural-Networks · 3.3.02-Dropout-Regularization