import tensorflow as tf

    src_mask = tf.sequence_mask(encoder_input_length[0], maxlen=max_src_len, dtype=tf.float32)
    src_mask = tf.einsum('ij,ik->ijk', src_mask, src_mask)
    attn_loss *= tf.to_float(src_mask)    # don't take padding words into account

    attn_loss = tf.norm(attn_loss) / tf.to_float(batch_size)
    xent_loss += reconstruction_attn_weight * attn_loss

    attention_weights = [attention_weights, reconstructed_weights]
