Neural networks.

A neural network is many simple neurons stacked in layers. Each figure here runs a real network in your browser, built from scratch for the book, so you can see what more neurons, a different activation or a different optimizer actually change.

From Chapter 15: Layers and Activations, Chapter 17: Backpropagation and Chapter 18: Optimizers, which explain these figures step by step.

Figure

Enough neurons to separate the crescents

6.44, 0.788.58, 3.774.86, 2.025.97, 1.518.12, 3.148.41, 2.176.52, 1.333.97, 3.497.39, 1.658.49, 4.334.19, 3.943.19, 5.756.9, 1.535.8, 1.15.32, 2.133.68, 5.375.48, 1.654.73, 2.635.79, 1.918.6, 3.354.5, 3.325.71, 1.238.1, 2.98.15, 1.958.93, 3.633.11, 4.278.82, 3.647, 0.94.39, 2.365.08, 1.918.46, 3.547.93, 2.629.35, 4.774.08, 35.76, 2.258.24, 3.543.5, 4.035.9, 1.755.07, 1.927.33, 1.512.89, 4.743.84, 5.864.13, 2.937.17, 1.825.11, 1.868.67, 5.178.88, 3.296.94, 1.647.12, 1.714.06, 4.180.93, 7.695.64, 6.933.2, 9.465.92, 7.853.36, 7.851.51, 6.872.27, 8.863.57, 8.576.6, 5.231.22, 5.393.78, 9.136.86, 5.912.37, 8.391.92, 4.456.43, 3.946.15, 5.815.11, 7.975.26, 8.256.15, 7.590.81, 5.931.17, 4.152.41, 84.68, 8.161.41, 6.535.53, 7.071.09, 5.453.47, 8.025.8, 4.024.11, 8.556.82, 5.854.05, 8.684.96, 7.685.67, 4.963.28, 8.236.65, 64.48, 8.126.91, 5.134.2, 9.52.32, 6.922.29, 8.554.22, 8.314.35, 8.22.73, 8.496.57, 5.031.58, 5.165.94, 6.435.35, 7.814.19, 7.784.08, 8.454.26, 9.16
  • Shaded: called the filled kind
  • Filled and hollow: the two kinds
Hidden neurons
1
Right on the 100 shown
93%
Right on 300 new points
90.7%
1
Shaded areas are classified as the filled kind. The network is 2 inputs → hidden neurons → 2 outputs. Try it: with ReLU on, raise the hidden neurons from 1 to 3 and watch the boundary fold. Then switch the activation off and move the slider again.
Figure

Four activation functions

1.5, 1.5
  • The function
  • Its slope
Input
1.5
Output
1.500
Slope here
1.000
Note
The default for hidden layers.
1.5
The solid line is the function. The dashed line is its slope, which is what training uses. Try it: switch between the four and compare their slopes far from zero. Then look at the step function's slope.
Figure

The same network, five optimizers

0, 00, 0.010, 0.020, 0.030, 0.040.04, 0.030.03, 0.050.04, 0.060.05, 0.070.08, 0.040.09, 0.040.11, 0.020.12, 0.030.1, 0.080.14, -0.020.14, 0.050.15, -0.050.17, -0.010.18, -0.020.19, 0.010.2, -0.030.2, -0.080.16, -0.150.22, -0.060.23, -0.090.22, -0.120.25, -0.070.16, -0.220.04, -0.28-0.03, -0.290.08, -0.290.04, -0.310.02, -0.32-0.08, -0.32-0.03, -0.34-0.1, -0.34-0.16, -0.330.04, -0.37-0.3, -0.24-0.22, -0.32-0.32, -0.25-0.05, -0.41-0.34, -0.25-0.26, -0.35-0.44, -0.07-0.31, -0.33-0.45, -0.12-0.46, 0.1-0.48, 0-0.49, -0.09-0.5, -0.07-0.51, -0.08-0.53, -0.01-0.53, -0.07-0.53, 0.12-0.56, -0.02-0.37, 0.43-0.4, 0.42-0.33, 0.48-0.27, 0.53-0.22, 0.57-0.29, 0.54-0.17, 0.6-0.23, 0.59-0.23, 0.6-0.03, 0.66-0.02, 0.670.32, 0.590.22, 0.650.14, 0.680.29, 0.650.62, 0.360.46, 0.560.35, 0.650.32, 0.670.71, 0.270.67, 0.380.78, 0.040.79, 0.020.79, 0.140.8, 0.140.81, 0.080.82, 0.070.82, 0.190.79, 0.30.84, 0.180.71, -0.50.88, 00.71, -0.530.49, -0.750.31, -0.860.89, -0.210.72, -0.590.46, -0.820.48, -0.82-0.06, -0.960.49, -0.830.46, -0.86-0.16, -0.98-0.36, -0.930, 00.01, -0.010.01, -0.010.02, -0.020.03, -0.020.04, -0.030.03, -0.050.04, -0.060.03, -0.070, -0.090.04, -0.090.05, -0.1-0.02, -0.12-0.07, -0.11-0.07, -0.12-0.01, -0.15-0.04, -0.16-0.07, -0.16-0.06, -0.17-0.15, -0.12-0.18, -0.1-0.12, -0.17-0.15, -0.17-0.21, -0.1-0.24, -0.06-0.25, -0.03-0.23, -0.13-0.26, -0.07-0.28, 0-0.29, -0.02-0.3, 0.06-0.31, 0.02-0.32, 0.06-0.24, 0.23-0.21, 0.27-0.31, 0.17-0.24, 0.27-0.32, 0.2-0.2, 0.32-0.19, 0.35-0.16, 0.37-0.02, 0.41-0.12, 0.41-0.17, 0.4-0.11, 0.43-0.05, 0.450.02, 0.460.04, 0.470.29, 0.390.27, 0.410.17, 0.480.4, 0.330.42, 0.310.33, 0.420.16, 0.520.5, 0.230.56, 0.090.47, 0.330.58, -0.070.59, -0.070.61, 00.61, 0.110.6, -0.160.59, -0.230.63, -0.150.64, -0.160.64, 0.20.67, -0.110.27, -0.630.4, -0.570.47, -0.520.44, -0.560.42, -0.590.29, -0.680.29, -0.69-0.1, -0.75-0.18, -0.75-0.04, -0.780.14, -0.77-0.4, -0.690.09, -0.8-0.46, -0.67-0.47, -0.68-0.69, -0.48-0.37, -0.76-0.77, -0.38-0.62, -0.61-0.6, -0.65-0.72, -0.53-0.85, -0.28-0.89, -0.16-0.83, -0.39-0.83, 0.41-0.93, 0.12-0.94, 0.16-0.91, 0.3-0.92, 0.31-0.93, 0.3-0.89, 0.43-0.99, 0.10, 0-0.01, 0-0.02, -0.01-0.03, 0-0.04, 0.01-0.05, -0.01-0.06, -0.01-0.07, 0-0.07, 0.04-0.03, 0.08-0.1, 0.03-0.11, 0.03-0.06, 0.11-0.12, 0.05-0.04, 0.14-0.1, 0.110.01, 0.160, 0.17-0.02, 0.18-0.03, 0.19-0.05, 0.20, 0.21-0.07, 0.21-0.03, 0.230.06, 0.23-0.01, 0.250.03, 0.260.15, 0.230, 0.280.18, 0.230.07, 0.290.24, 0.20.24, 0.220.32, 0.080.3, 0.170.35, 0.010.32, 0.170.37, 0.040.37, 0.090.39, -0.080.38, -0.140.4, -0.120.42, -0.060.42, -0.110.44, -0.080.09, -0.450.21, -0.410.42, -0.220.46, -0.160.27, -0.420.26, -0.430.05, -0.510.42, -0.320.03, -0.53-0.08, -0.540.22, -0.510.21, -0.53-0.29, -0.5-0.12, -0.57-0.41, -0.43-0.3, -0.53-0.27, -0.56-0.41, -0.47-0.49, -0.4-0.62, -0.18-0.58, -0.32-0.24, -0.62-0.68, 0.04-0.61, -0.32-0.7, -0.04-0.68, -0.18-0.71, 0.08-0.68, -0.26-0.74, -0.04-0.72, 0.19-0.72, 0.22-0.74, 0.22-0.49, 0.6-0.69, 0.39-0.39, 0.7-0.73, 0.34-0.68, 0.460.03, 0.83-0.45, 0.71-0.09, 0.84-0.21, 0.83-0.22, 0.84-0.44, 0.760.23, 0.86-0.39, 0.810.25, 0.870.22, 0.890.67, 0.650.32, 0.880.71, 0.630.83, 0.470.64, 0.730.34, 0.920.89, 0.430.76, 0.65
  • Class 1, and where the network predicts it
  • Class 2, and where the network predicts it
  • Class 3, and where the network predicts it
Steps
0
Loss
1.173
Right on the 300 shown
32%
Right on 300 new points
34%
A small network learns to tell three spiral arms apart. Each run starts from identical weights. Choosing an optimizer resets the network. Try it: train with plain SGD for a few hundred steps and note how slowly the loss falls. Then choose Adam and train again.

Learn the ideas behind it

More playgrounds

Search

    The Book of Machine Learning
    Search
    Reading settings
    Text size
    Colours

    Saved in this browser only.

    Keyboard shortcuts
    /
    Search the book
    ← →
    Previous and next chapter
    g
    Glossary
    c
    Table of contents
    e
    Jump to the exercises
    t
    Reading settings
    ?
    Show this list
    Esc
    Close a window or pop-in