Pytorch GRU/LSTM 权重参数初始化


pytorch模型训练表现不佳, 很有可能是参数初始化的问题

GRU weights采用正交初始化, bias采用0初始化

       self.gru = nn.GRU(10, 20, 2, dropout=0.2, bidirectional=True)
        # use orthogonal init for GRU layer0 weights
        weight_init.orthogonal(self.gru.weight_ih_l0)
        weight_init.orthogonal(self.gru.weight_hh_l0)
        # use zero init for GRU layer0 bias
        self.gru.bias_ih_l0.zero_()
        self.gru.bias_hh_l0.zero_()

 

self.gru.bias_ih_l0.zero_()
--> RunTime Error: A leaf Variable that requires grad has been used in an inplace operation. ???

>>> self.gru.bias_ih_l0.is_leaf
>>> True

>>> import torch.nn.parameter.Parameter as parameter
>>> self.gru.bias_ih_l0 = parameter(torch.zeros_like(self.gru.bias_ih_l0))





免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM