import tensorflow as tf

    for a in attn_dists:
        covloss = tf.reduce_sum(tf.minimum(a, coverage), [1]) # calculate the coverage loss for this step
        covlosses.append(covloss)
        coverage += a # update the coverage vector
    coverage_loss = _mask_and_avg(covlosses, loss_weights)
    return coverage_loss

# values: [batch_size, step_size, vocab_size]
# answers: [batch_size, step_size]
def _mask_and_accuracy(values, answers, loss_weights):
    values = tf.argmax(values,axis=2)
    x = tf.cast(values, dtype=tf.int32)
    y = tf.cast(answers, dtype=tf.int32)
    res = tf.equal(x, y)
    res = tf.cast(res, dtype=tf.float32)
    res = tf.multiply(res, loss_weights)
    return tf.reduce_sum(res)


