Classical machine learningML 09
Neural Networks
A neural network is built from many simple units. Each neuron adds up its inputs, each multiplied by a weight, and passes the sum through a simple bend (the activation function). On its own a neuron can only draw a straight boundary, but neurons in later layers combine the outputs of earlier ones, and together they can draw almost any shape. Training adjusts every weight by gradient descent, with the gradients computed layer by layer backwards from the output (backpropagation). Pick a dataset, press play and watch the boundary form; hover over a neuron to see what it responds to.
Training
Loss by epoch
every square is a neuron, painted with its activation at each point of the plane: aqua high, orange low · filled: training points · hollow: test points (one in three) · while training runs, the pictures ease smoothly instead of redrawing every update, to avoid flicker · an epoch is one pass through the training points, in mini-batches of 10
What the neurons learn
Each neuron in the first hidden layer splits the plane along one straight line, soft-edged by its activation function: hover over them to see. The next layer combines these half-planes into corners, bands and patches, and the output combines those into the final boundary. Two neurons cannot surround a circle; three or four can. The checkerboard needs neurons that pick out the diagonals, and the spiral needs several layers or extra inputs. Adding x², y² or xy as inputs hands the network curved features ready-made: with x² and y² a circle can be separated by a single output neuron with no hidden layer at all.
Training and its pitfalls
A training run that starts from different random weights can end somewhere different: if the loss stops falling at a poor value, press reset to try new starting weights. Too high a learning rate makes the loss jump about; too low and nothing seems to happen. With noisy data and a large network, the training loss keeps falling while the test loss starts to rise as the network bends its boundary around individual noisy points: overfitting, as in the regression demo. The L2 penalty (weight decay) discourages large weights and so keeps the boundary smoother. ReLU, max(0, z), and smooth variants of it such as GELU are the usual choices in modern networks because they train quickly in deep stacks; tanh and the sigmoid were the classic choices.
From perceptrons to deep learning
Rosenblatt’s perceptron (1958) was a single layer of trainable weights. Multilayer networks were known to be more powerful, but there was no practical way to train their hidden layers until backpropagation was popularised by Rumelhart, Hinton and Williams (1986). Cybenko (1989) proved that one hidden layer with enough neurons can approximate any continuous function (on a bounded region, with sigmoid-type activations), although “enough” may be very many; for some functions, deeper networks can need far fewer neurons. Today’s deep networks for images, speech and language are much larger, and many have a different overall design, but they are built from the same parts: weighted sums, activations and training by backpropagation. The layout of this demo follows the TensorFlow Playground (Smilkov et al., 2017).
References
- Rosenblatt, F. (1958). The perceptron: a probabilistic model for information storage and organization in the brain. Psychological Review, 65(6), 386–408. doi.org/10.1037/h0042519
- Rumelhart, D. E., Hinton, G. E., & Williams, R. J. (1986). Learning representations by back-propagating errors. Nature, 323, 533–536. doi.org/10.1038/323533a0
- Cybenko, G. (1989). Approximation by superpositions of a sigmoidal function. Mathematics of Control, Signals and Systems, 2(4), 303–314. doi.org/10.1007/BF02551274
- Kingma, D. P., & Ba, J. (2015). Adam: a method for stochastic optimization. ICLR 2015. arxiv.org/abs/1412.6980
- Smilkov, D., Carter, S., Sculley, D., Viégas, F. B., & Wattenberg, M. (2017). Direct-manipulation visualization of deep networks. arxiv.org/abs/1708.03788 · playground.tensorflow.org