Before you readExactly one of two switches must be on for a lamp to light. Plot the four switch settings at the corners of a square. Can a straight line separate the on cases from the off cases?
Watch: But what is a neural network? · 3Blue1Brown · Neural networks, ch. 1
Logistic regression takes a weighted sum z=wTx+b and passes it through a sigmoid. The sigmoid bends the score into a probability, but the 0.5 cutoff is still where z=0: a straight line in two dimensions. It can’t separate the two opposite corners of the switch problem, called exclusive OR (XOR).
A neuron takes a weighted sum with a bias and applies an activation. A hidden neuron often uses a rectified linear unit (ReLU), ReLU(z)=max(0,z): negative inputs become zero; positive inputs pass through. A multilayer perceptron (MLP) feeds the outputs of one layer of neurons into the next.
For XOR, let s=x1+x2. One hidden neuron outputs h1=ReLU(s); the other outputs h2=ReLU(s−1). The output score is z=h1−2h2−21. The first neuron makes the score rise. Past s=1, the second pulls it down twice as fast as the first raises it. So the score is positive at s=1 and negative at s=0 and s=2.
h1=1h2=0z=0.50: lamp on
Try all four switch settings. Only one switch on puts the score above zero, between the two crossings.
Recall
Why can't a sigmoid applied to one weighted sum solve XOR?
A layer is a matrix and an activation
Stack the hidden weight vectors as rows of W. For a column input x, the forward pass is
h=ReLU(Wx+b),p^=σ(vTh+c).
ReLU acts on each entry separately. In XOR, both rows of W are (1,1),b=(0,−1)T,v=(1,−2)T and c=−21. With d inputs and m hidden neurons, W is m×d and h has m entries. The next layer takes those m entries as its input.
Recall
Why not just stack more layers of weighted sums without activations?
Exercise
For the XOR network, take (x1,x2)=(1,1). Find h1,h2 and the output score z, in that order.
Exercise
A layer has a 3×2 weight matrix W. Its activation h=ReLU(Wx+b) feeds a second layer with four neurons. Give four numbers in order: the input length, the bias length, and the number of rows and columns in the second weight matrix.