From 1b1d9992d06601278a3249a206891fe6fb5b8b9f Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 11:36:00 +0800 Subject: [PATCH 1/2] Update having_predictor.py --- models/having_predictor.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/models/having_predictor.py b/models/having_predictor.py index 3d4bb72..7400faa 100644 --- a/models/having_predictor.py +++ b/models/having_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 a87591db70d37bcbde53f9242f1217fc1050be50 Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 14:59:03 +0800 Subject: [PATCH 2/2] Update having_predictor.py --- models/having_predictor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/having_predictor.py b/models/having_predictor.py index 7400faa..5ed6d9f 100644 --- a/models/having_predictor.py +++ b/models/having_predictor.py @@ -33,7 +33,7 @@ def __init__(self, N_word, N_h, N_depth, gpu, use_hs): self.hv_out_c = nn.Linear(N_h, N_h) self.hv_out = nn.Sequential(nn.Tanh(), nn.Linear(N_h, 2)) #for having/none - 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() @@ -81,6 +81,7 @@ 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)) + data = torch._cast_Long(data) if self.gpu: truth_var = Variable(data.cuda()) else: