def f_log_probs(self, probs, x, x_mask, y, y_mask,
src_selector, trg_selector, cg=None):
y_flat = y.flatten()
y_flat_idx = tensor.arange(y_flat.shape[0]) * self.vocab_size + y_flat
cost = -tensor.log(probs.flatten()[y_flat_idx])
cost = cost.reshape([y.shape[0], y.shape[1]])
cost = (cost * y_mask).sum(0)
func_inps = [x, x_mask, y, y_mask, src_selector, trg_selector]
return theano.function(
inputs=func_inps,
outputs=cost, on_unused_input='warn')
评论列表
文章目录