(self, base_target_emb, input_from_dec, encoder_out_top,
                encoder_out_combine)
return context_output, attn
Args:
            base_target_emb: target emb tensor
            input: output of decode conv
            encoder_out_t: the key matrix for calculation of attetion weight,
                which is the top output of encode conv
            encoder_out_combine:
                the value matrix for the attention-weighted sum,
                which is the combination of base emb and top output of encode
Args:
            base_target_emb: target emb tensor
            input: output of decode conv
            encoder_out_t: the key matrix for calculation of attetion weight,
                which is the top output of encode conv
            encoder_out_combine:
                the value matrix for the attention-weighted sum,
                which is the combination of base emb and top output of encode
Args : base_target_emb : target emb tensor input : output of decode conv encoder_out_t : the key matrix for calculation of attetion weight which is the top output of encode conv encoder_out_combine : the value matrix for the attention - weighted sum which is the combination of base emb and top output of encode
def forward(self, base_target_emb, input_from_dec, encoder_out_top,
                encoder_out_combine):
        """
        Args:
            base_target_emb: target emb tensor
            input: output of decode conv
            encoder_out_t: the key matrix for calculation of attetion weight,
                which is the top output of encode conv
            encoder_out_combine:
                the value matrix for the attention-weighted sum,
                which is the combination of base emb and top output of encode

        """
        # checks
        # batch, channel, height, width = base_target_emb.size()
        batch, _, height, _ = base_target_emb.size()
        # batch_, channel_, height_, width_ = input_from_dec.size()
        batch_, _, height_, _ = input_from_dec.size()
        aeq(batch, batch_)
        aeq(height, height_)

        # enc_batch, enc_channel, enc_height = encoder_out_top.size()
        enc_batch, _, enc_height = encoder_out_top.size()
        # enc_batch_, enc_channel_, enc_height_ = encoder_out_combine.size()
        enc_batch_, _, enc_height_ = encoder_out_combine.size()

        aeq(enc_batch, enc_batch_)
        aeq(enc_height, enc_height_)

        preatt = seq_linear(self.linear_in, input_from_dec)
        target = (base_target_emb + preatt) * SCALE_WEIGHT
        target = torch.squeeze(target, 3)
        target = torch.transpose(target, 1, 2)
        pre_attn = torch.bmm(target, encoder_out_top)

        if self.mask is not None:
            pre_attn.data.masked_fill_(self.mask, -float('inf'))

        pre_attn = pre_attn.transpose(0, 2)
        attn = F.softmax(pre_attn, dim=-1)
        attn = attn.transpose(0, 2).contiguous()
        context_output = torch.bmm(
            attn, torch.transpose(encoder_out_combine, 1, 2))
        context_output = torch.transpose(
            torch.unsqueeze(context_output, 3), 1, 2)
        return context_output, attn
def forward ( self , base_target_emb , input_from_dec , encoder_out_top , encoder_out_combine ) : # checks # batch, channel, height, width = base_target_emb.size() batch , _ , height , _ = base_target_emb . size ( ) # batch_, channel_, height_, width_ = input_from_dec.size() batch_ , _ , height_ , _ = input_from_dec . size ( ) aeq ( batch , batch_ ) aeq ( height , height_ ) # enc_batch, enc_channel, enc_height = encoder_out_top.size() enc_batch , _ , enc_height = encoder_out_top . size ( ) # enc_batch_, enc_channel_, enc_height_ = encoder_out_combine.size() enc_batch_ , _ , enc_height_ = encoder_out_combine . size ( ) aeq ( enc_batch , enc_batch_ ) aeq ( enc_height , enc_height_ ) preatt = seq_linear ( self . linear_in , input_from_dec ) target = ( base_target_emb + preatt ) * SCALE_WEIGHT target = torch . squeeze ( target , 3 ) target = torch . transpose ( target , 1 , 2 ) pre_attn = torch . bmm ( target , encoder_out_top ) if self . mask is not None : pre_attn . data . masked_fill_ ( self . mask , - float ( 'inf' ) ) pre_attn = pre_attn . transpose ( 0 , 2 ) attn = F . softmax ( pre_attn , dim = - 1 ) attn = attn . transpose ( 0 , 2 ) . contiguous ( ) context_output = torch . bmm ( attn , torch . transpose ( encoder_out_combine , 1 , 2 ) ) context_output = torch . transpose ( torch . unsqueeze ( context_output , 3 ) , 1 , 2 ) return context_output , attn