__init__.py 文件源码

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

项目:theanomodels 作者: clinicalml 项目源码 文件源码
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'
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号