def dropout(state_before, is_train, trng):
"""
dropout with p=0.5
Parameters
----------
state_before : theano 3d tensor, input data, dimensions: (num of time steps, batch size, dim of vector)
is_train : theano shared scalar, 0. = test/valid, 1. = train,
trng : random number generator
Returns
-------
proj : theano 3d tensor, output data, dimensions: (num of time steps, batch size, dim of vector)
"""
proj = tensor.switch(is_train,
state_before * trng.binomial(state_before.shape, p=0.5, n=1, dtype=state_before.dtype),
state_before * 0.5)
return proj
评论列表
文章目录