mixer.py 文件源码

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

项目:dl4mt-c2c 作者: nyu-dl 项目源码 文件源码
def conv_encoder(tparams, state_below, options, prefix='conv_enc',
          one_step=False, init_state=None, width=None, nkernels=None, pool_window=None, pool_stride=None, **kwargs):
    # state_below : maxlen X n_samples X dim_word_src
    # mask : maxlen X n_samples
    # data = (n_samples, dim, maxlen, 1)
    # kernel = (nkernels, dim, width, 1)

    maxlen = state_below.shape[0]
    n_samples = state_below.shape[1]
    dim = state_below.shape[2]

    data = state_below.dimshuffle(1,2,0,'x')
    # data : n_samples X dim X maxlen X 1

    W = tparams[_p(prefix, 'convW')]
    b = tparams[_p(prefix, 'convB')]

    #conv_out = dnn_conv(data, W, border_mode='valid', subsample=(stride,1), precision='float32')
    output = dnn_conv(data, W, border_mode='half', precision='float32')
    #conv_out = conv2d(data, W, border_mode='valid')
    #conv_out = conv2d(data, W, input_shape=(8, 256, 450, 1), filter_shape=(64, 1, 4, 1), border_mode='valid')

    if curr_width % 2 == 0:
        output = output[:,:,:-1,:]

    output = tensor.nnet.relu(output + b.dimshuffle('x',0,'x','x'))

    output = dnn_pool(output, (pool_window, 1), stride=(pool_stride, 1), mode='max', pad=(0, 0))

    #output = tensor.nnet.sigmoid(conv_out)
    # output : n_samples X nkernels X (maxlen-width+1) X 1

    #output = output.dimshuffle(2,0,1,3).squeeze()
    output = output.dimshuffle(2,0,1,3)[:,:,:,0]
    # NOTE : when we pass 1 or 2 instead of 0, get IndexError: index out of bounds
    # not sure why squeeze wouldn't work though

    # output : (maxlen-width+1) X n_samples X nkernels 

    return output
    # emb : maxlen X n_samples X dim_word_src
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号