Course 5 Week 1 Assignment 1 Exercise 4: lstm_forward returns correct cache, incorrect values

Hey, I am getting the following error. Have been staring at my screen for a while and can’t figure out what I am doing wrong

a[4][3][6] = 0.1786306327904998
a.shape = (5, 10, 7)
y[1][4][3] = 0.9470058898412563
y.shape = (2, 10, 7)
caches[1][1][1] =
[ 0.82797464 0.23009474 0.76201118 -0.22232814 -0.20075807 0.18656139
0.41005165]
c[1][2][1] -0.6345136458872118
len(caches) = 2

AssertionError Traceback (most recent call last)
in
24
25 # UNIT TEST
—> 26 lstm_forward_test(lstm_forward)

~/work/W1A1/public_tests.py in lstm_forward_test(target)
162 assert len(caches[0][0]) == 10, f"length of caches[0][0] must be 10."
163
→ 164 assert np.allclose(a[2, 1, 4:6], [-0.01606022, 0.0243569]), “Wrong values for a”
165 assert np.allclose(c[2, 1, 4:6], [-0.02753855, 0.05668358]), “Wrong values for c”
166 assert np.allclose(y[1, 1, 4:6], [0.70444592 ,0.70648935]), “Wrong values for y”

AssertionError: Wrong values for a

In “n_y, n_a = …”, you don’t need “parameters” there. Just Wy.shape is sufficient.

In your call to lstm_cell(), you should use a_next and c_next.

Please don’t post your code on the Forums. That’s not allowed by the course Honor Code. If a mentor needs to see your code, they’ll ask you for it.

Thanks for your response. All runs smoothly now. Code removed!

I have fixed the two issues you mention, but I’m getting the same error. I’m using xt, a_next, c_next, and parameters in my call to lstm_cell_forward. Anything else to check?

1 Like

Those are the correct arguments.
Perhaps you’ve got a problem with the slicing used to create xt, a, c, or y.

Hi to all, I currently have the same result as [travisbickle34], same identical values
Good cache values but wrong a, y and c values.

I have already verified the pieces of advice mentioned in this post.
Since, the very beginning I used a_next and c_next to call my lstm_cell().
Although I was using parameters[“Wy”].shape to recover the n_y and n_a, getting these values from Wy.shape does not solve my error.

I have been looking for over 3 h the function, and I cannot get the error. Could someone give some advice?

Thanks in advance

@lmuriarte ,
My reply to Travis was in answer to the assert he had “Wrong values for a”.
What assert are you seeing?

@TMosh
Thanks for such a fast reply, I really apprecite it.
I have the same error:

a[4][3][6] = 0.1786306327904998
a.shape = (5, 10, 7)
y[1][4][3] = 0.9470058898412563
y.shape = (2, 10, 7)
caches[1][1][1] =
[ 0.82797464 0.23009474 0.76201118 -0.22232814 -0.20075807 0.18656139
0.41005165]
c[1][2][1] -0.6345136458872118
len(caches) = 2


AssertionError Traceback (most recent call last)
in
24
25 # UNIT TEST
—> 26 lstm_forward_test(lstm_forward)

~/work/W1A1/public_tests.py in lstm_forward_test(target)
162 assert len(caches[0][0]) == 10, f"length of caches[0][0] must be 10."
163
→ 164 assert np.allclose(a[2, 1, 4:6], [-0.01606022, 0.0243569]), “Wrong values for a”
165 assert np.allclose(c[2, 1, 4:6], [-0.02753855, 0.05668358]), “Wrong values for c”
166 assert np.allclose(y[1, 1, 4:6], [0.70444592 ,0.70648935]), “Wrong values for y”

AssertionError: Wrong values for a

Hi @TMosh, I am also having the same problem. I’m almost certain I have initialized a incorrectly but can’t think of any other way to do it. How do I send you a private message with my code to get help?

Thank you all for this thread. It has been very helpful. I’ll also add to make sure that you are initializing with a0. In other words, make sure that a_next and c_next are not identical when you initialized them.

1 Like

a_next = np.copy(a0)