Created
December 9, 2020 07:37
-
-
Save 1pha/605ea9571998dfaede0b7610ad1e2de8 to your computer and use it in GitHub Desktop.
L2 Regularization in PyTorch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_lambda = 0.0005 | |
l2_reg = torch.tensor(0.) | |
for param in model.parameters(): | |
l2_reg += torch.norm(param) | |
loss += lamb * l2_reg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Stackoverflow