Complete the code to add L2 regularization (weight decay) to the optimizer.
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, weight_decay=[1])
Weight decay is set by the weight_decay parameter in the optimizer. A small positive value like 0.001 applies L2 regularization.
Complete the code to create an SGD optimizer with learning rate 0.1 and weight decay 0.01.
optimizer = torch.optim.SGD(model.parameters(), lr=[1], weight_decay=[2])
The learning rate is set with lr to 0.1 (D) and weight decay with weight_decay to 0.01 (A).
Fix the error in the optimizer creation by filling the correct weight decay value.
optimizer = torch.optim.Adam(model.parameters(), lr=0.001, weight_decay=[1])
Weight decay must be a positive float number. Negative or string values cause errors.
Fill both blanks to create an Adam optimizer with learning rate 0.0005 and weight decay 0.0001.
optimizer = torch.optim.Adam(model.parameters(), lr=[1], weight_decay=[2])
The learning rate is 0.0005 and weight decay is 0.0001 as specified.
Fill all three blanks to create an SGD optimizer with momentum 0.9, learning rate 0.01, and weight decay 0.0005.
optimizer = torch.optim.SGD(model.parameters(), momentum=[1], lr=[2], weight_decay=[3])
Momentum is 0.9, learning rate is 0.01, and weight decay is 0.0005 as required.