code: def sequence_entropy_with_logits(
      logits,
      rank=None,
      sequence_length=None,
      average_across_batch=True,
      average_across_timesteps=False,
      average_across_remaining=False,
      sum_over_batch=False,
      sum_over_timesteps=True,
      sum_over_remaining=True,
      time_major=False,
  ):
      """Shannon entropy given logits.
  
      Args:
          logits: Unscaled log probabilities of shape
              `[batch_size, max_time, d_3, ..., 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.
  
              The batch and time dimensions are exchanged if :attr:`time_major`
              is `True`.
          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 3, i.e., assuming `logits` is of shape
              `[batch_size, max_time, distribution_dim]`
          sequence_length (optional): A Tensor of shape `[batch_size]`.
              Time steps beyond the respective sequence lengths are
              counted into the entropy.
          average_across_timesteps (bool): If set, average the entropy across
              the time dimension. Must not set `average_across_timesteps`
              and `sum_over_timesteps` at the same time.
          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 >= 4.
          sum_over_timesteps (bool): If set, sum the entropy across the
              time dimension. Must not set `average_across_timesteps`
              and `sum_over_timesteps` at the same time.
          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 >= 4.
          time_major (bool): The shape format of the inputs. If `True`,
              :attr:`logits` must have shape `[max_time, batch_size, ...]`.
              If `False` (default), it must have shape
              `[batch_size, max_time, ...]`.
  
      Returns:
          A Tensor containing the shannon entropy. The dimensionality of the
          Tensor depends on the configuration of reduction arguments. For
          example, if batch, time, and remaining dimensions are all 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 = 3
      rank -= 1  # reduced last dimension
  
      entropy = mask_and_reduce(
          entropy,
          sequence_length,
          rank=rank,
          average_across_batch=average_across_batch,
          average_across_timesteps=average_across_timesteps,
          average_across_remaining=average_across_remaining,
          sum_over_batch=sum_over_batch,
          sum_over_timesteps=sum_over_timesteps,
          sum_over_remaining=sum_over_remaining,
          time_major=time_major,
      )
  
      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 3 for calling a global function with example usage: sequence_entropy_with_logits(logits, rank, sequence_length, average_across_batch, average_across_timesteps, average_across_remaining, sum_over_batch, sum_over_timesteps, sum_over_remaining, time_major) and returns: entropy