Skip to content

Instantly share code, notes, and snippets.

@1pha
Created December 9, 2020 07:37
Show Gist options
  • Save 1pha/605ea9571998dfaede0b7610ad1e2de8 to your computer and use it in GitHub Desktop.
Save 1pha/605ea9571998dfaede0b7610ad1e2de8 to your computer and use it in GitHub Desktop.
L2 Regularization in PyTorch
_lambda = 0.0005
l2_reg = torch.tensor(0.)
for param in model.parameters():
l2_reg += torch.norm(param)
loss += lamb * l2_reg
@1pha
Copy link
Author

1pha commented Dec 9, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment