context_models.py 文件源码

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

项目:context2vec 作者: orenmel 项目源码 文件源码
def _calculate_loss(self, sent):
        # sent is a batch of sentences.
        sent_arr = self.xp.asarray(sent, dtype=np.int32)

        sent_y = self._contexts_rep(sent_arr)

        sent_x = []
        for i in range(sent_arr.shape[1]):
            x = chainer.Variable(sent_arr[:,i])
            sent_x.append(x)

        accum_loss = None
        for y,x in izip(sent_y, sent_x):
            loss = self.loss_func(y, x)
            accum_loss = accum_loss + loss if accum_loss is not None else loss 

        return accum_loss
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号