import tensorflow as tf

    outputs, attention_weights, _, _, samples, beam_fun, initial_data = attention_decoder(
        attention_states=attention_states, initial_state=encoder_state, feed_previous=feed_previous,
        decoder_inputs=targets[:, :-1], align_encoder_id=align_encoder_id, encoder_input_length=encoder_input_length,
        **parameters
    )

    if use_baseline:
        baseline_rewards = reinforce_baseline(outputs, rewards)   # FIXME: use logits or decoder outputs?
        baseline_weights = get_weights(samples, utils.EOS_ID, include_first_eos=False)
        baseline_loss_ = baseline_loss(rewards=baseline_rewards, weights=baseline_weights)
    else:
        baseline_rewards = rewards
        baseline_loss_ = tf.constant(0.0)

    reinforce_weights = get_weights(samples, utils.EOS_ID, include_first_eos=True)
    reinforce_loss = sequence_loss(logits=outputs, targets=samples, weights=reinforce_weights,
                                   rewards=baseline_rewards)

    trg_mask = get_weights(targets[:, 1:], utils.EOS_ID, include_first_eos=True)
    xent_loss = sequence_loss(logits=outputs, targets=targets[:, 1:], weights=trg_mask)

    if monotonicity_weight:
        monotonicity_dist = monotonicity_dist or 1.0

