How does one implement Weight regularization (l1 or l2) manually without optimum?

Is it possible to replace

batch_loss = (1/N_train)*(y_pred - batch_ys).pow(2).sum() + l2_reg * reg_lambda

with

batch_loss = MSEloss(y_pred, batch_ys) + l2_reg * reg_lambda

Thanks!

1 Like