Fix HAN for batch_size 1 (#161)

This commit is contained in:
Ashutosh-Adhikari
2018-11-09 21:37:49 -05:00
committed by Ralph Tang
parent 97bdaec5bb
commit 3dd3ced661
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ class SentLevelRNN(nn.Module):
sentence_h,_ = self.sentence_GRU(x)
x = torch.tanh(self.sentence_linear(sentence_h))
x = torch.matmul(x, self.sentence_context_wghts)
x = x.squeeze()
x = x.squeeze(dim=2)
x = self.soft_sent(x.transpose(1,0))
x = torch.mul(sentence_h.permute(2,0,1), x.transpose(1,0))
x = torch.sum(x,dim = 1).transpose(1,0).unsqueeze(0)
+1 -1
View File
@@ -41,7 +41,7 @@ class WordLevelRNN(nn.Module):
h,_ = self.GRU(x)
x = torch.tanh(self.linear(h))
x = torch.matmul(x, self.word_context_wghts)
x = x.squeeze()
x = x.squeeze(dim=2)
x = self.soft_word(x.transpose(1,0))
x = torch.mul(h.permute(2,0,1), x.transpose(1,0))
x = torch.sum(x, dim = 1).transpose(1,0).unsqueeze(0)