Skip to content

Instantly share code, notes, and snippets.

@llSourcell
Created August 7, 2018 20:12
Show Gist options
  • Select an option

  • Save llSourcell/8a8b5b593bdf0b77bed3ee33130256ca to your computer and use it in GitHub Desktop.

Select an option

Save llSourcell/8a8b5b593bdf0b77bed3ee33130256ca to your computer and use it in GitHub Desktop.
class NeuralAccumulatorCell(nn.Module):
#PyTorch Code for the NAC!
def __init__(self, in_dim, out_dim):
super().__init__()
self.in_dim = in_dim
self.out_dim = out_dim
self.W_hat = Parameter(torch.Tensor(out_dim, in_dim))
self.M_hat = Parameter(torch.Tensor(out_dim, in_dim))
self.W = Parameter(F.tanh(self.W_hat) * F.sigmoid(self.M_hat))
self.register_parameter('bias', None)
init.kaiming_uniform_(self.W_hat, a=math.sqrt(5))
init.kaiming_uniform_(self.M_hat, a=math.sqrt(5))
def forward(self, input):
return F.linear(input, self.W, self.bias)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment