Each evening we note three warning signs: is the air humid, how cloudy is it, is the pressure falling. The next day we note whether it rained. The network learns to turn today's signs into a probability of rain. Sigmoid neurons keep every value between 0 and 1, and a new loss, cross-entropy, scores a probability by how surprised we are.
Green = numbers flowing forward. Red dashed = blame flowing backward. Yellow = being computed now. Every neuron is a sigmoid, so it never fully switches off: instead its derivative h(1 − h) gets small when h is near 0 or 1, which quietly shrinks the blame passing through.
Keyboard: → or space for Next, ← for Back.
Sigmoid instead of ReLU. σ(z) = 1 / (1 + e−z) squashes any number into the range 0 to 1, so the output can be read as a probability. You cannot compute e−z in your head, so use the small table on the right. Its derivative has a lovely shortcut: σ′(z) = σ(z) · (1 − σ(z)), which you can compute from the value you already have.
Cross-entropy instead of squared error. If it rained, the loss is −ln(p); if it stayed dry, −ln(1 − p). In words: the loss is how surprised you are by what happened, given the probability you gave it. Saying 0.5 always costs ln 2 ≈ 0.69. Saying 0.99 for rain and then getting rain costs only 0.01. Saying 0.01 for rain and then getting rain costs 4.6.
The output error signal is just p − y. The derivative of cross-entropy and the derivative of the sigmoid cancel each other almost perfectly, leaving prediction minus truth, exactly what we had in examples 1 and 2. This is why sigmoid outputs and cross-entropy loss are always used together. You never need the loss number itself to do the update.
| z | σ(z) | σ′ = σ(1−σ) | −ln σ(z) |
|---|
σ(−z) = 1 − σ(z). Values rounded to 3 decimals, so a hand result may differ from the page in the last digit. The first training step lands exactly on z = 0.
Start: hidden 1 watches humidity and clouds, hidden 2 watches clouds and pressure, the output adds them and starts a little pessimistic (c = −1). Learning rate η = 1: sigmoid gradients are small, so the steps can be big. Parameters are rounded to 4 decimals after each update.
| # | humid | clouds | falling | rained | p(rain) |
|---|
Eight evenings and what happened next. Hidden rule the network never sees: it rains when the signs add up to 2 or more (partly cloudy counts ½). Training starts on the quiet day so the first step is all table values.
| step | p(rain) | rained | loss | output (v₁, v₂, c) |
|---|
Nothing trained yet. Hidden weights after each step are in the cards above; the log shows the output neuron so you can watch it change.
z₁ = w₁₁·x₁ + w₁₂·x₂ + w₁₃·x₃ + b₁ h₁ = σ(z₁)
z₂ = w₂₁·x₁ + w₂₂·x₂ + w₂₃·x₃ + b₂ h₂ = σ(z₂)
zₒ = v₁·h₁ + v₂·h₂ + c p = σ(zₒ)
L = −ln p if it rained, −ln(1 − p) if dry
δₒ = p − y
∂L/∂v₁ = δₒ·h₁ ∂L/∂v₂ = δₒ·h₂ ∂L/∂c = δₒ
δ₁ = δₒ · v₁ · h₁(1 − h₁)
δ₂ = δₒ · v₂ · h₂(1 − h₂)
∂L/∂w₁ᵢ = δ₁·xᵢ ∂L/∂b₁ = δ₁
∂L/∂w₂ᵢ = δ₂·xᵢ ∂L/∂b₂ = δ₂
every parameter: p ← p − η · ∂L/∂p η = 1