17/32
Part 4 of 6 · The ReLU mask, and a worked exampleLearn and do

A worked example

These numbers are small enough to check by hand: two examples, two inputs, two hidden units, two classes, and biases at zero.

The forward pass: example 2 is confidently wrong

x = np.array([[1.0, -1.0], [1.0, 2.0]])
y = np.array([0, 1])
W1 = np.array([[1.0, 1.0], [0.0, -1.0]])
W2 = np.array([[1.0, -1.0], [0.0, 1.0]])

pre = x @ W1
h = np.maximum(pre, 0)
logits = h @ W2
z = logits - logits.max(axis=1, keepdims=True)
log_probs = z - np.log(np.exp(z).sum(axis=1, keepdims=True))
loss = -log_probs[np.arange(2), y].mean()
print(np.exp(log_probs).round(2))
print(round(loss, 2))
Predict

The probabilities come out [0.5, 0.5] and [0.88, 0.12], with labels 0 and 1. About what is the mean loss?

Pick one to see what it prints.
Pick an answer above to see the rest