Week 3: nn_model

I have the following error,the console doesnt explicitly specify what it is

Please help me out here!

You need to debug the problem. Are you sure that your forward_propagation function passed the earlier test cases that were specific to that function?

Anytime you get a dimension mismatch, the first question is “well, what shapes are they?” So add some print statements down in forward_propagation right before the line that “throws”. What do you see? Then the question is which one is wrong. Then you have to track backwards to figure out where the bug is. You can see the shapes of the input values by looking at the test code in public_tests.py.

1 Like

this is the output of the forward propagation:
A2 = [[0.21292656 0.21274673 0.21295976]]
All tests passed!

I will however debug and check

HI Paul,

I checked with other module predict and the result is as below:


and even in the case of forward propagation, the result is all passed.

Does anyone think the error maybe due to some weird test cases?
I have tried debugging too, no anomaly there.

and FYI my forward_propagation code looks something like the below:

{moderator edit - solution code removed}

The evidence suggests that the bug is not in forward_propagation or predict: it’s in nn_model. A perfectly correct subroutine can throw errors if you pass it bad arguments. So the thing to look for is something in nn_model that would cause bad arguments to be passed down.

Did you do the thing I suggested of printing the shapes of A2 and X down in forward_propagation to see what the bad values actually are? That should be a clue.

1 Like

the shape of A2 and (1,X[1].shape) is
(4, 3) (1, 3)

but the same error did not arise in forward_propagation step and now I am confused.

The problem is that the weights are initialized like:
W1 = (1, 2)
[[0.01788628 0.0043651 ]]
W2=(4, 1)
[[ 0.00096497]
[-0.01863493]
[-0.00277388]
[-0.00354759]]
It’s not even done by me its done by the system, is there any way to circumvent the issue?

Those shapes of W1 and W2 are completely wrong. It must be something you are doing in nn_model that is causing that. That’s not what the test case is giving you. Take a look at nn_model_test in public_tests.py. Here are the dimensions:

X is 2 x 3
Y is 1 x 3
n_h is 4

So that means there are 2 input “features”. So the dimension of W1 should be 4 x 2, right? It takes 2 inputs and produces 4 output neurons.

Then the output layer has one neuron, so W2 should be 1 x 4.

So why are your W1 and W2 the wrong shape? You must be calling the initialize routine with the wrong arguments.

Yes, I called the initialize_parameters function wrongly , the parameters that were passed inside were not in order. Thank you so much for the help Paul.