TF 2.0 is out! Get hands-on practice at TF World, Oct 28-31. Use code TF20 for 20% off select passes. Register now

tf.contrib.seq2seq.safe_cumprod

View source on GitHub

Computes cumprod of x in logspace using cumsum to avoid underflow.

tf.contrib.seq2seq.safe_cumprod(
    x,
    *args,
    **kwargs
)

The cumprod function and its gradient can result in numerical instabilities when its argument has very small and/or zero values. As long as the argument is all positive, we can instead compute the cumulative product as exp(cumsum(log(x))). This function can be called identically to tf.cumprod.

Args:

  • x: Tensor to take the cumulative product of.
  • *args: Passed on to cumsum; these are identical to those in cumprod.
  • **kwargs: Passed on to cumsum; these are identical to those in cumprod.

Returns:

Cumulative product of x.