def get_costs(self, probs, y, y_mask,
decay_cs=None, opt_rets=None):
"""
probs : dict, mapping cg_name to probabilities
y : theano tensor variable
y_mask : theano tensor variable
decay_cs : list of l2 regularization weights
opt_rets : dict, mapping cg_name to optional returned variables
"""
costs = self.decoder.costs(probs, y, y_mask)
if decay_cs is not None:
for name, cost in costs.iteritems():
if decay_cs[name] > 0.:
decay_c = theano.shared(numpy.float32(decay_cs[name]),
name='decay_c')
weight_decay = 0.
for pp in ComputationGraph(cost).parameters:
weight_decay += (pp ** 2).sum()
weight_decay *= decay_c
costs[name] += weight_decay
costs[name].name = name
return costs
评论列表
文章目录