code: def sequence_sparse_softmax_cross_entropy(
      labels,
      logits,
      sequence_length,
      average_across_batch=True,
      average_across_timesteps=False,
      sum_over_batch=False,
      sum_over_timesteps=True,
      time_major=False,
      name=None,
  ):
      """Computes sparse softmax cross entropy for each time step of sequence
      predictions.
  
      Args:
          labels: Target class indexes. I.e., classes are mutually exclusive
              (each entry is in exactly one class).
  
              - If :attr:`time_major` is `False` (default), this must be\
              a Tensor of shape `[batch_size, max_time]`.
  
              - If `time_major` is `True`, this must be a Tensor of shape\
              `[max_time, batch_size].`
          logits: Unscaled log probabilities. This must have the shape of
              `[max_time, batch_size, num_classes]` or
              `[batch_size, max_time, num_classes]` according to
              the value of `time_major`.
          sequence_length: A Tensor of shape `[batch_size]`. Time steps beyond
              the respective sequence lengths will have zero losses.
          average_across_timesteps (bool): If set, average the loss 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 loss across the
              batch dimension. Must not set `average_across_batch`'
              and `sum_over_batch` at the same time.
          sum_over_timesteps (bool): If set, sum the loss 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 loss across the
              batch dimension. Must not set `average_across_batch`
              and `sum_over_batch` at the same time.
          time_major (bool): The shape format of the inputs. If `True`,
              :attr:`labels` and :attr:`logits` must have shape
              `[max_time, batch_size, ...]`. If `False`
              (default), they must have shape `[batch_size, max_time, ...]`.
          name (str, optional): A name for the operation.
  
      Returns:
          A Tensor containing the loss, of rank 0, 1, or 2 depending on the
          arguments :attr:`{average_across}/{sum_over}_{timesteps}/{batch}`.
          For example:
  
          - If :attr:`sum_over_timesteps` and :attr:`average_across_batch`  \
          are `True` (default), the return Tensor is of rank 0.
  
          - If :attr:`average_across_batch` is `True` and other arguments are \
          `False`, the return Tensor is of shape `[max_time]`.
  
      Example:
  
          .. code-block:: python
  
              embedder = WordEmbedder(vocab_size=data.vocab.size)
              decoder = BasicRNNDecoder(vocab_size=data.vocab.size)
              outputs, _, _ = decoder(
                  decoding_strategy='train_greedy',
                  inputs=embedder(data_batch['text_ids']),
                  sequence_length=data_batch['length']-1)
  
              loss = sequence_sparse_softmax_cross_entropy(
                  labels=data_batch['text_ids'][:, 1:],
                  logits=outputs.logits,
                  sequence_length=data_batch['length']-1)
  
      """
      with tf.name_scope(name, "sequence_sparse_softmax_cross_entropy"):
          losses = tf.nn.sparse_softmax_cross_entropy_with_logits(
              labels=labels, logits=logits
          )
  
          losses = mask_and_reduce(
              losses,
              sequence_length,
              rank=2,
              average_across_batch=average_across_batch,
              average_across_timesteps=average_across_timesteps,
              sum_over_batch=sum_over_batch,
              sum_over_timesteps=sum_over_timesteps,
              time_major=time_major,
          )
  
          return losses
  
imports: import tensorflow
  from texar.tf.losses.losses_utils import mask_and_reduce, reduce_dimensions
  from texar.tf.utils import shapes
label_desc: Use image node_id 2 for calling a global function with example usage: sequence_sparse_softmax_cross_entropy(labels, logits, sequence_length, average_across_batch, average_across_timesteps, sum_over_batch, sum_over_timesteps, time_major, name) and returns: losses