Skip to content

Instantly share code, notes, and snippets.

@adamoudad
Created March 20, 2021 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamoudad/9ae2075c8d2f24683a29d65adf36fe71 to your computer and use it in GitHub Desktop.
Save adamoudad/9ae2075c8d2f24683a29d65adf36fe71 to your computer and use it in GitHub Desktop.
def init_weights(self):
self.encoder.weight.data.uniform_(-0.5, 0.5)
ih = (param.data for name, param in self.named_parameters() if 'weight_ih' in name)
hh = (param.data for name, param in self.named_parameters() if 'weight_hh' in name)
b = (param.data for name, param in self.named_parameters() if 'bias' in name)
for t in ih:
nn.init.xavier_uniform(t)
for t in hh:
nn.init.orthogonal(t)
for t in b:
nn.init.constant(t, 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment