# Ex 4 and 5 nlp course 2 assignment 4 of week 4

**URL:** <https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379>\
**Category:** NLP with Probabilistic Models\
**Tags:** week-module-4\
**Created:** [April 6, 2023, 6:48pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379 "2023-04-06T18:48:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mahnoor\_Shafiq](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Mahnoor\_Shafiq](https://community.deeplearning.ai/u/Mahnoor_Shafiq)\
**Post date:** [April 6, 2023, 6:48pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/1 "2023-04-06T18:48:06Z")

</div>

Hi @Mubsi ,  
Lab id: jfxmpusrcheo

Can anyone please help me with exercises 4 and 5? I tried many times but did not get the solution. I will appreciate your help and support.

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/elemento/32/854_2.png) [@Elemento](https://community.deeplearning.ai/u/Elemento)\
**Post date:** [April 7, 2023, 5:24am UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/2 "2023-04-07T05:24:02Z")

</div>

Hey @Mahnoor_Shafiq,  
Can you please share your error stack, or in other words, the error that you are getting, in exercises 4 and 5?

Cheers,  
Elemento

---

<div class="post-metadata">

**Author:** ![Mahnoor\_Shafiq](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Mahnoor\_Shafiq](https://community.deeplearning.ai/u/Mahnoor_Shafiq)\
**Post date:** [April 7, 2023, 2:44pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/3 "2023-04-07T14:44:04Z")

</div>

Hi,

Attached below is the error.

 ![image](https://global.discourse-cdn.com/dlai/original/3X/6/0/608ed88b22ba0a8f7c89d73114355fc68479871a.png)

---

<div class="post-metadata">

**Author:** ![Mahnoor\_Shafiq](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Mahnoor\_Shafiq](https://community.deeplearning.ai/u/Mahnoor_Shafiq)\
**Post date:** [April 7, 2023, 3:20pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/4 "2023-04-07T15:20:52Z")

</div>

Wrong output values for gradient of b1 vector.  
Expected: [[0.56665732]  
[0.46268776]  
[0.10631469]  
[0.]  
[0.11041817]  
[0.32025188]  
[0.]  
[0.08430877]  
[0.19341]  
[0.08339139]  
[0.]  
[0.]  
[0.19055422]  
[0.56405984]  
[0.13321987]]  
Got: [[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]].  
Wrong output values for gradient of b2 vector.  
Expected: [[0.09488382]  
[-0.92645217]  
[0.04061033]  
[0.11081115]  
[0.06029008]  
[0.15000559]  
[0.12740163]  
[0.14957542]  
[0.1007054]  
[0.09216876]]  
Got: [[0.70541249]  
[-6.88769622]  
[0.30191695]  
[0.82382401]  
[0.44822579]  
[1.11521454]  
[0.94716571]  
[1.11201645]  
[0.74869294]  
[0.68522741]].  
Wrong output values for gradient of b1 vector.  
Expected: [[0.01864644]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.14815984]  
[0.25794505]  
[0.24893135]  
[0.05895103]  
[0.]]  
Got: [[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]  
[0.]].  
Wrong output values for gradient of b2 vector.  
Expected: [[0.22636192]  
[-0.59052847]  
[0.12268763]  
[0.06530444]  
[0.17617448]]  
Got: [[1.30236687]  
[-3.39758876]  
[0.70587979]  
[0.37572724]  
[1.01361486]].  
12 Tests passed  
4 Tests failed

After some changes now I am getting this error.

---

<div class="post-metadata">

**Author:** ![Mahnoor\_Shafiq](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Mahnoor\_Shafiq](https://community.deeplearning.ai/u/Mahnoor_Shafiq)\
**Post date:** [April 7, 2023, 8:41pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/5 "2023-04-07T20:41:56Z")

</div>

Can you please help me with this?

---

<div class="post-metadata">

**Author:** ![Elemento](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/elemento/32/854_2.png) [@Elemento](https://community.deeplearning.ai/u/Elemento)\
**Post date:** [April 8, 2023, 6:01am UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/6 "2023-04-08T06:01:11Z")

</div>

Hey @Mahnoor_Shafiq,  
Did you cross-check your equations with the ones given in the lecture video? Let me give you some starting hints. For computing `grad_b1`, as per the equations given, we don’t need W\_1, still in your code, I can see that you have used it. Similarly, for computing `grad_b2`, I can see that you have used H^T, still it’s not used in the equations given. Re-check your equations once using the ones given in this [lecture video](https://www.coursera.org/learn/probabilistic-models-in-nlp/lecture/mPJwt/training-a-cbow-model-backpropagation-and-gradient-descent) as a reference. Let us know if this helps.

Cheers,  
Elemento

---

<div class="post-metadata">

**Author:** ![Mahnoor\_Shafiq](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@Mahnoor\_Shafiq](https://community.deeplearning.ai/u/Mahnoor_Shafiq)\
**Post date:** [April 9, 2023, 10:18pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/7 "2023-04-09T22:18:01Z")

</div>

Hi,

Hope you are doing well. Sorry for the late response. Thank you for your help I checked the lecture and I was able to solve the issue. Thank you for your help again.

---

<div class="post-metadata">

**Author:** ![sunbird](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@sunbird](https://community.deeplearning.ai/u/sunbird)\
**Post date:** [October 8, 2023, 6:40pm UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/8 "2023-10-08T18:40:41Z")

</div>

> [@Elemento](#):
>
> lecture video

Hi @Elemento

I’m also stuck on this issue.  
Could you please advise me on what the ‘step’ function implies here:

 ![Screenshot 2023-10-08 at 11.43.42 PM](https://global.discourse-cdn.com/dlai/original/3X/6/d/6df1352143b717f9dabb28d6ecfdfaa32f96ba00.jpeg)

---

<div class="post-metadata">

**Author:** ![sunbird](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@sunbird](https://community.deeplearning.ai/u/sunbird)\
**Post date:** [October 9, 2023, 3:52am UTC](https://community.deeplearning.ai/t/ex-4-and-5-nlp-course-2-assignment-4-of-week-4/304379/9 "2023-10-09T03:52:27Z")

</div>

Also, the formula for gradient of b2 is missing in the slide in the latest version of the video.  
I could not find it in the lecture notes as well.
