code: def entropy_with_logits(
      logits,
      rank=None,
      average_across_batch=True,
      average_across_remaining=False,
      sum_over_batch=False,
      sum_over_remaining=True,
  ):
      """Shannon entropy given logits.
  
      Args:
          logits: Unscaled log probabilities of shape
              `[batch_size, d_2, ..., d_{rank-1}, distribution_dim]`
              and of dtype `float32` or `float64`.
  
              The rank of the tensor is optionally specified by the argument
              :attr:`rank`.
  
              The tensor is considered as having `[batch_size, .., d_{rank-1}]`
              elements, each of which has a distribution of length `d_rank`
              (i.e., `distribution_dim`). So the last dimension is always
              summed out to compute the entropy.
          rank (int, optional): The rank of :attr:`logits`.
              If `None` (default), `rank` is inferred automatically from
              `logits`. If the inference fails, `rank` is
              set to 2, i.e., assuming :attr:`logits` is of shape
              `[batch_size, distribution_dim]`
          average_across_batch (bool): If set, average the entropy across the
              batch dimension. Must not set `average_across_batch`'
              and `sum_over_batch` at the same time.
          average_across_remaining (bool): If set, average the entropy across the
              remaining dimensions. Must not set `average_across_remaining`'
              and `sum_over_remaining` at the same time.
              Used only when :attr:`logits` has rank >= 3.
          sum_over_batch (bool): If set, sum the entropy across the
              batch dimension. Must not set `average_across_batch`
              and `sum_over_batch` at the same time.
          sum_over_remaining (bool): If set, sum the entropy across the
              remaining dimension. Must not set `average_across_remaining`
              and `sum_over_remaining` at the same time.
              Used only when :attr:`logits` has rank >= 3.
  
      Returns:
          A Tensor containing the shannon entropy. The dimensionality of the
          Tensor depends on the configuration of reduction arguments. For
          example, if both batch and remaining dimensions are reduced (by
          either sum or average), the returned Tensor is a scalar Tensor.
      """
      entropy = _get_entropy(logits)
  
      if rank is None:
          rank = get_rank(logits)
      if rank is None:
          rank = 2
      rank -= 1  # reduced last dimension
  
      # Reduces
      if average_across_batch and sum_over_batch:
          raise ValueError(
              "Only one of `average_across_batch` and "
              "`sum_over_batch` can be set."
          )
      if average_across_remaining and sum_over_remaining:
          raise ValueError(
              "Only one of `average_across_remaining` and "
              "`sum_over_remaining` can be set."
          )
      sum_axes, average_axes = [], []
      if sum_over_batch:
          sum_axes.append(0)
      if average_across_batch:
          average_axes.append(0)
      if sum_over_remaining and rank >= 2:
          sum_axes += list(range(1, rank))
      if average_across_remaining and rank >= 2:
          average_axes += list(range(1, rank))
  
      entropy = reduce_dimensions(
          entropy, average_axes=average_axes, sum_axes=sum_axes
      )
  
      return entropy
  
imports: import tensorflow
  from texar.tf.losses.losses_utils import mask_and_reduce, reduce_dimensions
  from texar.tf.utils.shapes import get_rank
label_desc: Use image node_id 2 for calling a global function with example usage: entropy_with_logits(logits, rank, average_across_batch, average_across_remaining, sum_over_batch, sum_over_remaining) and returns: entropy