(self, tgt, memory_bank, state, memory_lengths=None,sent_encoder=None,src_sents=None)
return hidden, decoder_outputs, attns
See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
        TODO: added a new param: sent_encoder, from model.py, this is the sentence matrix; add attns["mmr"] = [].
See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
        TODO: added a new param: sent_encoder, from model.py, this is the sentence matrix; add attns["mmr"] = [].
See StdRNNDecoder . _run_forward_pass () for description of arguments and return values . TODO : added a new param : sent_encoder from model . py this is the sentence matrix ; add attns [ mmr ] = [] .
def _run_forward_pass(self, tgt, memory_bank, state, memory_lengths=None,sent_encoder=None,src_sents=None):
        """
        See StdRNNDecoder._run_forward_pass() for description
        of arguments and return values.
        TODO: added a new param: sent_encoder, from model.py, this is the sentence matrix; add attns["mmr"] = [].

        """


        # 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": []}
        attns["mmr"] = []
        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.

        #print("emb size: {}\n".format(emb.size()));exit()
        for _, emb_t in enumerate(emb.split(1)):
            # for each output time step in the loop

            emb_t = emb_t.squeeze(0)
            decoder_input = torch.cat([emb_t, input_feed], 1)

            # TODO: the following is where we get attention!
            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)
            # p_attn: size (batch=2,input_step=200)

            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"] # attns["copy"] is a list of tensor for each output step=51, each size: [batch_size=2, input_step=200]



        # 2333: TODO : the sentence representation for decoder
        sent_decoder = decoder_outputs[-1].unsqueeze(0)  # shape: (1, batch_size=2,dim=512)

        # Return result.
        # 2333: TODO: attns['std'] is a list of tensors, length is output_step, each tensor shape is (batch=2,input_step=200)

        # 2333: TODO: compute mmr attention here:
        print ('Now..')
        mmr_among_words = self._run_mmr_attention(sent_encoder, sent_decoder, src_sents,attns["std"][0].size()[-1])

        #  2333: TODO: bring mmr to attention...

        for output_step in attns["std"]:
            attention_weight = output_step
            # pairwise multiplication
            attention_weight = torch.mul(mmr_among_words,attention_weight)
            attns["mmr"].append(attention_weight.cuda())
        # pdb.set_trace()

        attns["std"] = attns["mmr"]

        # decoder_outputs is a list of tensors for each output step=51, each tensor: (batch_size=2,dim=512)
        return hidden, decoder_outputs, attns
def _run_forward_pass ( self , tgt , memory_bank , state , memory_lengths = None , sent_encoder = None , src_sents = 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" : [ ] } attns [ "mmr" ] = [ ] 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. #print("emb size: {}\n".format(emb.size()));exit() for _ , emb_t in enumerate ( emb . split ( 1 ) ) : # for each output time step in the loop emb_t = emb_t . squeeze ( 0 ) decoder_input = torch . cat ( [ emb_t , input_feed ] , 1 ) # TODO: the following is where we get attention! 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 ) # p_attn: size (batch=2,input_step=200) 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" ] # attns["copy"] is a list of tensor for each output step=51, each size: [batch_size=2, input_step=200] # 2333: TODO : the sentence representation for decoder sent_decoder = decoder_outputs [ - 1 ] . unsqueeze ( 0 ) # shape: (1, batch_size=2,dim=512) # Return result. # 2333: TODO: attns['std'] is a list of tensors, length is output_step, each tensor shape is (batch=2,input_step=200) # 2333: TODO: compute mmr attention here: print ( 'Now..' ) mmr_among_words = self . _run_mmr_attention ( sent_encoder , sent_decoder , src_sents , attns [ "std" ] [ 0 ] . size ( ) [ - 1 ] ) #  2333: TODO: bring mmr to attention... for output_step in attns [ "std" ] : attention_weight = output_step # pairwise multiplication attention_weight = torch . mul ( mmr_among_words , attention_weight ) attns [ "mmr" ] . append ( attention_weight . cuda ( ) ) # pdb.set_trace() attns [ "std" ] = attns [ "mmr" ] # decoder_outputs is a list of tensors for each output step=51, each tensor: (batch_size=2,dim=512) return hidden , decoder_outputs , attns