(self, inputs, memory_bank, src_pad_mask, tgt_pad_mask,
                previous_input=None, layer_cache=None, step=None)
return output, attn, all_input
Args:
            inputs (`FloatTensor`): `[batch_size x 1 x model_dim]`
            memory_bank (`FloatTensor`): `[batch_size x src_len x model_dim]`
            src_pad_mask (`LongTensor`): `[batch_size x 1 x src_len]`
            tgt_pad_mask (`LongTensor`): `[batch_size x 1 x 1]`

        Returns:
            (`FloatTensor`, `FloatTensor`, `FloatTensor`):

            * output `[batch_size x 1 x model_dim]`
            * attn `[batch_size x 1 x src_len]`
            * all_input `[batch_size x current_step x model_dim]`
Args:
            inputs (`FloatTensor`): `[batch_size x 1 x model_dim]`
            memory_bank (`FloatTensor`): `[batch_size x src_len x model_dim]`
            src_pad_mask (`LongTensor`): `[batch_size x 1 x src_len]`
            tgt_pad_mask (`LongTensor`): `[batch_size x 1 x 1]`
Args : inputs ( FloatTensor ) : [ batch_size x 1 x model_dim ] memory_bank ( FloatTensor ) : [ batch_size x src_len x model_dim ] src_pad_mask ( LongTensor ) : [ batch_size x 1 x src_len ] tgt_pad_mask ( LongTensor ) : [ batch_size x 1 x 1 ]
def forward(self, inputs, memory_bank, src_pad_mask, tgt_pad_mask,
                previous_input=None, layer_cache=None, step=None):
        """
        Args:
            inputs (`FloatTensor`): `[batch_size x 1 x model_dim]`
            memory_bank (`FloatTensor`): `[batch_size x src_len x model_dim]`
            src_pad_mask (`LongTensor`): `[batch_size x 1 x src_len]`
            tgt_pad_mask (`LongTensor`): `[batch_size x 1 x 1]`

        Returns:
            (`FloatTensor`, `FloatTensor`, `FloatTensor`):

            * output `[batch_size x 1 x model_dim]`
            * attn `[batch_size x 1 x src_len]`
            * all_input `[batch_size x current_step x model_dim]`

        """
        dec_mask = torch.gt(tgt_pad_mask +
                            self.mask[:, :tgt_pad_mask.size(1),
                                      :tgt_pad_mask.size(1)], 0)
        input_norm = self.layer_norm_1(inputs)
        all_input = input_norm
        if previous_input is not None:
            all_input = torch.cat((previous_input, input_norm), dim=1)
            dec_mask = None

        if self.self_attn_type == "scaled-dot":
            query, attn = self.self_attn(all_input, all_input, input_norm,
                                         mask=dec_mask,
                                         layer_cache=layer_cache,
                                         type="self")
        elif self.self_attn_type == "average":
            query, attn = self.self_attn(input_norm, mask=dec_mask,
                                         layer_cache=layer_cache, step=step)

        query = self.drop(query) + inputs

        query_norm = self.layer_norm_2(query)
        mid, attn = self.context_attn(memory_bank, memory_bank, query_norm,
                                      mask=src_pad_mask,
                                      layer_cache=layer_cache,
                                      type="context")
        output = self.feed_forward(self.drop(mid) + query)

        return output, attn, all_input
def forward ( self , inputs , memory_bank , src_pad_mask , tgt_pad_mask , previous_input = None , layer_cache = None , step = None ) : dec_mask = torch . gt ( tgt_pad_mask + self . mask [ : , : tgt_pad_mask . size ( 1 ) , : tgt_pad_mask . size ( 1 ) ] , 0 ) input_norm = self . layer_norm_1 ( inputs ) all_input = input_norm if previous_input is not None : all_input = torch . cat ( ( previous_input , input_norm ) , dim = 1 ) dec_mask = None if self . self_attn_type == "scaled-dot" : query , attn = self . self_attn ( all_input , all_input , input_norm , mask = dec_mask , layer_cache = layer_cache , type = "self" ) elif self . self_attn_type == "average" : query , attn = self . self_attn ( input_norm , mask = dec_mask , layer_cache = layer_cache , step = step ) query = self . drop ( query ) + inputs query_norm = self . layer_norm_2 ( query ) mid , attn = self . context_attn ( memory_bank , memory_bank , query_norm , mask = src_pad_mask , layer_cache = layer_cache , type = "context" ) output = self . feed_forward ( self . drop ( mid ) + query ) return output , attn , all_input