def lstm_seq2seq_internal(inputs, targets, hparams, train):
  """The basic LSTM seq2seq model, main step used for training."""
  with tf.variable_scope("lstm_seq2seq"):
    if inputs is not None:
      inputs_length = common_layers.length_from_embedding(inputs)
      # Flatten inputs.
      inputs = common_layers.flatten4d3d(inputs)

      # LSTM encoder.
      inputs = tf.reverse_sequence(inputs, inputs_length, seq_axis=1)
      _, final_encoder_state = lstm(inputs, inputs_length, hparams, train,
                                    "encoder")
    else:
      final_encoder_state = None

    # LSTM decoder.
    shifted_targets = common_layers.shift_right(targets)
    # Add 1 to account for the padding added to the left from shift_right
    targets_length = common_layers.length_from_embedding(shifted_targets) + 1
    decoder_outputs, _ = lstm(
        common_layers.flatten4d3d(shifted_targets),
        targets_length,
        hparams,
        train,
        "decoder",
        initial_state=final_encoder_state)
    return tf.expand_dims(decoder_outputs, axis=2)
def lstm_seq2seq_internal ( inputs , targets , hparams , train ) : with tf . variable_scope ( "lstm_seq2seq" ) : if inputs is not None : inputs_length = common_layers . length_from_embedding ( inputs ) inputs = common_layers . flatten4d3d ( inputs ) inputs = tf . reverse_sequence ( inputs , inputs_length , seq_axis = 1 ) _ , final_encoder_state = lstm ( inputs , inputs_length , hparams , train , "encoder" ) else : final_encoder_state = None shifted_targets = common_layers . shift_right ( targets ) targets_length = common_layers . length_from_embedding ( shifted_targets ) + 1 decoder_outputs , _ = lstm ( common_layers . flatten4d3d ( shifted_targets ) , targets_length , hparams , train , "decoder" , initial_state = final_encoder_state ) return tf . expand_dims ( decoder_outputs , axis = 2 )
The basic LSTM seq2seq model, main step used for training.