Week 3 assignment: bug in the test

In original notebook, there is no code to set the seed in initialize_parameters(). Where did you get it ?
nn_model() sets the seed to 3 at the top of the code. So, initialize_parameters() in nn_model() should inherit this setting, i.e, seed=3. The root cause is you put the np.random.seed(2) in initialize_parameters().

2 Likes

Yes, I’ve removed the parameters argument from cost function. Thank you.

1 Like

That’s stupid of me. Now the code is in original form I guess.
This problem still exists.

1 Like

It clearly said that the shape of your A2 is (1,3). Since the shape of Y is (1,400), it does not work. It needs to be the same shape as Y or the shape that Python can broadcast.
Assuming that A2 comes from forward_propagation() just before calling compute_cost(), the problem should be in there. Do you have any fixed parameter in there ?
I think it is better for you to trace the shape of A2 in both nn_model() and forward_propagation().

1 Like

Thank you for your reply Nobu_Asai. There are no fixed parameters I guess. Here are the screenshots for the forward_propagation and cost function. I couldn’t figure it out by myself. All the test are passed except 5.2 Here I’ve attached 3 screenshorts for the forward, backward and cost function. Thank you.

{moderator edit - solution code removed}

Thank you.

1 Like

At first , please delete all code. It is not recommended in this community.
I will send my thought shortly.

1 Like

Your notebook has lots of “trial and errors”. Again, it is better to clean up. Otherwise, no one can predict what will happen.
The most problematic portion is you mixed up global variables and variables inside classes/functions. For example, there is no parameter t_X passed to forward_propagation(). You needs to use parameters passed. In this case, that should be X. As the fact, the shape of t_X in global variables is (2,3). But, the shape of X is different. It should pass the first test which uses t_X, but it should not for others.
In addition, there are still some “debris” in compute_cost(). I remember you added one argument in here. And, there are still some code that refer ‘parameter’. In this case, you refer a global variable. If everything is cleaned up, then, those may cause unexpected errors.
Anyway, the first thing to do is, of course, remove code in here, which is not recommended in this community. Then, 2nd thing to do is, to replace t_X, a global variable, by X, which is passed to forward_propagation().

1 Like

Thank you so much Nobu_Asai yeah the problem was with forward_propagation function, I had used global variable. Now it is all fixed. Once again you’re the best.
Thank you.

1 Like

I would like to ask last question, is it possible to revert the notebook to the original file which discards all the changes that we made.

Thank you.

1 Like

Good to know that you completed this assignment !

Here is a good article which may help you. FAQ: Frequently Asked Questions for all DLS Courses

Good luck !

2 Likes

hey,Sara,I got exactly the same output with you. Did you figure out the problem? thx.

1 Like

Hi, Phoebe.

In Sara’s case, it turned out there was an error in that one of the variable names used to hold the return values from one of the functions called by nn_model was misspelled, so the later code ended up using a global variable.

Of course programming has lots of “degrees of freedom”, so that means the number of potentially different mistakes one can make is pretty large. If the hint I gave above doesn’t get you anywhere, let us know and we’ll go from there. :nerd_face:

1 Like

OMG! I did misspelled a variable names! :rofl: Now it worked ! Thank you very much!!! :grin:

Wow, so it really was the same kind of mistake to get the same result. So glad to hear that hint was enough for you to find the solution! Onward! :nerd_face:

1 Like

Hi @Jitendra_Bansal I have the same problem exactly with you please what is the mistake??

I am looking at this since 2 days but I have the same problem

@Bernardin_Tamo_Amoug If your error is on backward_propagation, there are a number of common mistakes there. Start by checking your implementation of dZ1 carefully. Are you sure you used W2 there and not dW2? Also check your implementation of g^{[1]'}(Z^{[1]}) in that formula: it is not equal to (1 - Z1^2), right?

Those are the most common two mistakes I can think of. If that’s doesn’t help, then we’ll go to the next step.

1 Like

@paulinpaloalto thank you for your help.I found my mistake

1 Like

That’s great news! Thanks for confirming.

Hello, I think there may be a bug on exercise 6 test suite because I get a KeyError: A1 when unpacking parameters["A*"]. When on a new cell I inspect the parameters dictionary returned by backward_propagation_test_case I get
image
Which seem to me be the initialised parameters, not the updated ones after running forward_propagation at least once, which would contain A*.

So is this a bug or am I missing something?