code: def log2_inverse(rank: TensorLike) -> tf.Tensor:
      """Computes `1./log2(1+x)` element-wise for each label.
  
      Can be used to define `rank_discount_fn` for `tfr.keras.metrics.NDCGMetric`.
  
      Args:
        rank: A `Tensor` or anything that can be converted to a tensor using
          `tf.convert_to_tensor`.
  
      Returns:
        A `Tensor` that has each input element transformed as `x` to `1./log2(1+x)`.
      """
      return tf.math.divide_no_nan(
          tf.math.log(2.0), tf.math.log1p(rank)
      )
  
file_path: ranking/tensorflow_ranking/python/keras/utils.py
imports: from typing import Callable
  import tensorflow
label_desc: Use image node_id 6 for calling a global function with example usage: log2_inverse(rank) and returns: tf