classifier.py 文件源码

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

项目:neural-semantic-role-labeler 作者: hiroki13 项目源码 文件源码
def get_y_prob(self, h, y):
        """
        :param h: 1D: n_words, 2D: Batch, 3D: n_y
        :param y: 1D: n_words, 2D: Batch
        :return: gradient of cross entropy: 1D: Batch
        """
        batch_index = T.arange(h.shape[1])
        z_score0 = self.BOS + h[0]  # 1D: batch, 2D: n_y
        y_score0 = z_score0[batch_index, y[0]]  # 1D: batch

        [_, y_scores, z_scores], _ = theano.scan(fn=self._forward_step,
                                                 sequences=[h[1:], y[1:]],
                                                 outputs_info=[y[0], y_score0, z_score0],
                                                 non_sequences=[self.W_t, batch_index])

        y_score = y_scores[-1]
        z_score = logsumexp(z_scores[-1], axis=1).flatten()

        return y_score - z_score
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号