- A neural network stacks linear scores with nonlinear activations.
- A hidden layer can learn features that bend the decision boundary.
- Training uses gradients; backpropagation computes them efficiently.
This lesson follows When a Line Is Not Enough and leads into Backpropagation.
1. A boundary that bends
A logistic classifier draws a straight boundary in its input space. A feature map can bend that boundary, but the map has to be chosen by hand. A neural network takes a different route: it learns the features itself.
Start with a ring of points. The inner class and the outer class cannot be separated by a line. A hidden layer can combine the inputs into new intermediate values, and the final output can use those values to make a curved region.
2. A tiny network
We will use two inputs, three hidden units, and one output. Each hidden unit computes its own weighted sum and applies a nonlinear activation:
The output unit combines the hidden activations with a sigmoid:
The hidden values are not the final answer. They are learned intermediate features. With a tanh activation, each hidden unit responds differently to the same input.
The demo uses a fixed set of weights so the numbers stay readable. The same structure is trained from data in the playground.
3. Why activation matters
If every layer is linear, stacking layers does nothing. Matrix multiplication composes into one matrix:
A nonlinear activation is what prevents the collapse. It lets the hidden layer carve the input space into regions that a single line cannot describe.
Common choices are tanh, sigmoid, and ReLU. The output layer uses a sigmoid here because the task is binary classification; a regression network would usually end with a linear output instead.
A network has two layers but both use the identity activation. How many linear layers does it effectively have?
4. Forward pass by hand
Use x = (1, 1). The hidden weights and biases are:
The hidden scores are (0.5, 0, −1.5). Applying tanh gives(0.462, 0, −0.905).
Worked example: one forward pass
| hidden unit | score z | activation tanh(z) |
|---|---|---|
| 1 | 0.500 | 0.462 |
| 2 | 0.000 | 0.000 |
| 3 | -1.500 | -0.905 |
The output weights are (3, 1, 1) with bias −0.2. The output score is 0.281:
Since p ≈ 0.570 ≥ 0.5, the predicted class is 1. The hidden layer produced the intermediate values; the output layer only combined them.
For input (0, 0), the same weights give hidden scores (−1.5, 0, 0.5), output score −2.453, and p ≈ 0.079 — class 0. One set of weights, two different decisions.
5. Training
The loss is still binary cross-entropy on the output probability. To train, we need the gradient of the loss with respect to every weight and bias. Backpropagation applies the chain rule from the output back through each layer.
The next lesson works through a one-hidden-unit example by hand. The Decision Boundary Playground trains this kind of network live.
The optimizer is still gradient descent: backprop computes the gradients, then the update subtracts a learning-rate multiple of each one.
6. Where it struggles
A network is not automatically better than a simpler model. It needs enough data, a sensible architecture, and a training procedure that does not overfit. A small network can fit a ring; a large one can fit noise.
Training is also more expensive than logistic regression, and the learned hidden features are harder to interpret. “The network learned it” is not an explanation of why a decision was made.
The next question is how to tell whether a flexible model is learning the pattern or memorizing the examples. That is the overfitting and regularization lesson.
Next: Backpropagation · Later: Overfitting, Bias–Variance & Regularization
7. Going deeper
The universal approximation theorem says a network with enough hidden units can approximate a wide class of continuous functions. It does not say that gradient descent will find the right weights, or that the network will generalize. Those are separate questions about optimization and data.
Initialization matters. If every hidden unit starts with identical weights, they stay identical during training; random small weights break the symmetry. Very large initial weights can also push tanh into its flat region, where gradients are tiny.
Depth composes features: early layers can learn simple edges or regions, later layers combine them. That is the intuition behind deep learning, even though the mathematics of why depth helps in practice is still an active area.
The demo has 3 hidden units. The playground uses eight; the number is a design choice, not a law.
8. Practice
What is tanh(0), and what does a hidden unit with score 0 contribute?
Why does a two-layer network with identity activations have the same expressive power as a one-layer linear model?
The demo output is p = 0.570. What class does it predict at a 0.5 threshold, and how confident is that prediction?
9. Resources
The MIT chapter builds networks from single units through backpropagation. The 3Blue1Brown chapter gives the visual tour, and the Crash Course connects the ideas to practice. All three links were opened and checked for this lesson.
Continue the track
Open the playground for this topic
Decision Boundary Playground →Add and drag points, switch between linear, quadratic, and neural models, and watch the boundary and both accuracy scores respond.
The mathematics behind this topic: Linear algebra.