x : (batch_size, sequence_len, in_size)
(self, x, lengths)
| 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 | |
| 40 | class Attention(nn.Module): # Attention layer of decoder |
nothing calls this directly
no outgoing calls
no test coverage detected