# Course 1:Week 4 Programming Assignment 2 Error in two\_layer\_model

**URL:** <https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [June 18, 2022, 12:57am UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566 "2022-06-18T00:57:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![gurjinder](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@gurjinder](https://community.deeplearning.ai/u/gurjinder)\
**Post date:** [June 18, 2022, 12:57am UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566/1 "2022-06-18T00:57:41Z")

</div>

I am not able to pass two test cases. I am using the provided initialize\_parameters(n\_x,n\_h,n\_y) function for parameter init. Cannot figure out what is wrong. Any suggestions will be appreciated. Thank you.

 ![Screen Shot 2022-06-17 at 8.54.13 PM](https://global.discourse-cdn.com/dlai/original/3X/e/a/ea35a93384d8534a5b3c76362819a2a14103e0dc.png)

---

<div class="post-metadata">

**Author:** ![anon57530071](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@anon57530071](https://community.deeplearning.ai/u/anon57530071)\
**Post date:** [June 18, 2022, 3:28am UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566/2 "2022-06-18T03:28:43Z")

</div>

This is slightly interesting output.  
Observations are;

- Looks like the first iteration seems to be OK.
- Shapes and types for all weights seem to be OK.
- A problem is 2nd iteration or later. In that case, parameters are not properly updated.
- On the other hand, in the 2nd test, W2 and b2 are correct. But, W1 and b1 are not. In the last test, still b2 are correct.

From the above observations, of course, you may want to check the process to update.  
Since there are some correct weights even in the 2nd iteration, one doubt is, do you set an appropriate activation function for back-propagation to update dA0, dW1, and db1 ? It is not “sigmoid”.

---

<div class="post-metadata">

**Author:** ![gurjinder](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@gurjinder](https://community.deeplearning.ai/u/gurjinder)\
**Post date:** [June 18, 2022, 5:27pm UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566/3 "2022-06-18T17:27:31Z")

</div>

Thank you for your response!

I am using relu for dA0, dW1, db1  
And then simply using update\_parameters() function

Still confused what might go wrong…

---

<div class="post-metadata">

**Author:** ![anon57530071](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@anon57530071](https://community.deeplearning.ai/u/anon57530071)\
**Post date:** [June 18, 2022, 5:32pm UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566/4 "2022-06-18T17:32:40Z")

</div>

Now, I understood whole reason… I was very close actually.  
To get dA0, dW1 and db1, we need to pass dA1 and cache with “relu” activation.  
It is not A1.

By the way, pasting code in here is not recommended. Please remove them, thank you.

Good luck !

Nobu.

---

<div class="post-metadata">

**Author:** ![gurjinder](https://avatars.discourse-cdn.com/v4/letter/g/e36b37/32.png) [@gurjinder](https://community.deeplearning.ai/u/gurjinder)\
**Post date:** [June 18, 2022, 5:34pm UTC](https://community.deeplearning.ai/t/course-1-week-4-programming-assignment-2-error-in-two-layer-model/141566/5 "2022-06-18T17:34:10Z")

</div>

That was so silly of me! Thank you for pointing that out. I will delete the code now. Thanks again 🙂
