Neural network layers: more inputs, more neurons
Why neural networks need non-linear activation functions such as ReLU. Can extra neurons learn a curve that one neuron cannot?
Builds on A neuron that learns.
Last time, one neuron learned to turn cubits into metres.
It worked well. But some problems are harder.
A conversion that does not start at zero
An archaeologist has found a weather report from the United States, full of temperatures in a baffling, archaic unit: degrees Fahrenheit. Nobody is sure how it relates to Celsius. To crack it, the archaeologist matches eight of the tablet’s readings with Celsius ones.
Here they are, and the same neuron from before, ready to learn the conversion. Each Next step sends one reading forward through the neuron and the error back again, then updates the weights. Or press Train.
It cannot. The neuron only multiplies, so when the input is 0 its answer is 0. But 0 °C is 32 °F. Its line is stuck at the bottom left corner.
A second input: the bias
The fix is to give the neuron a second input that is always 1. Its weight, the bias , is added to every answer.
Same neuron, same training loop, two weights to learn:
It finds the rule: about 1.8 times the Celsius temperature, plus 32.
A harder question
Now ten years of Norwich weather. Each dot is the average temperature for one month of one year. It is cold in winter and warm in summer.
The input is the month, and the constant 1, so the neuron can learn a bias.
Train it the same way.
It misses by 4.4 °C, however long you train. A line goes up, or down. The weather does both.
What if we add more neurons?
Put one neuron after another, or several side by side:
Try it. Add neurons and press Train.
Nothing improves. Each neuron only multiplies and adds, and a sum of lines is a line:
That is one weight times , plus one bias. A hundred neurons that only multiply and add are still one neuron.
An activation function
Each neuron needs one more step after the adding. An activation function changes the sum before the neuron passes it on. The simplest is the ReLU: keep a positive number, and turn a negative one into zero.
Now a neuron is not just a line. It switches on in one part of the data and stays off in the rest. Give several neurons different weights and each one learns a different feature of the data. Their sum is the curve.
Same four neurons, now with the activation. Train:
The miss falls from 4.4 °C to about 1.1 °C. What is left is real year-to-year scatter. Tick “Show what each neuron adds” to see each neuron’s contribution: one for the climb into spring, one for the fall in autumn. Try fewer neurons, and more.
Any curve at all
It is not just weather. Pick a curve or draw your own, and press Train.
Other activation functions
The ReLU is not the only choice. These are the popular ones. Pick one, and slide the input to see what it answers.
Why this works
In 1989 George Cybenko proved that a single hidden layer with enough sigmoid neurons can approximate any continuous curve over a bounded range. Leshno and colleagues later showed that, under their theorem’s conditions, the result extends to non-polynomial activations such as ReLU. Minsky and Papert had shown the limits of a single-layer perceptron in Perceptrons (1969). Nair and Hinton studied rectified linear units in restricted Boltzmann machines; AlexNet helped establish ReLU as a practical choice for deep image-classification networks.
Next
A layer is a matrix multiplication followed by an activation. Nearly every layer in this series is that. Next, the input is a picture of 784 numbers, and the weights pile up. That is the problem convolutions solve.
Sources: Minsky and Papert, “Perceptrons” (1969); Cybenko, “Approximation by Superpositions of a Sigmoidal Function” (1989); Leshno et al., “Multilayer Feedforward Networks With a Nonpolynomial Activation Function Can Approximate Any Function” (1993); Nair and Hinton (2010); Krizhevsky, Sutskever and Hinton, “ImageNet Classification with Deep Convolutional Neural Networks” (2012); Kingma and Ba, “Adam” (2014). Temperature data: Open-Meteo, ERA5 reanalysis, Norwich, 2015 to 2024. The best straight line misses by 4.37 °C; with the ReLU, 1 neuron 4.37, 2 neurons 1.37, 4 neurons 1.14, 8 neurons 1.10. The Fahrenheit readings are illustrative, with the true rule 1.8 × °C + 32.