code: def _get_final_index(sequence_length, time_major=True):
      indices = [
          tf.maximum(0, sequence_length - 1),
          tf.range(sequence_length.shape[0]),
      ]
      if not time_major:
          indices = indices[-1::-1]
      return tf.stack(indices, axis=1)
  
imports: import collections
  from magenta.contrib import rnn
  from magenta.contrib import seq2seq
  import tensorflow.compat.v1
label_desc: Use image node_id 3 for calling a global function with example usage: _get_final_index(sequence_length, time_major) and returns: tf