Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question on two_layer_net #9

Closed
huangzl19 opened this issue Mar 14, 2021 · 3 comments
Closed

A question on two_layer_net #9

huangzl19 opened this issue Mar 14, 2021 · 3 comments

Comments

@huangzl19
Copy link

huangzl19 commented Mar 14, 2021

Hello! First great thanks to your brilliant answers of these assignments. It really helps me a lot!

I would like to ask a question in neural_net.py. When db1 is calculated, I noticed that 2 * reg * b1 hasn't been added. db2 has the the same problem. The original code is as below.

# Backprop dRelu1 to calculate db1. db1 = dRelu1 * 1 grads['b1'] = np.sum(db1, axis=0)

However, according to the forward process, when calculating the loss we have added reg * np.sum(b1 * b1). The original code is as below.

loss += reg * (np.sum(W1*W1) + np.sum(W2*W2) + np.sum(b1*b1) + np.sum(b2*b2))

Is this part missing during back propogation? I add the 2 * reg * b1 to my code, and the analytic gradients is still less than 1e-8 for b1, and b2.

@Burton2000
Copy link
Owner

Good spot thank you!

Looking at the notes again I believe we should not typically include the bias term when we do L2 regularization (From what is also said in the notes it probably has a negligible effect if we do or do not regularize biases).

But you are right that if we do include them in regularization we should also include the regularization terms in the backprop.
I will update the code to not include the bias terms in the L2 regularization so we dont need to backprop it.

@Burton2000
Copy link
Owner

Done

@xzh-scut
Copy link

where is my comment? it disappera???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants