[Week 1] Assignment 1, AssertionError: Problem 1 in yt_pred expression. Related to by?

Hello, Im stuck with the first assignment: Building_a_Recurrent_Neural_Network_Step_by_Step.

My problem is in:

def rnn_cell_forward(xt, a_prev, parameters)

I believe that I wrote down the formulas in a correct way, but running the cell continues to give me the

AssertionError: Problem 1 in yt_pred expression. Related to by?

I really dont understand the error because the biases ‘by’ are default.

What Im a missing/doing it wrong ?

I end up with the right values for ‘a_next’ and wrong values for ‘yt_pred’

Hi, @franz ,

The assertion error is triggered by yt_pred having a shape that is different from what is expected. So you need to check how yt_pred is calculated.

The parameter pass to np.dot in the softmax statement should be Wya and a_next, where a_next is the newly calculated hidden state. Please check the formula in Fig2 and also the instruction notes.

Hi, thanks a lot for your fast answer

Im really sorry to bother you, I think that Im missing something that is pretty trivial.

I read again the instructions without help, the fact is that:

  • in the softmax, Im dotting ‘Wya’ with ‘a_next’
  • ‘Wya’ is given by default,
  • ‘a_next’ is right (as you can check from values and shape in the figure above)
  • ‘by’ is also default

-the output shape of ‘yt_pred’ is also correct, in fact should be (2,10)

How can happen that the ‘y_pred’ values are wrong ?

Hi @franz ,

If your call to softmax followed the formula, then, I suggest you refresh the kernel and clear all output, and rerun the cells. This is to ensure your code is running in a clean state.

That does not seem to help.

But Im pretty sure that the parametrs that Im passing to softmax are correct.

Is there a way to complete restart the assignment from zero?

Hi @franz,

You can get another copy of the assignment by clicking the ?help button on the right corner. Do save a copy of your current file and rename it before hand just in case you want to make reference to it.
Are you getting the same results for y_pred as reported in your first post?

Yes Im getting always the same result.

I tried to refresh the lab workspace but that did not work.
I also tried to rebooting and nothing happens.
Im always stuck with the same error.
This procedures are mantaining the saved changes from the last days.

Why I cant erase all that I’ve done until now and get a new notebook?

Or is there a way, maybe if I share the Lab ID with you, that you can check what is going on?

Hi @franz,

Did you open the ?help button and click on the get updated version?
That should give you a fresh copy of the original notebook. You should rename your current version before getting a fresh copy for reference purposes. When you got a fresh copy of the original notebook, type in the code, don’t cut and paste from your previous notebook.

You can post the code of that function by direct messaging. I will have a look for you.

Did you find out what the problem was? I’m faced with similar assertion error, double checked my code, can’t find anything problems

Hi @walrus ,

Do post a fresh query with as much info as possible so that we could diagnose your problem.

Hi @Kic, I’m facing the exactly same error. I’ve double-checked the code, refreshed the kernel, nothing helped. Then I found out that the test passes fine if I assign y_pred to be not y_pred[:, :, t] but y_pred[:, :, t-1]. If I don’t do this minus 1, my y_pred result is somehow shifted +1 index to the right (see the picture below) and is not matching the expected result. Am I supposed to assign the t-1 position to y_pred or is it a bug? Assigning to t-1 seems illogical…


Hi @als ,

The values you showed here are not the same as the expected output.
If you have to change the time stamp, t, then there is something wrong with your code.
Put that section of your code and post a DM to me, I will have a look for you.

Hi @als ,

That section of the code looked fine. Did you rerun the code from start after refreshing the kernel?

Hi @als

The code for rnn_cell_forward() where softmax is called with values returned from np.dot() has a problem:
The np.dot() call should have a_next as the second parameter.

1 Like

Thank you very much.
I had the same value problem with the rnn_forward function.
I had incorrectly set a_prev in dot in softmax in the rnn_cell_forward function.
After correcting it to a_next, the test in the rnn_forward function worked correctly.

Hi @snowfly ,

That is great you have got it sorted.

AssertionError Traceback (most recent call last)
—> 18 rnn_cell_forward_tests(rnn_cell_forward)

~/work/W1A1/public_tests.py in rnn_cell_forward_tests(target)
24 assert len(cache_tmp[3].keys()) == 5, “Wrong number of parameters in cache. Expected 5”
—> 26 assert np.allclose(np.tanh(parameters_tmp[‘ba’]), a_next_tmp), “Problem 1 in a_next expression. Related to ba?”
27 assert np.allclose(softmax(parameters_tmp[‘by’]), yt_pred_tmp), “Problem 1 in yt_pred expression. Related to by?”

AssertionError: Problem 1 in a_next expression. Related to ba?

Ive got this error. below is an ss of my code
{Codes removed by moderator as it’s against community guidelines, refrain from posting grader codes}

Hi @ijazzia ,

What is xt_tmp?
Please check the def of rnn_cell_forward()

1 Like

Thank you for pointing that out. I mistakenly used the same variables that were passed on in my function as arguments, in the formulas inside my function.

Sorry to bother you for such a noob issue on my part. Been scrutinizing my code for about two hours, though.

1 Like