Exercise 4 - w4_unittest.test_back_prop(back_prop) is wrong

I was making my mistake in calculating grad_b1 and grad_b2.

For grad_b1 I was doing it like this,
grad_b1 = np.sum((1/batch_size)*np.dot(l1,x.T),axis=1,keepdims=True).

But I actually had to take the sum of l1 along the rows and then divide by batch_size. Hope this will help you

1 Like

I found my mistake. This post can be deleted.

hi bro i am still unable to find the solution so can you share me your code plssss

I’m not get it, could u plz expand it or just mention that grade_b1 line code plz

@Mubsi , Hi , I have tried programming exercises of NLP Course 2 and got some errors in Week 3 and Week 4.
For Week 4, Exercise 4 - back_prop, I am getting TypeError: only integer scalar arrays can be converted to a scalar index. Similarly for Exercise 5.
Please find my lab id and kindly help as I have only 2 days left for this week and have to do remaining courses by this month end. Thanks
zdyjykxmukbm

Hi @Riddhima_Sobti,

There were a few mistakes in your implementation.

Your calculation for grad_b1 and grad_b2 were incorrect.

As well as, for anyone else reading this, np.max is not the same as np.maximum. This is why you were getting the scalar related error @Riddhima_Sobti.

You can take a look at your notebook for more details.

Best,
Mubsi

1 Like

Thanks a lot for your help. I cannot express how thankful I am to you for resolving my queries so promptly.

1 Like

I still didn’t get the solution. can you help?

can you please share to me the code,
I am actually trying everything but it doesn’t work
I will be really grateful to you

Dear friends,
It is seems a lit confusing!

Wrote code for grad_b1 based on Video: (here is the screenshot from video)

Code

  1. Used np.sum(A, axis=1,keepdims=True)
  2. step(z1) => z1

Problem

Wrong output values for gradient of b1 vector.
	 Expected: [[ 0.56665733]
 [ 0.46268776]
 [ 0.1063147 ]
 [-0.17481454]
 [ 0.11041817]
 [ 0.32025188]
 [-0.51827161]
 [ 0.08430878]
 [ 0.19341   ]
 [ 0.08339139]
 [-0.35949678]
 [-0.13053946]
 [ 0.19055422]
 [ 0.56405985]
 [ 0.13321988]] 
	Got: [[ 0.46004568]
 [ 0.40483404]
 [ 0.07318845]
 [-0.0995559 ]
 [ 0.01777417]
 [ 0.14951921]
 [-0.17889287]
 [ 0.01897284]
 [ 0.11459772]
 [ 0.02604062]
 [-0.32940889]
 [-0.11874333]
 [ 0.04899498]
 [ 0.06254933]
 [ 0.02570647]].
Wrong output values for gradient of b1 vector.
	 Expected: [[ 0.01864644]
 [-0.31966546]
 [-0.3564441 ]
 [-0.31703253]
 [-0.26702975]
 [ 0.14815984]
 [ 0.25794505]
 [ 0.24893135]
 [ 0.05895103]
 [-0.15348205]] 
	Got: [[ 0.0183693 ]
 [-0.25618039]
 [-0.01923447]
 [-0.06038765]
 [-0.12080929]
 [ 0.10414779]
 [ 0.08565018]
 [ 0.0896111 ]
 [ 0.05432164]
 [-0.14636517]].
 14  Tests passed
 2  Tests failed

Looking forward for your advices and directions!

Sardor

If I understand you correctly, you may be doing the Relu check AFTER the np.sum step while my understanding is that it needs to be done before the sum step.

Good luck.

@Mubsi Hi , I am getting error with week4 back_prop function can you please tell me what am i doing wrong lab id is jlqsufmomevo.
Thank You

Hi @OM_GAYDHANE,

Please share the error you are getting.

Thanks,
Mubsi




This is the error @Mubsi , please help me in finding where did I go wrong.

Hi @OM_GAYDHANE

It looks like you have a similar error as in this post . Please check the suggested solution.

Cheers

Hi @arvyzukai , I tried following that solution but do not seem to find the solution please guide me.