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

Measure one entry, and it agrees

Nudge W1[1, 0] down and up by 10−610^{-6}:

def loss_at(W1: np.ndarray) -> float:
    """W1: (2, 2). The worked example's mean loss with this W1."""
    logits = np.maximum(x @ W1, 0) @ W2
    z = logits - logits.max(axis=1, keepdims=True)
    return np.mean(np.log(np.exp(z).sum(axis=1)) - z[np.arange(2), y])

down, up = W1.copy(), W1.copy()
down[1, 0] -= 1e-6
up[1, 0] += 1e-6
print(f"{loss_at(down):.9f} {loss_at(up):.9f}")
print(f"{(loss_at(up) - loss_at(down)) / 2e-6:.10f}")
print(f"{(x.T @ dpre)[1, 0]:.10f}")
Predict

Nudge W1[1, 0] by ±1e-6 and divide the change in the loss by 2e-6. How close does it come to backprop's 2.2615941560?

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