101 puffs

Chapter 2 · Neural networksPuff 6 of 23

One neuron

Every Saturday you decide whether to go for a walk. You check two numbers: the temperature and the chance of rain. Could one tiny piece of arithmetic make that call for you? It can, and that piece of arithmetic is called a neuron. The question is what it can and can’t learn.

Guess first

On a map of every possible day, a neuron marks some days “walk” and the rest “stay in”. What shape can the border between them be?

Play with it

Fig. 1 · One neuron Will we go for a walk?

Tap any day on the map to send its numbers through the neuron. Slide the knobs to move the blue line, or press “Let it learn”.

How it works

Tap a step to see it in the figure.

Check yourself

A neuron gives “chance of rain” a large negative weight. What does that mean?

Go deeper: the mathWeighted sum, sigmoid, and how a neuron learns its weights

The neuron

Call the temperature x1 (in °C) and the chance of rain x2 (in %). The neuron multiplies each by its weight, adds the bias b, and squashes the total z with the sigmoid function σ:

z = w1x1 + w2x2 + b
p = σ(z) = 11 + e−z

Right now the neuron computes z = 0.2 x₁ + 0 x₂ − 4.

Why the border is straight

The answer is exactly 0.5 when z = 0, because σ(0) = 1/(1 + 1) = 0.5. So the border is every day where w1x1 + w2x2 + b = 0, and that is the equation of a straight line. Here it is temperature = 20 °C. With three inputs the border would be a flat plane, and with more it is the same idea in more dimensions. It is never curved.

How it learns

Write y = 1 for days we walked and y = 0 for days we stayed in. A good score for a yes/no answer is the cross-entropy, the average of −log of the probability the neuron gave to what really happened:

L = −1n Σ [ y log p + (1 − y) log(1 − p) ]

Saying 0.9 on a day we walked costs −log 0.9 ≈ 0.11. Saying 0.1 costs −log 0.1 ≈ 2.3, so confident mistakes are punished hard. On this page the loss is now 0.5. Its slopes come out neatly:

∂L∂wj = 1n Σ (p − y) xj
∂L∂b = 1n Σ (p − y)

“Let it learn” nudges every knob against its slope, exactly as in puff 1. One neuron trained this way is called logistic regression. As in puff 1, the page rescales the two inputs to similar sizes while learning (learning rate 1 in those units) and shows the weights in °C and %. Because a straight line can split these sixteen days perfectly, the loss could keep shrinking for ever as the weights grow, so the page stops once every day is right and the loss is below 0.1.

Where the idea came from

In 1943 Warren McCulloch and Walter Pitts described a neuron as a unit that adds up its inputs and fires if the total passes a threshold. In 1958 Frank Rosenblatt’s perceptron learned its weights from examples. It used a hard on/off step instead of the smooth sigmoid; the smooth version is what lets us compute slopes. In 1969 Marvin Minsky and Seymour Papert’s book Perceptrons stressed the catch you just saw: a single unit can only separate things with a straight line.

How much like a brain is it?

Only loosely. A real nerve cell has thousands of connections, sends spikes over time and runs on chemistry that this sum ignores. The artificial neuron borrows one idea, “add up the signals and react if there’s enough”, and nothing more.

Sources

  1. I. Goodfellow, Y. Bengio and A. Courville, Deep Learning, MIT Press, 2016, chapter 6.
  2. F. Rosenblatt, “The perceptron: a probabilistic model for information storage and organization in the brain”, Psychological Review 65(6), 386–408, 1958.
  3. W. S. McCulloch and W. Pitts, “A logical calculus of the ideas immanent in nervous activity”, Bulletin of Mathematical Biophysics 5, 115–133, 1943.
  4. 3Blue1Brown, Neural networks (video lessons).
  5. The sixteen walk days are made up for this page.