src/transformers/models/mpnet/modeling_tf_mpnet.py/TFMPNetEncoder/compute_position_bias
class TFMPNetEncoder:    def compute_position_bias(self, x, position_ids=None):
        """Compute binned relative position bias"""
        input_shape = shape_list(x)
        qlen, klen = input_shape[1], input_shape[1]

        if position_ids is not None:
            context_position = position_ids[:, :, None]
            memory_position = position_ids[:, None, :]
        else:
            context_position = tf.range(qlen)[:, None]
            memory_position = tf.range(klen)[None, :]

        relative_position = memory_position - context_position  # shape (qlen, klen)

        rp_bucket = self._relative_position_bucket(
            relative_position,
            num_buckets=self.relative_attention_num_buckets,
        )
        values = tf.gather(self.relative_attention_bias, rp_bucket)  # shape (qlen, klen, num_heads)
        values = tf.expand_dims(tf.transpose(values, [2, 0, 1]), axis=0)  # shape (1, num_heads, qlen, klen)
        return values