code: def _mask_sequences_tensor(
      sequence,
      sequence_length,
      dtype=None,
      time_major=False,
      tensor_rank=2,
  ):
      """Masks out sequence entries that are beyond the respective sequence
      lengths. Masks along the time dimension.
  
      Args:
          sequence: A Tensor of sequence values.
  
              If `time_major=False` (default), this must be a Tensor of shape:
                  `[batch_size, max_time, d_2, ..., d_rank]`, where the rank of
                  the Tensor is specified with :attr:`tensor_rank`.
  
              If `time_major=True`, this must be a Tensor of shape:
                  `[max_time, batch_size, d_2, ..., d_rank].`
          sequence_length: A Tensor of shape `[batch_size]`. Time steps beyond
              the respective sequence lengths will be made zero.
          dtype (dtype): Type of :attr:`sequence`. If `None`, infer from
              :attr:`sequence` automatically.
          time_major (bool): The shape format of the inputs. If `True`,
              :attr:`sequence` must have shape
              `[max_time, batch_size, d_2, ..., d_rank]`.
              If `False` (default), :attr:`sequence` must have
              shape `[batch_size, max_time, d_2, ..., d_rank]`.
          tensor_rank (int): The number of dimensions of :attr:`sequence`.
              Default is 2, i.e., :attr:`sequence` is a 2D Tensor consisting
              of batch and time dimensions.
  
      Returns:
          The masked sequence, i.e., a Tensor of the same shape as
          :attr:`sequence` but with masked-out entries (set to zero).
      """
      if tensor_rank is None:
          tensor_rank = 2
      if tensor_rank < 2:
          raise ValueError(
              "tensor_rank must be > 2. Got tensor_rank = {}".format(
                  tensor_rank
              )
          )
      if time_major:
          sequence = rnn._transpose_batch_time(sequence)
      max_time = tf.cast(tf.shape(sequence)[1], tf.int32)
      if dtype is None:
          dtype = sequence.dtype
      mask = tf.sequence_mask(
          tf.cast(sequence_length, tf.int32), max_time, dtype=dtype
      )
      for _ in range(2, tensor_rank):
          mask = tf.expand_dims(mask, axis=-1)
      sequence = sequence * mask
      if time_major:
          sequence = rnn._transpose_batch_time(sequence)
      return sequence
  
file_path: texar/texar/tf/utils/shapes.py
imports: import numpy
  import tensorflow
  from tensorflow.python.util import nest
  from tensorflow.python.ops import rnn
  from tensorflow.python.framework import ops
label_desc: Use image node_id 5 for calling a global function with example usage: _mask_sequences_tensor(sequence, sequence_length, dtype, time_major, tensor_rank) and returns: sequence