All problems
Linear Layer Backward dW
Problem
Gradient of a linear layer with respect to its weight matrix for a single vector input: dW = outer(dout, x), with shape (output_dim, input_dim).
The signature is linear_dw(dout, x). dout is the upstream gradient vector and x is the layer input vector.
Hint
dW[i][j] = dout[i] * x[j]; no summation is needed for a single example.
Test cases
case 1
in: [[1,2],[3,4,5]]
expected: [[3,4,5],[6,8,10]]
case 2
in: [[2],[1,-1]]
expected: [[2,-2]]
case 3
in: [[-1,0.5],[2]]
expected: [[-2],[1]]
case 4
in: [[1],[0]]
expected: [[0]]
Starter codePython
def linear_dw(dout, x):
# Your code here
pass4 test cases · run your code against them in the editor