C2_W3_Assignment Exercise 2 - Wrong size of the hidden layer

I am trying to complete the function “layer_sizes(X, Y)” but I am having problems with the number of hidden layers n_h.

This is the output I am getting:

Test case “extra_check”. Wrong size of the hidden layer n_h.
Expected: 2.
Got: 5.
5 Tests passed
1 Tests failed

I know that the hidden layer should be 2, but for sure I am writing something wrong

Dear @Josue could you please elaborate on your answer in the notebook more?

Hie @ParetoFront :slight_smile: In this exercise, is it possible to calculate n_h using the inputs X, Y? or should I define this variable with a constant value?

Surely the instructions for that section must say something about how to handle that. Please have another careful look. I don’t have access to the M4ML courses, but they copied this assignment from DLS C1 W3 and there the instructions quite clearly tell you what to do about n_h. You can’t compute it from the shapes of X and Y.

1 Like

Dear @Josue as @paulinpaloalto very accurately mentioned, you cannot extract n_h from X and Y, because otherwise how could we have so many neural networks with different architectures and different layer sizes? :wink:

In this specific notebook, we are instructed to set n_h equal to 2.

Setting the best number of hidden layers and the best number of nodes in each layer is a tricky task, and they are considered as hyperparameters. You will learn to set these parameters much better as you gain more experience working with NNs.

Hope this solves your issue.

1 Like

Thanks! @ParetoFront @paulinpaloalto

1 Like

There’s an important “meta” lesson here: if you think you are “saving time” by not reading the instructions carefully, it almost always ends up not being a net savings of time. You “save” a couple of minutes and then waste a couple of hours trying to figure out what went wrong. :nerd_face:

@paulinpaloalto Or as the legend goes: 2 hours of debugging can save you from 10 minutes of documentation reading. :smiling_face_with_tear: