1z = w1*x1 + w2*x2 + b2a = max(0, z)3y = h1 - 2*h2ReLUsigmoidtanhx1×1Σ b = 0za×1×1×1x2×1Σ b = 0yΣ b = −1za×−2
Teal blocks: hidden neurons (sum z, output a) · rose: the output neuronWires with weight tags: each input is multiplied by its weight on the wayKhaki tokens: values travelling through the networkA tiny neural network that computes XOR. Two inputs feed a hidden layer of two neurons; each neuron adds its weighted inputs and its bias (z), then bends the sum with ReLU (a = max(0, z)). The output neuron adds the hidden values with weights 1 and −2. Value tokens travel the wires and become weight × value as they pass each weight tag. With ReLU all four XOR cases come out right; without it, (0, 0) gives 2. The weights are the XOR solution printed in Goodfellow, Bengio and Courville, Deep Learning (2016), section 6.1. Training from random weights usually finds a different set that also works.

One neuron

  1. A neural network works only with numbers. Ours gets two inputs, x1 and x2, each 0 or 1, and must output XOR (exclusive or): 1 when exactly one input is 1, else 0. First input: x = (1, 0).

A small network

Why activations matter

What happens

;; step 1/10 · inputs
XOR ("exclusive or")
  x1 x2   XOR
   0  0    0
   0  1    1
   1  0    1
   1  1    0
first input: x1 = 1, x2 = 0

The weights are the XOR solution printed in Goodfellow, Bengio and Courville, Deep Learning (2016), section 6.1. Training from random weights usually finds a different set that also works. Without activations, any stack of layers equals a single weighted sum. For XOR that is y = −x1 − x2 + 2 here, which gives 2 for (0, 0) instead of 0.