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

Method forward

toolkit/models/mctn.py:23–37  ·  view source on GitHub ↗

x : (batch_size, sequence_len, in_size)

(self, x, lengths)

Source from the content-addressed store, hash-verified

21 self.fc = nn.Linear(hidden_dim, hidden_dim, bias = False)
22
23 def forward(self, x, lengths):
24 '''
25 x : (batch_size, sequence_len, in_size)
26 '''
27 enc_output, enc_state = self.rnn(x)
28 if self.bidirectional:
29 h = self.dropout(torch.add(enc_output[:,:,:self.hidden_dim],enc_output[:,:,self.hidden_dim:]))
30 else:
31 h = self.dropout(enc_state[0].squeeze())
32 join = h
33 # encoder RNNs fed through a linear layer
34 # s = [batch_size, dec_hidden_dim]
35 s = torch.tanh(self.fc(torch.add(enc_state[0][-1],enc_state[0][-2]))) ####
36
37 return join, s
38
39
40class Attention(nn.Module): # Attention layer of decoder

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected