D5W1 A1 Assignment Exercise 7 " LSTM Backward Pass"

D5W1 A1 Assignment Exercise 7 " LSTM Backward Pass"

I am trying to implement D5W1 A1 Assignment Exercise 7 " LSTM Backward Pass" but got stuck in understanding this part in parameter derivates

Parameter Derivatives

π‘‘π‘Šπ‘“=π‘‘π›ΎβŸ¨π‘‘βŸ©π‘“[π‘Žπ‘π‘Ÿπ‘’π‘£π‘₯𝑑]𝑇(11)(11)dWf=dΞ³f⟨t⟩[aprevxt]Tπ‘‘π‘Šπ‘’=π‘‘π›ΎβŸ¨π‘‘βŸ©π‘’[π‘Žπ‘π‘Ÿπ‘’π‘£π‘₯𝑑]𝑇(12)(12)dWu=dΞ³u⟨t⟩[aprevxt]Tπ‘‘π‘Šπ‘=π‘‘π‘π‘ΛœβŸ¨π‘‘βŸ©[π‘Žπ‘π‘Ÿπ‘’π‘£π‘₯𝑑]𝑇(13)(13)dWc=dpc~⟨t⟩[aprevxt]Tπ‘‘π‘Šπ‘œ=π‘‘π›ΎβŸ¨π‘‘βŸ©π‘œ[π‘Žπ‘π‘Ÿπ‘’π‘£π‘₯𝑑]𝑇(14)

The instruction here appear to ask us to concatenate the matrix a_prev with xt. but they are of different size and once I done that the following numpy error appears.


TypeError Traceback (most recent call last)
in
19 da_next_tmp = np.random.randn(5,10)
20 dc_next_tmp = np.random.randn(5,10)
β€”> 21 gradients_tmp = lstm_cell_backward(da_next_tmp, dc_next_tmp, cache_tmp)
22 print(β€œgradients[β€œdxt”][1][2] =”, gradients_tmp[β€œdxt”][1][2])
23 print(β€œgradients[β€œdxt”].shape =”, gradients_tmp[β€œdxt”].shape)

in lstm_cell_backward(da_next, dc_next, cache)
46 print (a_prev.shape)
47 print (xt.shape)
β€”> 48 concat = np.concatenate(a_prev, xt)
49 print (concat.shape)
50 dWf = np.dot(dft, (np.concatenate(a_prev, xt)).T)

<array_function internals> in concatenate(*args, **kwargs)

TypeError: only integer scalar arrays can be converted to a scalar index

For debugging purpose the shape of a_prev and xt are:

(5, 10)
(3, 10)

My lab ID is pahlbtkn

The 1st parameter of np.concatenate is a sequence of arrays. So, wrap the arrays in a sequence and call it like this:
np.concatenate((arr1, arr2))