What happens when a hidden layer has more parameters?
In what a weight matrix actually does, we followed four apples through a network with two hidden neurons. Its weights were chosen by hand so that every coordinate could be calculated exactly. A weight matrix and ReLU produced a representation that the output neuron could separate with a straight line.
That raises another question: what changes if the hidden layer has three neurons, or ten? Does the boundary in the original input space become more complicated? Does having more parameters make the network more likely to find a solution?
We will keep the same four inputs and labels, increase the hidden layer’s width, and train its parameters. The widget lets us compare the resulting decision regions, repeat training from another initialization, and inspect the weights. More neurons allow more bends, but the boundary we get also depends on training.
The same four apples
Each point represents one apple, described by a color score and a softness score . Positive values mean redder or softer than a reference level; negative values mean greener or firmer. The labels are unripe (0) and ripe (1).
| Apple | Color () | Softness () | Label |
|---|---|---|---|
| A | Unripe (0) | ||
| B | Unripe (0) | ||
| C | Ripe (1) | ||
| D | Ripe (1) |
These measurements are invented to create XOR: each class occupies a diagonal of a square. They do not describe a real rule for apple ripeness. No single straight line can put both unripe apples on one side and both ripe apples on the other.
The widget opens with an alternative hand-chosen two-neuron solution whose hidden weights are and . The matrix article uses and ; both choices classify the same four apples correctly. Select 3 or 10 under Hidden neurons to train a new network. Train again changes the random seed; switching widths reuses the current seed. Hand-chosen (2) restores the original solution.
2 → 2 → 1 · Hand-chosen weights
9 parameters: 6 in the hidden layer + 3 in the output layer.
Choose a width to train on the same four apples. Train again changes the random seed; switching widths reuses it. More neurons allow more bends, but do not require them.
Training setup and current weights
One fully connected ReLU hidden layer and one output score. Training updates every weight and bias using all four apples, binary cross-entropy, and Adam: 6,000 steps at learning rate 0.02. Runs that miss an apple are shown too.
W: 2 × 2; b: 2; V: 1 × 2; c: one number. Values below are rounded; the plot uses full precision.
{
"W": [
[
1,
-1
],
[
-1,
1
]
],
"b": [
0,
0
],
"V": [
[
1,
1
]
],
"c": -0.5
}The two white lines are the complete network’s nonlinear boundary in the original input space. The teal band predicts unripe; coral regions outside it predict ripe. In 3D, the blue surface folds along x₁ = x₂.
s(x) = |x₁ − x₂| − 0.50
These fixed, hand-chosen weights compute the difference between the two inputs in both directions. Each apple keeps its original color and softness coordinates; the hidden layer and output neuron together compute this score.
Drag to rotate, or focus the plot and use arrow keys.
4 of 4 correct
All four original inputs are classified correctly: A and B fall inside the diagonal band, and C and D fall outside. A single straight line cannot create this decision region.
| Apple | (x₁, x₂) | Label | Score | Prediction |
|---|---|---|---|---|
| A | (-0.5, -0.5) | 0 | -0.50 | 0 |
| B | (0.5, 0.5) | 0 | -0.50 | 0 |
| C | (-0.5, 0.5) | 1 | 0.50 | 1 |
| D | (0.5, -0.5) | 1 | 0.50 | 1 |
In Top view (2D), the dots remain at their original coordinates. Teal regions predict unripe; coral regions predict ripe. White dashed segments mark score zero. A pink ring marks an apple whose prediction disagrees with its label.
In Angled view (3D), the orange outline encloses the input plane, while the blue surface shows the network’s score above or below each input position. Its intersection with score zero gives the same white boundary. The height scale adjusts to fit larger scores; the axis labels and table retain their actual values. The two horizontal axes are still color and softness, even when the hidden representation has ten coordinates.
Watch the learned representation change during training
The widget above shows the classifier’s output in the original input space. We can also watch the hidden representation itself change as training updates the parameters. We will keep two hidden neurons so that both hidden coordinates can be plotted directly.
Four examples are enough to train our small XOR network. To make the geometry easier to inspect, the widget below uses 100 fixed synthetic samples in four clusters, including the original A, B, C, and D. Inputs with matching signs have label 0; inputs with opposite signs have label 1. The clusters stay away from the axes. These are illustrative labels, not a rule for real apple ripeness.
At each training step , the hidden layer computes
The original samples stay fixed. What changes is the function applied to them: training updates the weights and biases, so the same inputs acquire new hidden coordinates. Unlike an animation between the stages of a forward pass, every state in this replay comes from an actual optimizer update.
Select Play training, or drag the training-step slider to inspect a recorded update. After W + b shows the affine transformation; After ReLU includes the activation. The scales remain fixed throughout each recorded run. The plot shows the hidden layer; the output layer’s weights affect the loss and training accuracy displayed above it.
Recording actual updates: 0 / 1200…
A: input (−0.5000, −0.5000) → h (0.0000, 0.2269)
Every displayed state uses the parameters recorded at that exact training step. Playback skips some steps for speed; the slider can inspect every update. Plot scales stay fixed within each run.
Current learned parameters
Values are rounded here; the plots use full precision. W and b determine the hidden plots. V and c determine the output score used for loss and accuracy.
100 fixed synthetic samples · batches of 20 · Adam · learning rate 0.02 · all nine parameters trained. Loss and accuracy describe these training samples, not held-out data. Different initializations can get stuck; unsuccessful runs are shown too.
Training uses batches of 20 samples and updates all nine parameters with Adam. Different batches can pull the parameters in different directions, so the representation may fluctuate, move smoothly, or change sharply. The motion is not guaranteed to oscillate or to converge to a correct classifier. New initialization records another run on the same fixed dataset; changing the learning rate keeps the initialization seed, allowing a comparison from the same starting weights. Playback speed only changes how quickly recorded steps are shown.
What one extra neuron adds
We use one fully connected hidden layer with ReLU, followed by one output neuron. With hidden neurons, the computation is
A positive score predicts ripe; a zero or negative score predicts unripe. Each hidden neuron has two input weights and one bias. The output neuron has one weight per hidden coordinate, plus its own bias:
| Hidden neurons | Hidden-layer parameters: | Output-layer parameters: | Total: |
|---|---|---|---|
| 2 | 6 | 3 | 9 |
| 3 | 9 | 4 | 13 |
| 10 | 30 | 11 | 41 |
Adding one hidden neuron adds four parameters to this network: two weights and a bias in the hidden layer, plus a weight connecting that neuron to the output. The hidden representation gains one coordinate. The input still has two measurements, and the output still has one score.
Changing width in the widget builds a new network and trains all its parameters from scratch. It does not keep the original two neurons fixed and append extra ones. Reusing a seed makes a run reproducible for a given width; differently shaped networks still start with different parameter arrays.
Why the boundary can bend
Our original two-neuron solution computes
followed by
Its boundary is the pair of lines . The middle band predicts unripe; both outer regions predict ripe. There are three regions but only two classes. A class can occupy disconnected parts of the input plane.
For a wider layer, the output score has the same general form, with more terms:
Each hidden neuron switches between zero and an affine expression at its activation line . Within a region where the same neurons are active, the score is affine. Crossing an activation line can change its slope.
That is why a ReLU network’s decision boundary is made of straight pieces that can meet at bends. Additional neurons provide additional places where the slope can change. Some neurons may stay inactive, have no effect through their output weight, or contribute changes that cancel, so an extra neuron need not create a visible bend. An activation line is also not automatically a class boundary: the white segments show where the combined output score is zero.
More parameters allow a more complicated boundary; they do not require one. A wider network can even reproduce the smaller network exactly by setting the extra output weights to zero. Training chooses a particular function from the ones the architecture can represent.
Compare widths, then compare initializations
Try the following sequence:
- Select Hand-chosen (2) and note the two parallel boundaries. This solution already classifies all four apples correctly.
- Select 3, then 10. Both train with seed 1 after that reset. Compare how the boundaries pass between the apples, as well as the number of correct predictions.
- Select Train again several times at one width. Watch how changing the initialization affects the learned boundary.
- Select 2 to train a two-neuron network too. Compare its learned solution with Hand-chosen (2), which has the same architecture.
The widget reports every run, including ones that miss an apple. Representing a solution and finding it through training are different questions. Our hand-chosen construction proves that two hidden neurons are sufficient for these labels. A failed two-neuron run does not disprove that; it shows that this initialization and optimization run did not find such a solution. ReLU units can become inactive on all training examples, and optimization can stall.
Every trained run uses the same four-example batch, binary cross-entropy computed from the scores, and 6,000 Adam updates at learning rate 0.02, with no regularization. The hard classification threshold is used to report predictions, not to calculate gradients. These settings are fixed so that we can explore width and initialization. They are not a claim that this is the best training setup for every width.
The hidden input weights start from a normal distribution with standard deviation 1, hidden biases with standard deviation 0.1, and output weights with standard deviation ; all have mean zero. The output bias starts at zero. Training setup and current weights shows the current parameters and loss. The displayed weights are rounded; the plotted boundaries use full precision.
Four correct predictions do not determine the whole boundary
All four apples can receive the right label under different decision regions. Training provides no labels for the spaces between those points, or for the rest of the displayed plane. A network still has to assign scores there, and different parameter choices can produce different answers.
This is a useful limit of our experiment: four out of four is training accuracy on four examples. It does not tell us which boundary would work better on new apples. A more intricate boundary is not automatically better, and its appearance alone does not establish overfitting. We would need more labeled examples, including data held out from training, to compare generalization.
The changing boundary is the original-space view of a changing representation. The input measurements do not move. Every network computes its own hidden coordinates and then uses them to calculate an output score. With three hidden neurons, the intermediate vector has three entries; with ten, it has ten. All of those computations still define a function of the original two inputs.
The same forward pass at every width
For a batch of four apples, has shape . The only changing dimension is :
The following NumPy function evaluates a network of any of these widths, given its parameters. It computes the forward pass; the widget additionally trains those parameters.
import numpy as np
def forward(X, W, b, V, c):
# X: one apple per row, shape (batch_size, 2).
# W: one weight row per hidden neuron, shape (m, 2).
# Each dot product supplies one hidden coordinate per apple.
Z = X @ W.T + b # (batch_size, m)
H = np.maximum(0.0, Z) # ReLU, coordinate by coordinate
scores = H @ V.T + c # V: (1, m); scores: (batch_size, 1)
predictions = (scores > 0).astype(int)
return H, scores, predictionsFor the arithmetic and geometry behind each of these operations, return to what a weight matrix actually does. For experiments on a larger dataset, our article on network depth and width compares architectures on handwritten digits.
A separate two-neuron training run in NumPy
Before building the width experiment, I trained the same ReLU architecture on these four apples using NumPy. This run used plain gradient descent and a different initialization scheme from the widget’s Adam experiment, so matching seed numbers does not reproduce the same weights or results. It provides another example of what training can find with just two hidden neurons.
I initialized the weights from a normal distribution with mean 0 and standard deviation 1, and both biases at zero. Then I ran 20,000 full-batch gradient descent updates with a learning rate of 0.05, updating , , , and . The loss was binary cross-entropy computed from the output scores, with no regularization. The threshold was used to report predictions, not to calculate gradients.
With NumPy’s default_rng(1) as the random generator, drawing before , the run produced these parameters, rounded for display:
W = np.array([[-3.0998, 3.0998],
[ 3.1660, -3.1659]])
b = np.array([-0.00004169, -0.00008875])
V = np.array([[4.3837, 4.2924]])
c = -5.9400Substituting these parameters into the forward pass above gives the following scores and predictions, rounded to three decimal places:
| Apple | Score | Prediction | Correct label |
|---|---|---|---|
| A | Unripe (0) | Unripe (0) | |
| B | Unripe (0) | Unripe (0) | |
| C | Ripe (1) | Ripe (1) | |
| D | Ripe (1) | Ripe (1) |
The numbers look different, but the rows of reveal a familiar computation. The first hidden neuron measures approximately ; the second measures approximately . Training found versions of our two difference features, with their order swapped and their scales changed. After the tiny bias shifts and ReLU, A and B both land at the origin, while C and D land on different positive axes. The output layer combines those hidden coordinates into a score.
There is a useful distinction here: our hand-chosen has exactly rank one, while this learned has rank two and is nearly rank one. Before ReLU, it compresses the square into a very thin parallelogram instead of collapsing it exactly onto a line. Training only needs parameters that reduce the loss; it does not have to reproduce our exact geometric construction.
I repeated the experiment with random seeds 0 through 7. Five of the eight runs classified all four training points correctly after 20,000 updates; the other three classified three correctly. That is the outcome of this small experiment, not a general success rate. Initialization can affect the result, and training need not find our exact matrix—or even the same features. Matching these four labels also does not establish a correct rule for every other point in the plane.