def _getLSTMWeight(self, shape):
"""
http://yyue.blogspot.com/2015/01/a-brief-overview-of-deep-learning.html
For LSTMs, use orthogonal initializations for the weight matrices and
set the forget gate biases to be high
"""
if len(shape)==1: #bias
dim = int(shape[0]/4)
self._p('Sampling biases for LSTM from exponential distribution')
return np.random.laplace(size=shape).astype(config.floatX)
#return np.concatenate([self._getUniformWeight((dim,)),np.ones((dim,))*self.params['forget_bias'],
# self._getUniformWeight((dim*2,))]).astype(config.floatX)
elif len(shape)==2: #weight
nin = shape[0]
nout= shape[1]
assert int(nout/4)==nin,'Not LSTM weight.'
return np.concatenate([self._getOrthogonalWeight((nin,int(nout/4))),
self._getOrthogonalWeight((nin,int(nout/4))),
self._getOrthogonalWeight((nin,int(nout/4))),
self._getOrthogonalWeight((nin,int(nout/4)))]
,axis=1).astype(config.floatX)
else:
assert False,'Should not get here'
评论列表
文章目录