Course 5 week 1 assignment 1 exercise 2 - AssertionError: Wrong values for a

Hi,

When I run the cell that tests the rnn_forward function, I get “AssertionError: Wrong values for a”.
There wasn’t much to do in creating the function so I really don’t know what could have gone wrong…

  • When running the rnn_cell_forward (within rnn_forward) the inputs I give it are x[:,:,t], a_next, parameters.
  • When a[:,:,t] needs to be updated, I put a_next.
  • When y_pred[:,:,t] needs to be updated, I put yt_pred.
    Is any of this wrong?

If not, I need someone to look at my code or something…

Thanks!
Tal

1 Like

In the next exercise on the same assignment (lstm_cell_forward) I am now getting a similar error message (lstm_cell_forward is not dependent on the previous functions): “AssertionError: wrong values for a_next”. And again, I have no idea why (this time there was a lot to do in creating this function, so the error can be anywhere…). Why isn’t there any useful feedback when a test fails?? Can someone look at my code (for both of these functions)?

Thanks!
Tal

If you open the public_tests.py file from the File menu, you can see what tests are included in rnn_forward_test(). This should give you some clues what may be triggering the assert.

All I can tell from that is what values it is feeding into my function and what values it expects to get… This isn’t telling me anything about what could have gone wrong.

You may have to do some old-fashioned paper calculations to compare with what your code is doing, and add some diagnostic print() statements.

The test cases are fairly small.

I don’t understand what you mean… The test isn’t helping me in any way. I couldn’t find the problem in my code. I need help identifying what’s wrong with it.

Hello @Tal_N!

First, let’s focus on your first post, rnn_forward.

This is a nice way of telling about your code without sharing it. Using words. Great! Yes, your code is correct.
Can you tell me, in words, how you are doing this:

# initialize "a" and "y_pred" with zeros (≈2 lines)
a = None
y_pred = None

# Initialize a_next (≈1 line)
a_next = None

And, have you passed the previous test, rnn_cell_forward?

Hi @saifkhanengr,

I am using np.zeros, and initializing a to a size of n_a,m,T_x , y_pred to a size of n_y,m,T_x, and a_next to a size of n_a,m.

And rnn_cell_forward passed all tests.

Thanks!!
Tal

That is wrong. You don’t need to use np.zeros for that. a0 -- Initial hidden state is already given to you. You just need to use it as initialize of a_next.

2 Likes

Great, thanks!
This has also helped me resolve the issue in the next function. So all good now :slight_smile:

Thank you!