6/32
Part 2 of 6 · Shapes place the transposesLearn and do
The shape rule
A gradient has the shape of its weight, and that places every transpose
Back to the network. Say you have the gradient at the logits, dlogits. It has the shape of logits, (N, K). A random stand-in will do for now.
dlogits = rng.normal(size=(N, K))
dW2 = h.T @ dlogits
dh = dlogits @ W2.T
print(dW2.shape, W2.shape)
print(dh.shape, h.shape)
dW2 = h.T @ dlogits and dh = dlogits @ W2.T. How do their shapes compare with W2's and h's?
Pick one to see what it prints.
Pick an answer above to see the rest
Add up one outer product per example, row n of h times row n of dlogits. Does the sum equal h.T @ dlogits?
Pick one to see what it prints.
Pick an answer above to see the rest