From cd49983a17c8d54b36df5225d9140960306b1f71 Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 11:41:19 +0800 Subject: [PATCH 1/2] Update root_teminal_predictor.py --- models/root_teminal_predictor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models/root_teminal_predictor.py b/models/root_teminal_predictor.py index 19f90f1..a1c27be 100644 --- a/models/root_teminal_predictor.py +++ b/models/root_teminal_predictor.py @@ -14,15 +14,15 @@ def __init__(self, N_word, N_h, N_depth, gpu, use_hs): self.gpu = gpu self.use_hs = use_hs - self.q_lstm = nn.LSTM(input_size=N_word, hidden_size=N_h/2, + self.q_lstm = nn.LSTM(input_size=N_word, hidden_size=int(N_h/2), num_layers=N_depth, batch_first=True, dropout=0.3, bidirectional=True) - self.hs_lstm = nn.LSTM(input_size=N_word, hidden_size=N_h/2, + self.hs_lstm = nn.LSTM(input_size=N_word, hidden_size=int(N_h/2), num_layers=N_depth, batch_first=True, dropout=0.3, bidirectional=True) - self.col_lstm = nn.LSTM(input_size=N_word, hidden_size=N_h/2, + self.col_lstm = nn.LSTM(input_size=N_word, hidden_size=int(N_h/2), num_layers=N_depth, batch_first=True, dropout=0.3, bidirectional=True) @@ -81,7 +81,10 @@ def forward(self, q_emb_var, q_len, hs_emb_var, hs_len, col_emb_var, col_len, co def loss(self, score, truth): loss = 0 data = torch.from_numpy(np.array(truth)) - truth_var = Variable(data.cuda()) + if self.gpu: + truth_var = Variable(data.cuda()) + else: + truth_var = Variable(data) loss = self.CE(score, truth_var) return loss From 96aaa524da7bfb01c4016e8b15d02c594b53e547 Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 14:56:07 +0800 Subject: [PATCH 2/2] Update root_teminal_predictor.py --- models/root_teminal_predictor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/root_teminal_predictor.py b/models/root_teminal_predictor.py index a1c27be..0543141 100644 --- a/models/root_teminal_predictor.py +++ b/models/root_teminal_predictor.py @@ -33,7 +33,7 @@ def __init__(self, N_word, N_h, N_depth, gpu, use_hs): self.rt_out_c = nn.Linear(N_h, N_h) self.rt_out = nn.Sequential(nn.Tanh(), nn.Linear(N_h, 2)) #for 2 operators - self.softmax = nn.Softmax() #dim=1 + self.softmax = nn.Softmax(dim=1) #dim=1 self.CE = nn.CrossEntropyLoss() self.log_softmax = nn.LogSoftmax() self.mlsml = nn.MultiLabelSoftMarginLoss()