layers.py 文件源码

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

项目:Relation-Network 作者: subercui 项目源码 文件源码
def __init__(self, input, n_in, n_out, prefix='Logist'):

        # initialize with 0 the weights W as a matrix of shape (n_in, n_out)
        self.W = param_init().uniform((n_in, n_out), name=_p(prefix, 'W'))
        # initialize the baises b as a vector of n_out 0s
        self.b = param_init().constant((n_out,), name=_p(prefix, 'b'))

        # compute vector of class-membership probabilities in symbolic form
        energy = theano.dot(input, self.W) + self.b
        if energy.ndim == 3:
            energy_exp = T.exp(energy - T.max(energy, 2, keepdims=True))
            pmf = energy_exp / energy_exp.sum(2, keepdims=True)
        else:
            pmf = T.nnet.softmax(energy)

        self.p_y_given_x = pmf
        self.y_pred = T.argmax(self.p_y_given_x, axis=-1)

        # compute prediction as class whose probability is maximal in
        # symbolic form

        # parameters of the model
        self.params = [self.W, self.b]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号