# Course 1 Week 4 Exercise 8 linear\_activation\_backward

**URL:** <https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419>\
**Category:** Neural Networks and Deep Learning\
**Tags:** coursera-platform\
**Created:** [February 26, 2022, 2:51pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419 "2022-02-26T14:51:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yash\_Singhal](https://avatars.discourse-cdn.com/v4/letter/y/22d042/32.png) [@Yash\_Singhal](https://community.deeplearning.ai/u/Yash_Singhal)\
**Post date:** [February 26, 2022, 2:51pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/1 "2022-02-26T14:51:56Z")

</div>

I m having The following Issue . I m getting the Following Error in the linear activation backward. I m really not sure Where I m getting this error . The error spefically related to the unpacking of the cache variable

ValueError: not enough values to unpack (expected 3, got 2)

Following is the Code

_{moderator edit - solution code removed}_

The error which is coming is

 ![image](https://global.discourse-cdn.com/dlai/original/2X/4/4d6a3ec618a21fd9eb2e8305dae5d8075961345c.png)

Following is the previous function (linear\_backward) output where all test cases passed

 ![image](https://global.discourse-cdn.com/dlai/original/2X/b/bc4d31d963ca2a7718d32d445f0031c1254dd2c9.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 26, 2022, 6:09pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/2 "2022-02-26T18:09:15Z")

</div>

You are passing the wrong cache value when you call _linear\_backward_. It should be the linear cache, but you are passing the full cache entry. They already extracted the two separate cache entries for you in the template code, right?

---

<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 26, 2022, 6:11pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/3 "2022-02-26T18:11:11Z")

</div>

Note that it is a general principle of debugging that the actual error may not be in the function that throws the exception. A perfectly correct subroutine can throw errors if you pass it incorrect arguments, which is what happened here. You have to track backwards from the point of the exception to figure out where the real problem is.

---

<div class="post-metadata">

**Author:** ![Yash\_Singhal](https://avatars.discourse-cdn.com/v4/letter/y/22d042/32.png) [@Yash\_Singhal](https://community.deeplearning.ai/u/Yash_Singhal)\
**Post date:** [February 28, 2022, 7:38pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/4 "2022-02-28T19:38:18Z")

</div>

Thank You for responding I actually was beign impatient and didnt realized

---

<div class="post-metadata">

**Author:** ![Malcolm\_Lawes](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/malcolm_lawes/32/22446_2.png) [@Malcolm\_Lawes](https://community.deeplearning.ai/u/Malcolm_Lawes)\
**Post date:** [August 4, 2022, 2:57am UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/5 "2022-08-04T02:57:37Z")

</div>

I had the same problem! Thanks for posting the question and saving me a lot of trouble…!

---

<div class="post-metadata">

**Author:** ![Erno\_Benko](https://avatars.discourse-cdn.com/v4/letter/e/d9b06d/32.png) [@Erno\_Benko](https://community.deeplearning.ai/u/Erno_Benko)\
**Post date:** [December 16, 2022, 12:10pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/6 "2022-12-16T12:10:29Z")

</div>

May i get some hints here, what is wrong? I suppose the data from cache shall be read backwards but i do not know how to implement that.

```auto
With sigmoid: dA_prev = [[0.44090989 0.]
 [0.37883606 0.]
 [-0.2298228 0.]]
With sigmoid: dW = [[0.44513824 0.37371418 -0.10478989]]
With sigmoid: db = [[-0.20837892]]
With relu: dA_prev = [[0.11017994 0.01105339]
 [0.09466817 0.00949723]
 [-0.05743092 -0.00576154]]
With relu: dW = [[0.10266786 0.09778551 -0.01968084]]
With relu: db = [[-0.05729622]]
Error: Wrong output with sigmoid activation for variable 0.
Error: Wrong output with sigmoid activation for variable 1.
Error: Wrong output with sigmoid activation for variable 2.
Error: Wrong output with relu activation for variable 0.
Error: Wrong output with relu activation for variable 1.
Error: Wrong output with relu activation for variable 2.
 4 Tests passed
 2 Tests failed
---------------------------------------------------------------------------
AssertionError Traceback (most recent call last)
<ipython-input-92-1dd7958789b5> in <module>
     11 print("With relu: db = " + str(t_db))
     12 
---> 13 linear_activation_backward_test(linear_activation_backward)

~/work/release/W4A1/public_tests.py in linear_activation_backward_test(target)
    378 ]
    379 
--> 380 multiple_test(test_cases, target)
    381 
    382 def L_model_backward_test(target):

~/work/release/W4A1/test_utils.py in multiple_test(test_cases, target)
    140 print('\033[92m', success," Tests passed")
    141 print('\033[91m', len(test_cases) - success, " Tests failed")
--> 142 raise AssertionError("Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.".format(target. __name__ ))
    143 

AssertionError: Not all tests were passed for linear_activation_backward. Check your equations and avoid using global variables inside the function.

Expected output:

With sigmoid: dA_prev = [[0.11017994 0.01105339]
 [0.09466817 0.00949723]
 [-0.05743092 -0.00576154]]
With sigmoid: dW = [[0.10266786 0.09778551 -0.01968084]]
With sigmoid: db = [[-0.05729622]]
With relu: dA_prev = [[0.44090989 0.]
 [0.37883606 0.]
 [-0.2298228 0.]]
With relu: dW = [[0.44513824 0.37371418 -0.10478989]]
With relu: db = [[-0.20837892]]

```

Regards

---

<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:** [December 16, 2022, 4:18pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/7 "2022-12-16T16:18:51Z")

</div>

The cache is passed in as an argument and they even give you the logic in the template code to extract the two components of the cache: the linear cache and the activation cache. Then you just have to pass the appropriate one to `linear_backward` and to `relu_backward` and `sigmoid_backward`.

Actually here’s a clue: compare your results to the expected values. You’ll notice that your values for the “with sigmoid” case agree with the expected values for the relu case. And vice versa. So you must have somehow got the logic backward in the two “if” clauses: you must have called `relu_backward` in the “sigmoid” case.

---

<div class="post-metadata">

**Author:** ![Erno\_Benko](https://avatars.discourse-cdn.com/v4/letter/e/d9b06d/32.png) [@Erno\_Benko](https://community.deeplearning.ai/u/Erno_Benko)\
**Post date:** [December 16, 2022, 6:02pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/8 "2022-12-16T18:02:53Z")

</div>

Ah, of course i called sigmoid in case of relu, and relu in case of sigmoid…  
Without your clue i was just blind enough, thank you for the response.

---

<div class="post-metadata">

**Author:** ![Anna\_Merino\_Garcia](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Anna\_Merino\_Garcia](https://community.deeplearning.ai/u/Anna_Merino_Garcia)\
**Post date:** [September 8, 2023, 9:20am UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/9 "2023-09-08T09:20:01Z")

</div>

Hahaha, it happened the same to me! I was starting to become crazy 😂  
Thanks 🙂

---

<div class="post-metadata">

**Author:** ![hellenxiahu](https://avatars.discourse-cdn.com/v4/letter/h/71e660/32.png) [@hellenxiahu](https://community.deeplearning.ai/u/hellenxiahu)\
**Post date:** [February 12, 2025, 8:46pm UTC](https://community.deeplearning.ai/t/course-1-week-4-exercise-8-linear-activation-backward/103419/10 "2025-02-12T20:46:45Z")

</div>

I did the same here, thank you for fix it, this  
dA\_prev, dW, db = linear\_backward(dZ, linear\_cache)  
now works  
checked back, cache will bring back Z, which we don’t need here
