Quiz: neural networks

Short questions on neurons, layers, the ReLU bend, softmax and training. Try each on paper first, then open the answer. A layer computes \text{ReLU}(A\mathbf x + \mathbf b) with \text{ReLU}(s) = \max(0, s) on each entry; training steps the weights against the gradient of a loss.


Q1. Compute \text{ReLU}\big((2,\ -3,\ 0,\ 0.5)\big).

Entry by entry: negatives become 0, the rest pass through.

(2,\ 0,\ 0,\ 0.5).


Q2. A colleague stacks ten layers, each a matrix plus a shift, with no ReLU in between. Can this network fit a curved intensity profile better than a single layer?

What is C(A\mathbf x + \mathbf b) + \mathbf d?

No. C(A\mathbf x + \mathbf b) + \mathbf d = (CA)\mathbf x + (C\mathbf b + \mathbf d): one matrix and one shift. However many layers, the result is a straight-line (linear) map. Only the bend between layers allows curves.


Q3. A network with one input x has three ReLU hidden units and one linear output. What does its output look like as a function of x?

Each hidden unit is \max(0, a_k x + b_k).

A continuous, piecewise straight line with at most three bends, one where each unit switches on (x = -b_k/a_k). Between the bends it is straight. More units allow more bends.


Q4. You train with gradient descent and the loss jumps up and down and grows. What is the first thing to change?

What controls the size of each step?

Lower the learning rate \eta. Steps that are too large overshoot the bottom of the valley and land higher on the other side; if each overshoot is larger than the last, the loss grows.


Q5. How many numbers (weights and shifts) does a layer from a 28\times 28 image to 64 hidden units have?

The matrix is 64 \times 784; one shift per hidden unit.

784 \cdot 64 + 64 = 50{,}240.


Q6. Why do neural networks for images need many training images?

Compare the number of weights with the number of examples.

They have very many weights (hundreds of thousands). With few images, many different weight settings fit them equally well, including ones that just memorise the training images and fail on new ones. Many examples (or a penalty, or a smaller network) pin the weights down; checking on images not used for training shows whether it worked.


Q7. A neuron has weights \mathbf w = (1, -1) and bias b = 0. Which points are on its positive side: (2, 1), (1, 2), (3, 3)? What is its decision line?

Compute x_1 - x_2.

(2, 1): +1, positive. (1, 2): -1, negative. (3, 3): 0, exactly on the line. The decision line is the diagonal x_1 = x_2; \mathbf w points to the side below it.


Q8. Why can a single neuron not compute XOR, while a network with two hidden units can?

Draw the four corners of the unit square and their XOR values.

One neuron splits the plane with one straight line, and no line puts (1,0) and (0,1) on one side and (0,0) and (1,1) on the other. Two hidden units give two lines; the output combines them (for example, “between the two lines”), which separates the corners.


Q9. A three-class network outputs the scores (1, 1, 1). What are the softmax probabilities? And for (5, 1, 1)?

p_k = e^{z_k}/\sum_j e^{z_j}.

Equal scores give equal probabilities, (1/3, 1/3, 1/3). For (5, 1, 1): e^4 = 54.6 times larger for the first class, so p = (54.6, 1, 1)/56.6 = (0.965, 0.018, 0.018).


Q10. (math) The neuron \varphi(\mathbf w^\top\mathbf x + b) with \mathbf w = (3, 4), b = -10. How far is its decision line from the origin? What changes if \mathbf w and b are both multiplied by 10?

Distance |b|/\|\mathbf w\|.

\|\mathbf w\| = 5, so the distance is 10/5 = 2. Multiplying both by 10 keeps the line (and the distance); only the steepness of a sigmoid output across the line increases tenfold.