(self, tgt, memory_bank, state, memory_lengths=None)
return hidden, decoder_outputs, attns
See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
See StdRNNDecoder . _run_forward_pass () for description of arguments and return values .
def _run_forward_pass(self, tgt, memory_bank, state, memory_lengths=None):
        """
        See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
        """
        # Additional args check.
        input_feed = state.input_feed.squeeze(0)
        # print("input feed size: {}\n".format(input_feed.size()))
        input_feed_batch, _ = input_feed.size()
        _, tgt_batch, _ = tgt.size()
        aeq(tgt_batch, input_feed_batch)
        # END Additional args check.

        # Initialize local and return variables.
        decoder_outputs = []
        attns = {"std": []}
        if self._copy:
            attns["copy"] = []
        if self._coverage:
            attns["coverage"] = []

        emb = self.embeddings(tgt)
        assert emb.dim() == 3  # len x batch x embedding_dim

        hidden = state.hidden
        coverage = state.coverage.squeeze(0) \
            if state.coverage is not None else None

        # Input feed concatenates hidden state with
        # input at every time step.
        #pdb.set_trace()
        #print("emb size: {}\n".format(emb.size()));exit()
        for _, emb_t in enumerate(emb.split(1)):
            emb_t = emb_t.squeeze(0)
            decoder_input = torch.cat([emb_t, input_feed], 1)

            rnn_output, hidden = self.rnn(decoder_input, hidden)
            decoder_output, p_attn = self.attn(
                rnn_output,
                memory_bank.transpose(0, 1),
                memory_lengths=memory_lengths)
            if self.context_gate is not None:
                # TODO: context gate should be employed
                # instead of second RNN transform.
                decoder_output = self.context_gate(
                    decoder_input, rnn_output, decoder_output
                )
            decoder_output = self.dropout(decoder_output)
            input_feed = decoder_output

            decoder_outputs += [decoder_output]
            attns["std"] += [p_attn]

            # Update the coverage attention.
            if self._coverage:
                coverage = coverage + p_attn \
                    if coverage is not None else p_attn
                attns["coverage"] += [coverage]

            # Run the forward pass of the copy attention layer.
            if self._copy and not self._reuse_copy_attn:
                _, copy_attn = self.copy_attn(decoder_output,
                                              memory_bank.transpose(0, 1))
                attns["copy"] += [copy_attn]
            elif self._copy:
                attns["copy"] = attns["std"]
        # Return result.
        return hidden, decoder_outputs, attns
def _run_forward_pass ( self , tgt , memory_bank , state , memory_lengths = None ) : # Additional args check. input_feed = state . input_feed . squeeze ( 0 ) # print("input feed size: {}\n".format(input_feed.size())) input_feed_batch , _ = input_feed . size ( ) _ , tgt_batch , _ = tgt . size ( ) aeq ( tgt_batch , input_feed_batch ) # END Additional args check. # Initialize local and return variables. decoder_outputs = [ ] attns = { "std" : [ ] } if self . _copy : attns [ "copy" ] = [ ] if self . _coverage : attns [ "coverage" ] = [ ] emb = self . embeddings ( tgt ) assert emb . dim ( ) == 3 # len x batch x embedding_dim hidden = state . hidden coverage = state . coverage . squeeze ( 0 ) if state . coverage is not None else None # Input feed concatenates hidden state with # input at every time step. #pdb.set_trace() #print("emb size: {}\n".format(emb.size()));exit() for _ , emb_t in enumerate ( emb . split ( 1 ) ) : emb_t = emb_t . squeeze ( 0 ) decoder_input = torch . cat ( [ emb_t , input_feed ] , 1 ) rnn_output , hidden = self . rnn ( decoder_input , hidden ) decoder_output , p_attn = self . attn ( rnn_output , memory_bank . transpose ( 0 , 1 ) , memory_lengths = memory_lengths ) if self . context_gate is not None : # TODO: context gate should be employed # instead of second RNN transform. decoder_output = self . context_gate ( decoder_input , rnn_output , decoder_output ) decoder_output = self . dropout ( decoder_output ) input_feed = decoder_output decoder_outputs += [ decoder_output ] attns [ "std" ] += [ p_attn ] # Update the coverage attention. if self . _coverage : coverage = coverage + p_attn if coverage is not None else p_attn attns [ "coverage" ] += [ coverage ] # Run the forward pass of the copy attention layer. if self . _copy and not self . _reuse_copy_attn : _ , copy_attn = self . copy_attn ( decoder_output , memory_bank . transpose ( 0 , 1 ) ) attns [ "copy" ] += [ copy_attn ] elif self . _copy : attns [ "copy" ] = attns [ "std" ] # Return result. return hidden , decoder_outputs , attns