def evaluate_model(sess, model, data_set):
    """Returns the average weighted cost, reconstruction cost and KL cost."""
    total_cost = 0.0
    total_r_cost = 0.0
    total_kl_cost = 0.0
    for batch in range(data_set.num_batches):
        unused_orig_x, x, s = data_set.get_batch(batch)
        feed = {model.input_data: x, model.sequence_lengths: s}
        (cost, r_cost,
         kl_cost) = sess.run([model.cost, model.r_cost, model.kl_cost], feed)
        total_cost += cost
        total_r_cost += r_cost
        total_kl_cost += kl_cost

    total_cost /= (data_set.num_batches)
    total_r_cost /= (data_set.num_batches)
    total_kl_cost /= (data_set.num_batches)
    return (total_cost, total_r_cost, total_kl_cost)