# Course 1, Week 4 Assignment 2 - 2 layer model

**URL:** <https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [June 11, 2021, 8:49am UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421 "2021-06-11T08:49:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kpal1995](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kpal1995](https://community.deeplearning.ai/u/kpal1995)\
**Post date:** [June 11, 2021, 8:49am UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/1 "2021-06-11T08:49:33Z")

</div>

While executing the 2 layer model in the 2nd assignment, I end up getting the following error message

 ![Screen Shot 2021-06-11 at 1.42.33 AM](https://global.discourse-cdn.com/dlai/original/2X/f/f2035b90abcca2335ef153380a200ef8c447f503.jpeg)

I can’t seem to figure out where the error might be. The next part of the assignment (L-layer model) runs fine with almost similar functions.

---

<div class="post-metadata">

**Author:** ![albertovilla](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/albertovilla/32/4530_2.png) [@albertovilla](https://community.deeplearning.ai/u/albertovilla)\
**Post date:** [June 11, 2021, 11:58am UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/2 "2021-06-11T11:58:30Z")

</div>

In order to debug the problem you need to chase it following its execution path. For example, looking at the error you’re getting it is clear that `W1` is wrong.

So, you need to check how `W1` is being calculated e.g. it is linked with `update_parameters` function. Ok, what are the inputs to that function? How are they calculated? Are they inputs to the `two_layer_model` function?

For example, `grads` is calculated upon the results of `linear_activation_backward`, you need to check what are the inputs to that function too, are they calculated? are they given inputs?

If you follow the execution path you will be able to chase the error.

Maybe before doing all the above you could check if by any chance you have hardcoded any value such as the `learning_rate`. If you are confident you haven’t done it then follow the execution flow by adding prints to what’s being calculated.

Check your output against what it is expected according to the public tests, for example, `W1` should be:

```python
'W1': np.array([[ 0.01624965, -0.00610741, -0.00528734, -0.01072836, 0.008664 ,
                                 -0.02301103, 0.01745639, -0.00760949, 0.0031934 , -0.00248971],
                                [ 0.01462848, -0.02057904, -0.00326745, -0.00383625, 0.01138176,
                                 -0.01097596, -0.00171974, -0.00877601, 0.00043022, 0.00584423],
                                [-0.01098272, 0.01148209, 0.00902102, 0.00500958, 0.00900571,
                                 -0.00683188, -0.00123491, -0.00937164, -0.00267157, 0.00532808],
                                [-0.00693465, -0.00400047, -0.00684685, -0.00844447, -0.00670397,
                                 -0.00014731, -0.01113977, 0.00238846, 0.0165895 , 0.00738212]])

```

---

<div class="post-metadata">

**Author:** ![ValeryLynn](https://avatars.discourse-cdn.com/v4/letter/v/a8b319/32.png) [@ValeryLynn](https://community.deeplearning.ai/u/ValeryLynn)\
**Post date:** [June 14, 2021, 3:04pm UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/3 "2021-06-14T15:04:39Z")

</div>

Hi, I’m using np.random.seed(1), but my W1 array is different than the expected:

‘W1’: array([[ 0.01624345, -0.00611756, -0.00528172, -0.01072969, 0.00865408,  
-0.02301539, 0.01744812, -0.00761207, 0.00319039, -0.0024937 ],  
[ 0.01462108, -0.02060141, -0.00322417, -0.00384054, 0.01133769,  
-0.01099891, -0.00172428, -0.00877858, 0.00042214, 0.00582815],  
[-0.01100619, 0.01144724, 0.00901591, 0.00502494, 0.00900856,  
-0.00683728, -0.0012289 , -0.00935769, -0.00267888, 0.00530355],  
[-0.00691661, -0.00396754, -0.00687173, -0.00845206, -0.00671246,  
-0.00012665, -0.0111731 , 0.00234416, 0.01659802, 0.00742044]])

---

<div class="post-metadata">

**Author:** ![tigo\_de](https://avatars.discourse-cdn.com/v4/letter/t/9dc877/32.png) [@tigo\_de](https://community.deeplearning.ai/u/tigo_de)\
**Post date:** [March 2, 2022, 8:18pm UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/4 "2022-03-02T20:18:39Z")

</div>

Hi Valery,  
I stumbled upon a similar problem. I could solve it be using the provided `initialize_parameters()` function instead of filling the `parameters` dict by myself (eg. with `np.random.randn()`):

Hope that helps!

---

<div class="post-metadata">

**Author:** ![Matheus\_PEDROSO\_SANC](https://avatars.discourse-cdn.com/v4/letter/m/c6cbf5/32.png) [@Matheus\_PEDROSO\_SANC](https://community.deeplearning.ai/u/Matheus_PEDROSO_SANC)\
**Post date:** [May 27, 2022, 7:52pm UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/5 "2022-05-27T19:52:46Z")

</div>

Hello Guys!

For the ones that are getting this error, this is my experience:

I was using the function to initialize the parameters from the previous assignment (`def initialize_parameters_deep(layer_dims)`). The thing is that you actually have to use the implementation that they provide to you (`def initialize_parameters(n_x, n_h, n_y)`)

Now everything is working as expected! =)

---

<div class="post-metadata">

**Author:** ![paulinpaloalto](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/paulinpaloalto/32/187_2.png) [@paulinpaloalto](https://community.deeplearning.ai/u/paulinpaloalto)\
**Post date:** [May 27, 2022, 8:29pm UTC](https://community.deeplearning.ai/t/course-1-week-4-assignment-2-2-layer-model/13421/6 "2022-05-27T20:29:22Z")

</div>

Yes, that’s what they tell us to do in the instructions. The ironic thing is that the “deep” version of the initialization that they give us here is a more sophisticated algorithm and it actually generates better results in the 2 layer case. But the grader is checking that the results match what it expects, so better is not considered a good thing in that context. 😆
