Skip to content
AI360XpertBeta
Core ML

Visual explainer

Multi-Layer Perceptron

Trace two nonlinear hidden features through a complete XOR construction, then distinguish representational capacity from successful training.

A single affine separator cannot fit all four XOR labels.
A single affine separator cannot fit all four XOR labels.

A multi-layer perceptron (MLP) composes weighted sums with nonlinear hidden activations. The hidden representation can make a problem separable that one straight input-space cut cannot solve. Here, filled circles are class 0 and triangles class 1. The synthetic XOR rows are (0, 0): 0, (0, 1): 1, (1, 0): 1 and (1, 1): 0.

The dashed segments join same-class corners. Their crossing midpoint prevents a single affine separator: its midpoint score cannot be negative for one class and nonnegative for the other. The perceptron sequence explains that limit.

Build a Hidden Feature

A hidden ReLU keeps a positive difference and clips a negative one.
A hidden ReLU keeps a positive difference and clips a negative one.

Define d = x₁ − x₂. Our first hidden neuron computes h₁ = max(0, d). When d = −1 it outputs zero; when d = 1 it outputs 1. A second neuron reverses the difference: h₂ = max(0, −d). These are dimensionless constructed features. A ReLU keeps positive inputs unchanged and clips negative inputs; it does not turn every value into a binary label.

Follow the Forward Pass

Two hidden values combine into one XOR score.
Two hidden values combine into one XOR score.

The 2–2–1 network processes input (1, 0). Straight same-row edges have weight +1, and the crossed input-to-hidden edges have weight −1. The bridge and gap mark a crossing without a junction. Both hidden biases are zero. Hidden values become (1, 0), and the two output weights +1 add them to score q = 1, with output bias zero.

The complete chosen construction is:

W=[1−1−11],b=[00],h=ReLU⁡(Wx+b),q=h1+h2.W=\begin{bmatrix}1&-1\\-1&1\end{bmatrix},\quad b=\begin{bmatrix}0\\0\end{bmatrix},\quad h=\operatorname{ReLU}(Wx+b),\quad q=h_1+h_2.

Predict 1 when q > 0.5. This follows the standard feedforward composition of affine maps and elementwise nonlinearities. These weights demonstrate what the network can represent; they were selected analytically, rather than obtained in an experiment.

Remove the Nonlinearity

Removing the hidden ReLUs cancels this network's score to zero.
Removing the hidden ReLUs cancels this network's score to zero.

Without clipping, the two features become d and −d, and their sum is zero for every input. With ReLU they sum to |d|, the mint V. Both curves use the same axes and scale; the horizontal axis is the difference d, rather than either original input alone.

More generally, two affine layers collapse to one:

W2(W1x+b1)+b2=(W2W1)x+(W2b1+b2).W_2(W_1x+b_1)+b_2=(W_2W_1)x+(W_2b_1+b_2).

Adding affine layers can change parameterization, but it does not create a nonlinear input-output function. A ReLU network's nonlinear function can still consist of straight pieces.

Separate the Four Corners

Two hidden features separate all four XOR corners.
Two hidden features separate all four XOR corners.

Return to the original unit square, with every point in its original position. Scores are 0, 1, 1 and 0 in the listed row order. The positive regions satisfy |x₁ − x₂| > 0.5. Their two boundary segments are x₁ − x₂ = −0.5 and x₁ − x₂ = 0.5. The middle band predicts 0; the two opposite triangular regions predict 1. Boundary ties predict 0 under the strict threshold used here.

No generic curved border was sketched around the dots: these segments come directly from the chosen weights. The four-corner fit establishes representability on this fixture, not accuracy on an unknown data distribution.

Count the Width Cost

Adding one hidden unit increases the parameter count from nine to thirteen.
Adding one hidden unit increases the parameter count from nine to thirteen.

Each dot represents one trainable scalar in a generic fully connected network, including biases. With two inputs, m hidden units and one scalar output, the count is 2m input weights + m hidden biases + m output weights + 1 output bias = 4m + 1. Width two gives 9; width three gives 13. The four extra parameters are outlined.

Wider networks provide more hidden features and cost more storage and computation. That does not mean width merely memorizes quirks or that greater depth is always the right default. Choose capacity using the task, optimization behavior and held-out results. The analytically fixed construction above still occupies these nine parameter slots even though some values are zero.

Learn Instead of Choosing

A loss gradient can adjust an output weight toward a training target.
A loss gradient can adjust an output weight toward a training target.

This separate training demonstration freezes the hidden layer and output bias. Change only the first output weight v₁ from its constructed value to 0.5. At input (1, 0), h = (1, 0), so q = v₁. With target 1, squared loss L = ½(q − 1)² has gradient −0.5 with respect to v₁.

At learning rate 0.2, gradient descent gives v₁ = 0.5 − 0.2(−0.5) = 0.6. Loss decreases from 0.125 to 0.08. The two brackets show score distances 0.5 and 0.4 from the target on the same scale. This is one checked update, not evidence that all hidden parameters will find the desired solution. Backpropagation computes gradients when the hidden layers also train.

Try a Fresh Input

A fresh input activates one hidden feature more than the other.
A fresh input activates one hidden feature more than the other.

Restore the chosen output weights (1, 1). For the fresh input (0.8, 0.2), d = 0.6, so h₁ = 0.6, h₂ = 0 and q = 0.6. The bars share one scale, with a ring marking exact zero. The strict 0.5 threshold predicts 1. A true fresh label is not supplied, so this is a prediction check rather than a generalization measurement.

Inspect the Hidden Space

The hidden representation makes XOR separable by a single output cut.
The hidden representation makes XOR separable by a single output cut.

The axes now show h₁ and h₂. Both class-0 inputs map to (0, 0), marked by the double ring. The class-1 inputs map to (0, 1) and (1, 0). In this representation, the single output cut h₁ + h₂ = 0.5 separates the classes. The nonlinear hidden map changed the arrangement; the output layer can remain affine. This is a deliberate change of coordinates, not movement of the original observations.

Where It Breaks

Inactive hidden units make both positive XOR corners fail.
Inactive hidden units make both positive XOR corners fail.

Keep the same weights but set both hidden biases to −2. For inputs in the unit square, d lies between −1 and 1. The two preactivations d − 2 and −d − 2 lie between −3 and −1, entirely below the zero line in the plot. Both hidden outputs are zero, so q = 0 and the two positive corners fail.

The local ReLU derivatives are also zero throughout this input range. With fixed inputs, ordinary data-loss gradients through those gates cannot change their incoming weights or biases. Other parameter changes, upstream changes or additional update terms can alter that situation; the picture does not prove that every network with one inactive unit is permanently stuck. Representational capacity alone does not ensure a useful training trajectory.

The Quick Version

  • One affine separator cannot fit all four XOR labels.
  • Hidden ReLUs keep positive differences and clip negative differences.
  • Two explicit hidden features produce scores zero, one, one, zero.
  • Removing these nonlinearities cancels the output to zero.
  • Exact straight boundary pieces separate the four original corners.
  • Another hidden unit adds four parameters in this architecture.
  • A checked loss gradient changes one output weight.
  • A fresh input follows the same forward computation.
  • Hidden coordinates make the classes linearly separable.
  • Entirely inactive hidden features can block useful loss gradients.