model.py 文件源码

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

项目:teras 作者: chantera 项目源码 文件源码
def __call__(self, x, hs):
        batch, dim = x.shape
        alphas = 0
        _sum = 0
        for h in F.transpose_sequence(hs[:batch]):
            size = h.shape[0]
            if size < batch:
                h = F.vstack([h, variable.Variable(
                    self.xp.zeros((batch - size, h.shape[1]), dtype='f'))])
            score = self._score_func(x, h)
            e = F.exp(score)
            _sum += e
            alphas += batch_matmul(h, e)
        c = F.reshape(batch_matmul(F.reshape(alphas, (batch, dim)),
                                   (1 / _sum)), (batch, dim))
        return c
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号