import tensorflow as tf

        encoder_input_length = [tf.to_int32(tf.reduce_sum(weights, axis=1))]

    attention_states, encoder_state, encoder_input_length = multi_encoder(
        encoder_input_length=encoder_input_length, encoders=encoders, encoder_inputs=encoder_inputs,
        training=training)

    outputs, attention_weights, states, _, samples, beam_fun, initial_data = attention_decoder(
        attention_states=attention_states, initial_state=encoder_state, feed_previous=feed_previous,
        decoder_inputs=targets[0][:, :-1], encoder_input_length=encoder_input_length,
        decoder=decoders[0], training=training, encoders=encoders
    )

    target_weights = get_weights(targets[0][:, 1:], utils.EOS_ID, include_first_eos=True)
    target_length = [tf.to_int32(tf.reduce_sum(target_weights, axis=1))]

    xent_loss = sequence_loss(logits=outputs, targets=targets[0][:, 1:], weights=target_weights)

    reconstructed_outputs, reconstructed_weights, _, _, _, _, _ = attention_decoder(
        attention_states=[states], initial_state=states[:,-1,:], feed_previous=feed_previous,
        decoder_inputs=targets[1][:, :-1], encoder_input_length=target_length,
        decoder=decoders[1], training=training, encoders=decoders[:1]
    )

    target_weights = get_weights(targets[1][:, 1:], utils.EOS_ID, include_first_eos=True)
    xent_loss += reconstruction_weight * sequence_loss(logits=reconstructed_outputs, targets=targets[1][:, 1:],
                                                       weights=target_weights)
