dense.py 文件源码

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

项目:SNLI 作者: qiaojingy 项目源码 文件源码
def get_output_for(self, inputs, **kwargs):
        sequence_length = inputs[0].shape[1]/2
        input_first = inputs[0][(slice(None),) + (slice(0, sequence_length),)]
        input_second = inputs[1]


        mask = inputs[self.mask_incoming_index]

        if input_second.ndim == 3:
            input_second = input_second[(slice(None), -1)]

        M = nonlinearities.tanh(T.dot(input_first, self.W_y) + T.dot(input_second.dimshuffle(0, 'x', 1), self.W_h))
        # M.shape = N * L * k
        alpha = nonlinearities.softmax(T.dot(M, self.w.T).reshape((inputs[0].shape[0], sequence_length)))
        # alpha.shape = N * L
        alpha = alpha * mask
        r = T.batched_dot(alpha, input_first)
        # r.shape = N * k
        h_star = nonlinearities.tanh(T.dot(r, self.W_p) + T.dot(input_second, self.W_x))
        return h_star
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号