Python utils 模块,uniform_weight() 实例源码

我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用utils.uniform_weight()

项目:LM_GANS    作者:anirudh9119    | 项目源码 | 文件源码
def param_init_gru(options, param, prefix='gru', nin=None, dim=None):

    param[prefix + '_W'] = numpy.concatenate(
        [
            uniform_weight(nin, dim), uniform_weight(nin, dim)
        ],
        axis=1)
    param[prefix + '_U'] = numpy.concatenate(
        [
            ortho_weight(dim), ortho_weight(dim)
        ],
        axis=1)
    param[prefix + '_b'] = zero_vector(2 * dim)

    param[prefix + '_Wx'] = uniform_weight(nin, dim)
    param[prefix + '_Ux'] = ortho_weight(dim)
    param[prefix + '_bx'] = zero_vector(dim)

    return param
项目:sentence_classification    作者:zhegan27    | 项目源码 | 文件源码
def param_init_encoder(options, params, prefix='lstm_encoder'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    params[_p(prefix,'b')] = zero_bias(4*n_h)

    # It is observed that setting a high initial forget gate bias for LSTMs can 
    # give slighly better results (Le et al., 2015). Hence, the initial forget
    # gate bias is set to 3.
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)

    return params
项目:sentence_classification    作者:zhegan27    | 项目源码 | 文件源码
def param_init_encoder(options, params, prefix='gru_encoder'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix,'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix,'U')] = U

    params[_p(prefix,'b')] = zero_bias(2*n_h)

    Wx = uniform_weight(n_x, n_h)
    params[_p(prefix,'Wx')] = Wx

    Ux = ortho_weight(n_h)
    params[_p(prefix,'Ux')] = Ux

    params[_p(prefix,'bx')] = zero_bias(n_h)

    return params
项目:sentence_classification    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options,W):

    params = OrderedDict()
    # W is initialized by the pretrained word embedding
    params['Wemb'] = W.astype(config.floatX)
    # otherwise, W will be initialized randomly
    # n_words = options['n_words']
    # n_x = options['n_x'] 
    # params['Wemb'] = uniform_weight(n_words,n_x)

    length = len(options['filter_shapes'])
    for idx in range(length):
        params = param_init_encoder(options['filter_shapes'][idx],params,prefix=_p('cnn_encoder',idx))

    n_h = options['feature_maps'] * length
    params['Wy'] = uniform_weight(n_h,options['n_y'])
    params['by'] = zero_bias(options['n_y'])                                     

    return params
项目:sentence_classification    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options,W):

    n_h = options['n_h']
    n_y = options['n_y']

    params = OrderedDict()
    # W is initialized by the pretrained word embedding
    params['Wemb'] = W.astype(config.floatX)
    # otherwise, W will be initialized randomly
    # n_words = options['n_words']
    # n_x = options['n_x'] 
    # params['Wemb'] = uniform_weight(n_words,n_x)

    # bidirectional LSTM
    params = param_init_encoder(options,params,prefix="gru_encoder")
    params = param_init_encoder(options,params,prefix="gru_encoder_rev")

    params['Wy'] = uniform_weight(2*n_h,n_y)
    params['by'] = zero_bias(n_y)                                     

    return params
项目:sentence_classification    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options,W):

    n_h = options['n_h']
    n_y = options['n_y']

    params = OrderedDict()
    # W is initialized by the pretrained word embedding
    params['Wemb'] = W.astype(config.floatX)
    # otherwise, W will be initialized randomly
    # n_words = options['n_words']
    # n_x = options['n_x'] 
    # params['Wemb'] = uniform_weight(n_words,n_x)

    # bidirectional LSTM
    params = param_init_encoder(options,params,prefix="lstm_encoder")
    params = param_init_encoder(options,params,prefix="lstm_encoder_rev")

    params['Wy'] = uniform_weight(2*n_h,n_y)
    params['by'] = zero_bias(n_y)                                     

    return params
项目:textGAN_public    作者:dreasysnail    | 项目源码 | 文件源码
def param_init_encoder(options, params, prefix='encoder'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    params[_p(prefix,'b')] = zero_bias(4*n_h)
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)

    return params
项目:textGAN_public    作者:dreasysnail    | 项目源码 | 文件源码
def param_init_encoder(options, params, prefix='encoder'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    params[_p(prefix,'b')] = zero_bias(4*n_h)
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)

    return params
项目:Bayesian_RNN    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options,W):

    n_words = options['n_words']
    n_x = options['n_x']  
    n_h = options['n_h']

    params = OrderedDict()
    # word embedding
    # params['Wemb'] = uniform_weight(n_words,n_x)
    params['Wemb'] = W.astype(config.floatX)
    params = param_init_decoder(options,params)

    params['Vhid'] = uniform_weight(n_h,n_x)
    params['bhid'] = zero_bias(n_words)                                    

    return params
项目:Bayesian_RNN    作者:zhegan27    | 项目源码 | 文件源码
def param_init_encoder(options, params, prefix='lstm_encoder'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    params[_p(prefix,'b')] = zero_bias(4*n_h)

    # It is observed that setting a high initial forget gate bias for LSTMs can 
    # give slighly better results (Le et al., 2015). Hence, the initial forget
    # gate bias is set to 3.
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)

    return params
项目:Bayesian_RNN    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options):

    n_words = options['n_words']
    n_x = options['n_x']  
    n_h = options['n_h']

    params = OrderedDict()
    params['Wemb'] = uniform_weight(n_words,n_x)
    params = param_init_decoder(options,params,prefix='decoder_h1')

    options['n_x'] = n_h
    params = param_init_decoder(options,params,prefix='decoder_h2')
    options['n_x'] = n_x

    params['Vhid'] = uniform_weight(n_h,n_words)
    params['bhid'] = zero_bias(n_words)                                    

    return params
项目:Bayesian_RNN    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options,W):

    n_h = options['n_h']
    n_y = options['n_y']

    params = OrderedDict()
    # W is initialized by the pretrained word embedding
    params['Wemb'] = W.astype(config.floatX)
    # otherwise, W will be initialized randomly
    # n_words = options['n_words']
    # n_x = options['n_x'] 
    # params['Wemb'] = uniform_weight(n_words,n_x)

    # bidirectional LSTM
    params = param_init_encoder(options,params,prefix="lstm_encoder")
    params = param_init_encoder(options,params,prefix="lstm_encoder_rev")

    params['Wy'] = uniform_weight(2*n_h,n_y)
    params['by'] = zero_bias(n_y)                                     

    return params
项目:LM_GANS    作者:anirudh9119    | 项目源码 | 文件源码
def param_init_fflayer(options,
                       param,
                       prefix='ff',
                       nin=None,
                       nout=None,
                       ortho=True):

    param[prefix + '_W'] = uniform_weight(nin, nout)
    param[prefix + '_b'] = zero_vector(nout)

    return param
项目:rnn_music    作者:zhegan27    | 项目源码 | 文件源码
def param_init_decoder(options, params, prefix='decoder_gru'):

    n_x = options['n_x']
    n_h = options['n_h']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix,'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix,'U')] = U

    params[_p(prefix,'b')] = zero_bias(2*n_h)

    Wx = uniform_weight(n_x, n_h)
    params[_p(prefix,'Wx')] = Wx

    Ux = ortho_weight(n_h)
    params[_p(prefix,'Ux')] = Ux

    params[_p(prefix,'bx')] = zero_bias(n_h)

    params[_p(prefix,'b0')] = zero_bias(n_h)

    return params
项目:rnn_music    作者:zhegan27    | 项目源码 | 文件源码
def init_params(options):

    n_x = options['n_x']  
    n_h = options['n_h']

    params = OrderedDict()
    params = param_init_decoder(options,params)

    params['Vhid'] = uniform_weight(n_h,n_x)
    params['bhid'] = zero_bias(n_x)                                     

    return params
项目:textGAN_public    作者:dreasysnail    | 项目源码 | 文件源码
def param_init_decoder(options, params, prefix='decoder'):

    n_x = options['n_x']
    n_h = options['n_h']
    n_z = options['n_z']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    C = np.concatenate([uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h)], axis=1)
    params[_p(prefix,'C')] = C

    params[_p(prefix,'b')] = zero_bias(4*n_h)
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)


    C0 = uniform_weight(n_z, n_h)
    params[_p(prefix,'C0')] = C0

    params[_p(prefix,'b0')] = zero_bias(n_h)

    params[_p(prefix,'b_y')] = zero_bias(n_x)  # 48

    return params
项目:textGAN_public    作者:dreasysnail    | 项目源码 | 文件源码
def param_init_decoder(options, params, prefix='decoder'):

    n_x = options['n_x']
    n_h = options['n_h']
    n_z = options['n_z']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix, 'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix, 'U')] = U

    C = np.concatenate([uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h),
                        uniform_weight(n_z,n_h)], axis=1)
    params[_p(prefix,'C')] = C

    params[_p(prefix,'b')] = zero_bias(4*n_h)
    params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)


    C0 = uniform_weight(n_z, n_h)
    params[_p(prefix,'C0')] = C0

    params[_p(prefix,'b0')] = zero_bias(n_h)

    #params[_p(prefix,'b_y')] = zero_bias(n_x)  # 48

    return params
项目:Bayesian_RNN    作者:zhegan27    | 项目源码 | 文件源码
def param_init_decoder(options, params, prefix='decoder_lstm'):

    n_x = options['n_x']
    n_h = options['n_h']
    n_z = options['n_z']

    W = np.concatenate([uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h),
                        uniform_weight(n_x,n_h)], axis=1)
    params[_p(prefix,'W')] = W

    U = np.concatenate([ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h),
                        ortho_weight(n_h)], axis=1)
    params[_p(prefix,'U')] = U

    #C = np.concatenate([uniform_weight(n_z,n_h),
    #                    uniform_weight(n_z,n_h),
    #                    uniform_weight(n_z,n_h),
    #                    uniform_weight(n_z,n_h)], axis=1)
    #params[_p(prefix,'C')] = C

    params[_p(prefix,'b')] = zero_bias(4*n_h)
    #params[_p(prefix, 'b')][n_h:2*n_h] = 3*np.ones((n_h,)).astype(theano.config.floatX)

    C0 = uniform_weight(n_z, n_h)
    params[_p(prefix,'C0')] = C0

    params[_p(prefix,'b0')] = zero_bias(n_h)

    return params