def average_product_correct(x):
    "Perform average product correct, used for contact prediction."
    a1 = tf.reduce_sum(x, -1, keepdims=True)
    a2 = tf.reduce_sum(x, -2, keepdims=True)
    a12 = tf.reduce_sum(x, (-1, -2), keepdims=True)

    avg = a1 * a2
    avg = avg / a12
    normalized = x - avg
    return normalized
Perform average product correct, used for contact prediction.
dpkd/transformers/src/transformers/models/esm/modeling_tf_esm.py