code: def get_final(sequence, sequence_length, time_major=True):
      """Get the final item in a batch of sequences."""
      final_index = _get_final_index(sequence_length, time_major)
      return tf.gather_nd(sequence, final_index)
  
imports: import collections
  from magenta.contrib import rnn
  from magenta.contrib import seq2seq
  import tensorflow.compat.v1
label_desc: Use image node_id 4 for calling a global function with example usage: get_final(sequence, sequence_length, time_major) and returns: tf