def inverse_tukey_hh(x, hl, hr):
  """Compute the inverse of the Tukey HH function.

  The Tukey HH function transforms a standard Gaussian distribution into the
  Tukey HH distribution and it's defined as:

  x = u * exp(hl * u ^ 2) for u < 0 and x = u * exp(hr * u ^ 2) for u >= 0.

  Given the values of x, this function computes the corresponding values of u.

  Args:
    x: The input `Tensor`.
    hl: The "left" parameter of the distribution. It must have the same dtype
      and shape of x (or a broadcastable shape) or be a scalar.
    hr: The "right" parameter of the distribution. It must have the same dtype
      and shape of x (or a broadcastable shape) or be a scalar.

  Returns:
    The inverse of the Tukey HH function.
  """
  def one_side(x, h):
    h_x_square = tf.multiply(h, tf.square(x))
    return tf.where(
        # Prevents the 0 / 0 form for small values of x..
        tf.less(h_x_square, 1.0e-7),
        x,  # The error is < 1e-14 for this case.
        tf.sqrt(tf.divide(lambert_w(h_x_square), h)))

  return tf.where(tf.less(x, 0.0), -one_side(-x, hl), one_side(x, hr))
Compute the inverse of the Tukey HH function.

  The Tukey HH function transforms a standard Gaussian distribution into the
  Tukey HH distribution and it's defined as:

  x = u * exp(hl * u ^ 2) for u < 0 and x = u * exp(hr * u ^ 2) for u >= 0.

  Given the values of x, this function computes the corresponding values of u.

  Args:
    x: The input `Tensor`.
    hl: The "left" parameter of the distribution. It must have the same dtype
      and shape of x (or a broadcastable shape) or be a scalar.
    hr: The "right" parameter of the distribution. It must have the same dtype
      and shape of x (or a broadcastable shape) or be a scalar.

  Returns:
    The inverse of the Tukey HH function.
  
tensorflow_transform/gaussianization.py