Last Programming Assignment. Code Passed Testings but Grade not fully taken

Although I have passed all tests, in the nn_model bringing all parts together, it showed some failures. I double checked my code, but no issue…
What can be the reason for this?

Failed test case: “extra_check”. Wrong weights matrix W1…
Expected:
[[-0.05350702 -0.10250995]
[-0.07303197 -0.1295294 ]
[-0.07487082 -0.11145172]],
but got:
[[-0.88792757 -2.15678679]
[-0.90083658 -2.29294507]
[-0.90485966 -2.2175348 ]].

Failed test case: “extra_check”. Wrong bias vector b1…
Expected:
[[0.03448384]
[0.03609865]
[0.0347455 ]],
but got:
[[0.79242606]
[0.92205182]
[0.85903016]].

Failed test case: “extra_check”. Wrong weights matrix W2…
Expected:
[[-0.39306094 -0.41154116 -0.40031599]],
but got:
[[-2.53898163 -2.75359949 -2.64586636]].

Failed test case: “extra_check”. Wrong bias vector b2…
Expected:
[[-0.74585916]],
but got:
[[1.72524631]].

There must be something wrong with your code if the tests fail. In the tests in the notebook, they do not set the random seeds, so the values may differ and they don’t check the actual values. So is that error coming from the grader?

Yes, Sir. I checked the code again and again. Even expected results have been achieved…
I am only suspicious of learning_rate of 1.2. Nothing else. But it is the value coming from the course creators.

You should not “hard-code” that learning rate value, right?

I did not hard code it. It is like a default value (in defining functions).
Did not change anything on this.

Are you sure you passed the learning rate when you call update_parameters from nn_model? And that you did not say learning_rate = 1.2? Because that would mean you are hard-coding it, right?

def nn_model(X, Y, n_h, num_iterations=10, learning_rate=1.2, print_cost=False):
“”"
Arguments:
X – dataset of shape (n_x, number of examples)
Y – labels of shape (n_y, number of examples)
num_iterations – number of iterations in the loop
learning_rate – learning rate parameter for gradient descent
print_cost – if True, print the cost every iteration

Returns:
parameters -- parameters learnt by the model. They can then be used to predict.
"""

(Snapshot from the file)

Issue was resolved!
Thanks!

1 Like

That is the definition of the nn_model function and that just says that 1.2 is the default value. My question is how you call update_parameters from nn_model. You need to pass the learning rate, but you need to be very careful not to say:

... = update_parameters(.., ..., learning_rate = 1.2, ...)

Because doing that means you are ignoring the value that was passed in to nn_model at the top level, which may well not be 1.2, right? You don’t know what the grader uses.

You are totally right. I just checked this and corrected. I was not expecting the grader to consider this too to be honest

Thanks for discussion now everything is crystal clear.

That’s great that you found the answer.

It is critical to understand how “named parameters” work in python. The definition of a function is a very different thing than calling a function. You can’t just “copy/paste” the definition of the function as the call to the function, because of the way named parameters work.