# Week 3, Programming Assignment, Exercise 8

**URL:** <https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [February 25, 2022, 3:17pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126 "2022-02-25T15:17:51Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![OSAMA\_SHBIB](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/osama_shbib/32/15264_2.png) [@OSAMA\_SHBIB](https://community.deeplearning.ai/u/OSAMA_SHBIB)\
**Post date:** [February 25, 2022, 3:17pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/1 "2022-02-25T15:17:52Z")

</div>

Hi everyone,  
When running the `nn_model()` , the cost isn’t changing after iterations, and I am getting this error. What do you think is the cause of the problem?  
Thanks in advance.

 ![Screenshot (6)](https://global.discourse-cdn.com/dlai/original/2X/7/7be61af17efe365a7c054db1259161ca7d48e063.png)

---

<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:** [February 25, 2022, 3:43pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/2 "2022-02-25T15:43:30Z")

</div>

If the cost doesn’t change, then the first place I would look is at your “update parameters” logic.

Notice that your b1 and b2 values are still zero, so I’ll bet your W values have not changed from their original either. So why are they not changing? If your _update\_parameters_ function passed its test case, then there must be something wrong with the way you are calling it. That logic should be in _nn\_model_.

---

<div class="post-metadata">

**Author:** ![vsnupoudel](https://avatars.discourse-cdn.com/v4/letter/v/53a042/32.png) [@vsnupoudel](https://community.deeplearning.ai/u/vsnupoudel)\
**Post date:** [February 25, 2022, 3:45pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/3 "2022-02-25T15:45:12Z")

</div>

The logic for updating weights after subtracting gradients may not be put correctly. You should have something like W1 = W1 - gradient(wrt W1) \*learning\_rate

---

<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:** [February 25, 2022, 5:46pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/4 "2022-02-25T17:46:58Z")

</div>

One way cause this behavior is to misspell the variable name that gets the relevant return value from _update\_parameters_. The updated values are passed back in a dictionary.

---

<div class="post-metadata">

**Author:** ![user585](https://avatars.discourse-cdn.com/v4/letter/u/dbc845/32.png) [@user585](https://community.deeplearning.ai/u/user585)\
**Post date:** [May 5, 2022, 9:25am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/5 "2022-05-05T09:25:26Z")

</div>

Hi, I had exactly the same issue and solved it, simply having _un-indentation_ of all the functions inside the nn\_model.

---

<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 5, 2022, 2:52pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/6 "2022-05-05T14:52:54Z")

</div>

Yes, indentation is a key part of the syntax of python. Changing it fundamentally changes the meaning of the code. Getting it right is essential!

---

<div class="post-metadata">

**Author:** ![Timothe\_Bulliard](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/timothe_bulliard/32/126660_2.png) [@Timothe\_Bulliard](https://community.deeplearning.ai/u/Timothe_Bulliard)\
**Post date:** [May 24, 2022, 8:25pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/7 "2022-05-24T20:25:16Z")

</div>

Hello everyone,  
I also have an issue running the **nn\_model( )**. I get an assertion error for the shape of A2 despite the fact that it had already been verified as fine in the previous function **forward\_propagation**.  
What do you think I am missing here?  
Thanks!

 ![image](https://global.discourse-cdn.com/dlai/original/3X/1/3/13a904f776acb0007fd59062acfaf9314593be45.png)  
 ![image](https://global.discourse-cdn.com/dlai/original/3X/7/b/7b292e643485c4b477c66e4a08db4db2073b26c6.png)

---

<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 24, 2022, 8:31pm UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/8 "2022-05-24T20:31:34Z")

</div>

A perfectly correct function can still throw errors if you pass it mismatching or incorrect parameters. So the bug is somewhere else. Most likely it’s in your _nn\_model_ logic, since all the other routines passed their tests. What is the actual shape you are getting for A2 in the failing case? What should it be and why is it different? Then work backwards …

Of course there is a small caveat here: it’s possible that the test cases for some of the earlier functions didn’t catch all possible bugs.

---

<div class="post-metadata">

**Author:** ![Timothe\_Bulliard](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/timothe_bulliard/32/126660_2.png) [@Timothe\_Bulliard](https://community.deeplearning.ai/u/Timothe_Bulliard)\
**Post date:** [May 25, 2022, 6:56am UTC](https://community.deeplearning.ai/t/week-3-programming-assignment-exercise-8/103126/9 "2022-05-25T06:56:11Z")

</div>

Thanks a lot, the issue indeed came from the initialization of the parameters, I had put the inputs in the wrong order…  
(I tried to print the shape of A2 in the nn\_model but it wasn’t appearing since the assertion was directly in the _forward\_propagation_ function and thus was stopping the algorithm before the _print_.  
So today, after a little thought I put a _print(A.shape)_ in the _forward\_propagation_… I feel bad for thinking about it so late … 🙃)
