From 7b3043a7ec676d0bd22ed3e93e98735f16ee76a5 Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 11:30:25 +0800 Subject: [PATCH 1/2] Update agg_predictor.py --- models/agg_predictor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/models/agg_predictor.py b/models/agg_predictor.py index f27685b..27ad50a 100644 --- a/models/agg_predictor.py +++ b/models/agg_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) From 506a9dd6982da0fb20bd69e2c902cb5c6e07d63b Mon Sep 17 00:00:00 2001 From: Tong Guo <779222056@qq.com> Date: Tue, 29 Oct 2019 15:03:39 +0800 Subject: [PATCH 2/2] Update agg_predictor.py --- models/agg_predictor.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/models/agg_predictor.py b/models/agg_predictor.py index 27ad50a..0f5b981 100644 --- a/models/agg_predictor.py +++ b/models/agg_predictor.py @@ -40,7 +40,7 @@ def __init__(self, N_word, N_h, N_depth, gpu, use_hs): self.agg_out_c = nn.Linear(N_h, N_h) self.agg_out = nn.Sequential(nn.Tanh(), nn.Linear(N_h, 5)) #for 1-5 aggregators - 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() @@ -113,7 +113,11 @@ def loss(self, score, truth): #loss for the column number truth_num = [len(t) for t in truth] # double check truth format and for test cases data = torch.from_numpy(np.array(truth_num)) - truth_num_var = Variable(data.cuda()) + data = torch._cast_Long(data) + if self.gpu: + truth_num_var = Variable(data.cuda()) + else: + truth_num_var = Variable(data) loss += self.CE(agg_num_score, truth_num_var) #loss for the key words T = len(agg_score[0]) @@ -121,7 +125,10 @@ def loss(self, score, truth): for b in range(B): truth_prob[b][truth[b]] = 1 data = torch.from_numpy(truth_prob) - truth_var = Variable(data.cuda()) + if self.gpu: + truth_var = Variable(data.cuda()) + else: + truth_var = Variable(data) #loss += self.mlsml(agg_score, truth_var) #loss += self.bce_logit(agg_score, truth_var) # double check no sigmoid pred_prob = self.sigm(agg_score)