Skip to content

Commit

Permalink
fixes #1: pytorch 0.3 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
loudinthecloud committed Feb 8, 2018
1 parent 7e7290a commit 5c5ce66
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ntm/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _address_memory(self, k, β, g, s, γ, w_prev):
k = k.clone()
β = F.softplus(β)
g = F.sigmoid(g)
s = F.softmax(F.softplus(s))
s = F.softmax(F.softplus(s), dim=0)
γ = 1 + F.softplus(γ)

w = self.memory.address(k, β, g, s, γ, w_prev)
Expand Down
5 changes: 2 additions & 3 deletions ntm/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def __init__(self, N, M):

# The memory bias allows the heads to learn how to initially address
# memory locations by content
self.mem_bias = Variable(torch.Tensor(N, M))
self.register_buffer('mem_bias', self.mem_bias.data)
self.register_buffer('mem_bias', Variable(torch.Tensor(N, M)))

# Initialize memory bias
stdev = 1 / (np.sqrt(N + M))
Expand Down Expand Up @@ -84,7 +83,7 @@ def address(self, k, β, g, s, γ, w_prev):

def _similarity(self, k, β):
k = k.view(self.batch_size, 1, -1)
w = F.softmax(β * F.cosine_similarity(self.memory + 1e-16, k + 1e-16, dim=-1))
w = F.softmax(β * F.cosine_similarity(self.memory + 1e-16, k + 1e-16, dim=-1), dim=0)
return w

def _interpolate(self, w_prev, wc, g):
Expand Down

0 comments on commit 5c5ce66

Please sign in to comment.