Sequence Models Week 1 Assignment 1

Hello all,
I am having difficulty resolving a shape issue with my code in week 1 assignment. Below is the error I receive. Thanks!

ValueError Traceback (most recent call last)
in
9 parameters_tmp[‘by’] = np.random.randn(2, 1)
10
—> 11 a_tmp, y_pred_tmp, caches_tmp = rnn_cell_forward(x_tmp, a0_tmp, parameters_tmp)
12 print(“a[4][1] = \n”, a_tmp[4][1])
13 print(“a.shape = \n”, a_tmp.shape)

in rnn_cell_forward(xt, a_prev, parameters)
30 ### START CODE HERE ### (≈2 lines)
31 # compute next activation state using the formula given above
—> 32 a_next = np.tanh(np.dot(Waa, a_prev) + np.dot(Wax, xt)+ba)
33 # compute output of the current cell using the formula given above
34 yt_pred = softmax(np.dot(Wya, a_next) + by)

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

ValueError: shapes (5,3) and (3,10,4) not aligned: 3 (dim 1) != 10 (dim 1)

These parameters being passed to rnn_cell_forward() from the unit test cell do not appear to be correct. Did you modify them?

It looks like you have modified that test cell. It does not look like that in my copy of the notebook. Here’s what I see for the line that invokes rnn_cell_forward:

a_next_tmp, yt_pred_tmp, cache_tmp = rnn_cell_forward(xt_tmp, a_prev_tmp, parameters_tmp)

See the difference? In your case the first and second arguments are different. So how did that happen? Just generally speaking it’s not a good idea to modify the test code. If the test fails, the solution is not to change the test: it is to figure out why your code fails the test.

If you want to get a clean copy of the notebook and start over, there is a topic about that on the FAQ Thread.

Hi, Tom. Sorry! Our replies “crossed in midair”. The good news is we both said the same thing. :nerd_face:

I am receiving the error from the rnn_forward test block not the rnn_cell_forward block. The parameters being passed are actually correct in this case. Please see below. Thanks for help!

This is also after updating the lab

Hey @Eric_Brazell, I guess there is a small confusion. In the screenshot you have attached above, it is for the test block of rnn_cell_forward only. Even in your error that you initiated your post with, it is mentioned rnn_cell_forward. Can you please confirm this? Because if this is for the rnn_cell_forward, then it differs from what we can see in our copy of the notebook.

Regards,
Elemento

Figured out the issue!

Glad to hear you found the answer. Note that in all the images you posted the function being call is not rnn_forward but rnn_cell_forward. Apparently some wires were crossed somewhere. :nerd_face:

1 Like