MCPcopy Create free account
hub / github.com/pytorch/tutorials / forward

Method forward

beginner_source/chatbot_tutorial.py:663–675  ·  view source on GitHub ↗
(self, input_seq, input_lengths, hidden=None)

Source from the content-addressed store, hash-verified

661 dropout=(0 if n_layers == 1 else dropout), bidirectional=True)
662
663 def forward(self, input_seq, input_lengths, hidden=None):
664 # Convert word indexes to embeddings
665 embedded = self.embedding(input_seq)
666 # Pack padded batch of sequences for RNN module
667 packed = nn.utils.rnn.pack_padded_sequence(embedded, input_lengths)
668 # Forward pass through GRU
669 outputs, hidden = self.gru(packed, hidden)
670 # Unpack padding
671 outputs, _ = nn.utils.rnn.pad_packed_sequence(outputs)
672 # Sum bidirectional GRU outputs
673 outputs = outputs[:, :, :self.hidden_size] + outputs[:, : ,self.hidden_size:]
674 # Return output and final hidden state
675 return outputs, hidden
676
677
678######################################################################

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected