Start by clearly defining the network architecture, tensor shapes, and forward pass equations. Then derive the gradients step-by-step using the chain rule, implement them in NumPy, and verify with finite differences. Finally, explain the shape transformations and the role of each gradient.
Pro tip: Emphasize the importance of shape consistency and vectorization; use small random inputs for finite difference checks to avoid numerical issues.
Specify input dimension D, hidden dimension H, and output dimension C. Write down the shapes of all parameters and intermediate tensors.
Implement the forward pass in NumPy: affine (XW1 + b1), ReLU, affine (H1W2 + b2), and softmax. Store intermediate values for backward pass.
Starting from the loss, compute gradients for each layer: dL/dZ2, dL/dW2, dL/db2, dL/dH1, dL/dZ1, dL/dW1, dL/db1. Show the chain rule steps and shape compatibility.
Code the backward pass in NumPy using the derived formulas, ensuring all matrix multiplications and element-wise operations match the shapes.
Use numerical gradient checking: perturb each parameter by epsilon, compute loss, and compare the numerical gradient to the analytical one. Use a small tolerance.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.