Course 5 week 1 - lstm_cell_forward

Hello,
in the function lstm_cell_forward I stuck at the concatenate of a_prev and xt.
The shape of a_prev is (5, 10) and of xt (3, 10).

If I specify the axis to 0, the following error message appears:
ValueError: shapes (5,10) and (5,10) not aligned: 10 (dim 1) != 5 (dim 0)

With axis to 1:
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 5 and the array at index 1 has size 3

any recommendations?
Cheers, Arno

1 Like

You need to concatenate a_prev and xt first, and use the concatenated matrix to calculate the gates. The comment has already given you the hint.

Hi Kic,

thanks for your response. I found the solution. :grinning:

Cheers, Arno

Hi Kic, I am already concatenating a_prev with xt and using the concatenated matrix for gate calculation but still getting error ValueError: shapes (5,10) and (5,10) not aligned: 10 (dim 1) != 5 (dim 0)

I would really appreciate your guidance.

Thank you.

Best,
Ishan

Hi Arno,

Could you please share how you were able to fix this issue.

Thank you for your time.

Best,
Ishan

Hi @IshanDindorkar

It looks like there is a problem with the parameters passed to np.dot() when calculating the gates.
Check that the correct parameters are used.

Hi @Kic,

Thank you for your prompt response. Appreciate it.
I figured out what was the issue. Actually, I was using np.dot to multiple forget gate with c_prev and also to multiply update gate with cct. It has to be elementwise multiplication(*) as dimensions of matrices are same. I referred one of the blog posts that showed implementation of LSTM from scratch using numpy and that gave me clue.
Thank you for your support.

Best,
Ishan

1 Like

Anyone run into repeated problem AssertionError: wrong values for a_next for exercise Exercise 2 - rnn_forward and Exercise 3 - lstm_cell_forward

I seem to have code correct, dot, and multiplications, double checked , couldn’t find anything wrong?

Hi @walrus

Do make a fresh post and give as much info as possible to help diagnose your problem.