code: def reduce_batch_time(
      sequence,
      sequence_length,
      average_across_batch=True,
      average_across_timesteps=False,
      sum_over_batch=False,
      sum_over_timesteps=True,
  ):
      """Average or sum over the respective dimensions of :attr:`sequence`, which
      is of shape `[batch_size, max_time, ...]`.
  
      Assumes :attr:`sequence` has been properly masked according to
      :attr:`sequence_length`.
      """
      if average_across_timesteps and sum_over_timesteps:
          raise ValueError(
              "Only one of `average_across_timesteps` and "
              "`sum_over_timesteps` can be set."
          )
      if average_across_batch and sum_over_batch:
          raise ValueError(
              "Only one of `average_across_batch` and "
              "`sum_over_batch` can be set."
          )
  
      if sum_over_timesteps:
          sequence = tf.reduce_sum(sequence, axis=[1])
      elif average_across_timesteps:
          if sequence_length is None:
              sequence = tf.reduce_mean(sequence, axis=[1])
          else:
              sequence = tf.reduce_sum(sequence, axis=[1]) / tf.cast(
                  sequence_length, sequence.dtype
              )
  
      if sum_over_batch:
          sequence = tf.reduce_sum(sequence, axis=[0])
      elif average_across_batch:
          sequence = tf.reduce_mean(sequence, axis=[0])
  
      return sequence
  
imports: import numpy
  import tensorflow
  from tensorflow.python.ops import rnn
  from texar.tf.utils.shapes import mask_sequences
label_desc: Use image node_id 2 for calling a global function with example usage: reduce_batch_time(sequence, sequence_length, average_across_batch, average_across_timesteps, sum_over_batch, sum_over_timesteps) and returns: sequence