how to add L2 regulazation to cost function pytorch?
I try add L1 and L2 regulazation in my Loss function. But I fail.
My code:
criterion = nn.NLLLoss() + nn.L1Loss()
it should be perfect for something like this:
criterion = nn.NLLLoss() + _lambda * nn.L1Loss()
How can i do it?

You need to first instantiate them both and them add them. they both expect two arguments :

nll_loss = nn.NLLLoss()
l1_loss = nn.L1Loss()
loss = nll_loss(x, y) + _lambda * l1_loss(x, y) 

