Open ankur6ue opened 7 years ago
one small typo: the reduce_mean should be a reduce_sum as L2 normalization doesn't take an average over the weights..
For L2 regularization the learners support it natively. Check for example: https://cntk.ai/pythondocs/cntk.learners.html?highlight=regularization#cntk.learners.sgd
Hello, I'm attempting to add L2 regularization on the network weights to the softmax with cross entropy loss function. Here's my implementation:
def cross_entropy_plus_softmax_with_regularization(model, labels, l2_regularization_weight): w_norm = C.Constant(0); for p in (model.parameters): w_norm = C.plus(w_norm, 0.5*C.reduce_mean(C.square(p)))
Does this look correct? It appears to work.. The whole symbol expression API is pretty wonky and takes some getting used to.
Thanks, Ankur