Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dataset in JSON format #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion codes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ def run(args):
len([y for x in test_idx for y in test_idx[x]])))
SAVE_PATH = args.save_path
tmp_path = 'checkpoint/'
os.mkdir(SAVE_PATH + tmp_path)
try:
os.mkdir(SAVE_PATH + tmp_path)
except:
pass
for epoch in range(parameters.epoch):
st = time.time()
if args.pretrain == 0:
Expand Down
28 changes: 14 additions & 14 deletions codes/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ def init_weights(self):
b = (param.data for name, param in self.named_parameters() if 'bias' in name)

for t in ih:
nn.init.xavier_uniform(t)
nn.init.xavier_uniform_(t)
for t in hh:
nn.init.orthogonal(t)
nn.init.orthogonal_(t)
for t in b:
nn.init.constant(t, 0)
nn.init.constant_(t, 0)

def forward(self, loc, tim):
h1 = Variable(torch.zeros(1, 1, self.hidden_size))
Expand All @@ -74,7 +74,7 @@ def forward(self, loc, tim):
out = self.dropout(out)

y = self.fc(out)
score = F.log_softmax(y) # calculate loss by NLLoss
score = F.log_softmax(y, dim=1) # calculate loss by NLLoss
return score


Expand Down Expand Up @@ -102,7 +102,7 @@ def forward(self, out_state, history):
for i in range(state_len):
for j in range(seq_len):
attn_energies[i, j] = self.score(out_state[i], history[j])
return F.softmax(attn_energies)
return F.softmax(attn_energies, dim=1)

def score(self, hidden, encoder_output):
if self.method == 'dot':
Expand Down Expand Up @@ -163,11 +163,11 @@ def init_weights(self):
b = (param.data for name, param in self.named_parameters() if 'bias' in name)

for t in ih:
nn.init.xavier_uniform(t)
nn.init.xavier_uniform_(t)
for t in hh:
nn.init.orthogonal(t)
nn.init.orthogonal_(t)
for t in b:
nn.init.constant(t, 0)
nn.init.constant_(t, 0)

def forward(self, loc, tim, history_loc, history_tim, history_count, uid, target_len):
h1 = Variable(torch.zeros(1, 1, self.hidden_size))
Expand Down Expand Up @@ -196,7 +196,7 @@ def forward(self, loc, tim, history_loc, history_tim, history_count, uid, target
count += c

history = torch.cat((loc_emb_history2, tim_emb_history2), 1)
history = F.tanh(self.fc_attn(history))
history = torch.tanh(self.fc_attn(history))

if self.rnn_type == 'GRU' or self.rnn_type == 'RNN':
out_state, h1 = self.rnn(x, h1)
Expand All @@ -214,7 +214,7 @@ def forward(self, loc, tim, history_loc, history_tim, history_count, uid, target
out = self.dropout(out)

y = self.fc_final(out)
score = F.log_softmax(y)
score = F.log_softmax(y, dim=1)

return score

Expand Down Expand Up @@ -263,11 +263,11 @@ def init_weights(self):
b = (param.data for name, param in self.named_parameters() if 'bias' in name)

for t in ih:
nn.init.xavier_uniform(t)
nn.init.xavier_uniform_(t)
for t in hh:
nn.init.orthogonal(t)
nn.init.orthogonal_(t)
for t in b:
nn.init.constant(t, 0)
nn.init.constant_(t, 0)

def forward(self, loc, tim, target_len):
h1 = Variable(torch.zeros(1, 1, self.hidden_size))
Expand Down Expand Up @@ -300,6 +300,6 @@ def forward(self, loc, tim, target_len):
out = self.dropout(out)

y = self.fc_final(out)
score = F.log_softmax(y)
score = F.log_softmax(y, dim=1)

return score