Data scientists say: the clues are inputs, how suspicious each clue is are the weights, and adding up is a weighted sum.
Pip reads an email and looks for clues. Each clue comes with a number: how suspicious it makes Pip. Positive numbers push towards spam. Negative numbers push towards fine. Tick the clues Pip has spotted in this email.
Data scientists call this S-shaped curve the sigmoid, and the squashing step an activation function.
A pile of points can be any size: +0.5, +40, −200. But a confidence has to sit between 0% (certainly fine) and 100% (certainly spam). So Pip squashes the points into that range with an S-shaped curve. The orange dot is this email. Tick and untick clues in step 1 and watch it slide.
- In the middle, Pip is torn, so every new clue makes a big difference.
- At the top and bottom, Pip has made up its mind. Another clue hardly changes anything.
- It never reaches exactly 0% or 100%. A sensible person always leaves a little room for doubt.
For the curious: the maths of the squash
Data scientists call “how steep the curve is here” the derivative of the sigmoid.
Here is the clever bit. Pip asks itself: if one more clue turned up, how much would I change my mind? That depends on where the dot is. On the steep middle: a lot. On the flat ends: hardly at all. The green line shows the steepness at the dot, so it tilts as you tick clues in step 1.
The aha moment
Pip never has to do any extra sums to find out how open-minded it is. The confidence it has just announced already contains everything it needs: multiply it by its own doubt. Computers doing this millions of times a second save an enormous amount of work, and it’s a big reason this kind of squashing curve became so popular.
# add up the clues, squash, then get open-mindedness for free score = 3 * has_prize + 2 * pushy_link - 3 * known_sender confidence = 1 / (1 + math.exp(-score)) openness = confidence * (1 - confidence) # no new maths needed
For the curious: why “confidence × doubt” is exactly right
Data scientists call how wrong Pip was the error (or loss), and sharing out the blame backpropagation.
Pip announces its answer. Then someone tells it the truth. If Pip was wrong, it needs to work out which of its feelings to blame, so it can adjust them. Each clue’s share of the blame comes from three questions, multiplied together.
The clues come from step 1, so change them there. Weights change here, so go back up and see how Pip’s squash and open-mindedness shift.
A team of deciders is a neural network. Each group is a layer. Multiplying blame along the chain is the chain rule.
Real systems have more than one Pip. Pip’s helpers each look for one kind of thing: does this sound pushy? does the sender seem like a stranger? Their opinions go to a boss Pip, who makes the final call. When the boss is wrong, the blame is handed back along the chain.
Think of a restaurant. A customer complains about a bad meal. The manager asks the chef, the chef asks which ingredient let him down, and the ingredient’s supplier gets asked in turn. At every hand-over, the question is the same: how much of this was your doing?
If you were turning a set of gears, a small turn of the first gear becomes a bigger or smaller turn of the last one, depending on every ratio along the way, all multiplied together. Handing blame back works the same way: multiply the “how much did you matter?” numbers link by link.
For the curious: the maths of the chain
Nudging the weights a tiny bit each time is gradient descent. The whole practice session is training.
One round of blame and nudging changes Pip’s feelings only a tiny bit. So Pip does it again and again, over lots of emails where the right answer is known. Below is a brand-new Pip who knows nothing, with 13 example emails. Press Train Pip.
Pip’s feelings about each clue
Nobody told Pip that prizes and pushy links are suspicious, or that mail from people you know is usually fine. It worked that out for itself from the examples, one tiny nudge at a time.