code: def collect_final_step_of_lstm(lstm_representation, lengths):
      """
      Collect final step of lstm.
  
      :param lstm_representation: [batch_size, len_rt, dim]
      :param lengths: [batch_size]
      :return: [batch_size, dim]
      """
      lengths = tf.maximum(lengths, K.zeros_like(lengths))
  
      batch_size = tf.shape(lengths)[0]
      # shape (batch_size)
      batch_nums = tf.range(0, limit=batch_size)
      # shape (batch_size, 2)
      indices = tf.stack((batch_nums, lengths), axis=1)
      result = tf.gather_nd(
          lstm_representation, indices, name="last-forwar-lstm"
      )
      # [batch_size, dim]
      return result
  
imports: import tensorflow
  from keras import backend
  from keras.engine import Layer
  from matchzoo.contrib.layers.attention_layer import AttentionLayer
label_desc: Use image node_id 3 for calling a global function with example usage: collect_final_step_of_lstm(lstm_representation, lengths) and returns: result