code: def lstm_seq2seq_internal_attention(inputs, targets, hparams, train,
                                      inputs_length, targets_length):
    
    with tf.variable_scope("lstm_seq2seq_attention"):
      # Flatten inputs.
      inputs = common_layers.flatten4d3d(inputs)
  
      # LSTM encoder.
      inputs = tf.reverse_sequence(inputs, inputs_length, seq_axis=1)
      encoder_outputs, final_encoder_state = lstm(
          inputs, inputs_length, hparams, train, "encoder")
  
      # LSTM decoder with attention.
      shifted_targets = common_layers.shift_right(targets)
      # Add 1 to account for the padding added to the left from shift_right
      targets_length = targets_length + 1
      decoder_outputs = lstm_attention_decoder(
          common_layers.flatten4d3d(shifted_targets), hparams, train, "decoder",
          final_encoder_state, encoder_outputs, inputs_length, targets_length)
      return tf.expand_dims(decoder_outputs, axis=2)
docs: LSTM seq2seq model with attention, main step used for training.