One neuron
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 neuron multiplies each input by a weight, adds the results and adds a bias b: z = w1·x1 + w2·x2 + b. Neuron h1 has weights 1 and 1 and bias 0, so z = 1·1 + 1·0 + 0 = 1.
Then an activation function bends the sum. The usual one is ReLU, the rectified linear unit: a = max(0, z). It passes positive numbers through and turns negative ones into 0. Here z = 1, so h1 outputs a = 1.
A small network
Neuron h2 reads the same inputs with the same weights, but its bias is −1: z = 1 + 0 − 1 = 0, and ReLU gives 0. Neurons side by side, reading the same inputs, form a layer: here h = (1, 0).
The output neuron weighs the layer's numbers: y = 1·h1 − 2·h2 + 0 = 1 − 0 = 1. It has no ReLU, so it may pass on any number. Exactly one input was 1, so XOR says 1: correct.
Now x = (1, 1). h1: z = 1 + 1 + 0 = 2. h2: z = 1 + 1 − 1 = 1. ReLU passes both unchanged, so y = 2 − 2·1 = 0. XOR of 1 and 1 is 0: correct.
Now x = (0, 0). h2 gets z = 0 + 0 − 1 = −1, and ReLU clips it to 0, so h = (0, 0) and y = 0: correct. (0, 1) works like (1, 0): all four XOR cases are right.
Why activations matter
Take the bend away and h2 passes −1 straight on: y = 0 − 2·(−1) = 2, wrong. Without activations, a sum of weighted sums is just one weighted sum, a straight line, and no straight line separates XOR's 1s from its 0s.
Sigmoid squashes any z into 0 to 1; tanh into −1 to 1. Hidden layers today mostly use ReLU or relatives such as GELU. ReLU is cheap, and its slope is 1 for every positive z, so learning signals do not fade.
We copied these weights from the XOR example in the Deep Learning textbook. A real network starts from random weights and learns them: gradient descent nudges every weight and bias to shrink the loss, and backpropagation works out each one's slope.
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.