models.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:dl4mt-multi 作者: nyu-dl 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号