keras/src/regularizers/regularizers.py/OrthogonalRegularizer/__call__
class OrthogonalRegularizer:    def __call__(self, inputs):
        if len(inputs.shape) != 2:
            raise ValueError(
                "Inputs to OrthogonalRegularizer must have rank 2. Received: "
                f"inputs.shape={inputs.shape}"
            )
        if self.mode == "rows":
            inputs = normalize(inputs, axis=1)
            product = ops.matmul(inputs, ops.transpose(inputs))
            size = inputs.shape[0]
        else:
            inputs = normalize(inputs, axis=0)
            product = ops.matmul(ops.transpose(inputs), inputs)
            size = inputs.shape[1]
        product_no_diagonal = product * (
            1.0 - ops.eye(size, dtype=inputs.dtype)
        )
        num_pairs = size * (size - 1.0) / 2.0
        return (
            self.factor
            * 0.5
            * ops.sum(ops.absolute(product_no_diagonal))
            / num_pairs
        )