MCPcopy Create free account
hub / github.com/WarmCongee/SDUMC / forward

Method forward

toolkit/models/mctn.py:107–126  ·  view source on GitHub ↗
(self, dec_input, s, join)

Source from the content-addressed store, hash-verified

105 self.dropout = nn.Dropout(dropout)
106
107 def forward(self, dec_input, s, join):
108 dec_input = dec_input.unsqueeze(1).transpose(0, 1)
109 a = self.attention(s, join).unsqueeze(1)
110 # join
111 join = join.transpose(0, 1)
112 c = torch.bmm(a, join).transpose(0, 1)
113 rnn_input = torch.cat((dec_input, c), dim = 2)
114 dec_output, dec_state = self.rnn(rnn_input)
115
116 if self.bidirectional:
117 dec_output = torch.add(dec_output[:,:,:self.hidden_dim],dec_output[:,:,self.hidden_dim:])
118 h = torch.add(dec_state[0][-1],dec_state[0][-2])
119
120 dec_input = dec_input.squeeze(0)
121 dec_output = dec_output.squeeze(0)
122 c = c.squeeze(0)
123
124 pred = self.fc_out(torch.cat((dec_output, c), dim = 1))
125
126 return pred, h.squeeze(0)
127
128
129class MCTN(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected