(self, inputs, mask_or_step,
                           layer_cache=None, step=None)
Computes the cumulative average as described in
        https://arxiv.org/abs/1805.00631 -- Equations (1) (5) (6)

        Args:
            inputs (`FloatTensor`): sequence to average
                `[batch_size x input_len x dimension]`
            mask_or_step: if cache is set, this is assumed
                to be the current step of the
                dynamic decoding. Otherwise, it is the mask matrix
                used to compute the cumulative average.
            cache: a dictionary containing the cumulative average
                of the previous step.
Computes the cumulative average as described in
        https://arxiv.org/abs/1805.00631 -- Equations (1) (5) (6)
Computes the cumulative average as described in https : // arxiv . org / abs / 1805 . 00631 -- Equations ( 1 ) ( 5 ) ( 6 )
def cumulative_average(self, inputs, mask_or_step,
                           layer_cache=None, step=None):
        """
        Computes the cumulative average as described in
        https://arxiv.org/abs/1805.00631 -- Equations (1) (5) (6)

        Args:
            inputs (`FloatTensor`): sequence to average
                `[batch_size x input_len x dimension]`
            mask_or_step: if cache is set, this is assumed
                to be the current step of the
                dynamic decoding. Otherwise, it is the mask matrix
                used to compute the cumulative average.
            cache: a dictionary containing the cumulative average
                of the previous step.
        """
        if layer_cache is not None:
            step = mask_or_step
            device = inputs.device
            average_attention = (inputs + step *
                                 layer_cache["prev_g"].to(device)) / (step + 1)
            layer_cache["prev_g"] = average_attention
            return average_attention
        else:
            mask = mask_or_step
            return torch.matmul(mask, inputs)
def cumulative_average ( self , inputs , mask_or_step , layer_cache = None , step = None ) : if layer_cache is not None : step = mask_or_step device = inputs . device average_attention = ( inputs + step * layer_cache [ "prev_g" ] . to ( device ) ) / ( step + 1 ) layer_cache [ "prev_g" ] = average_attention return average_attention else : mask = mask_or_step return torch . matmul ( mask , inputs )