class_docstr: Off-diagonal orthogonal regularizer.
  
  The implementation is based on https://arxiv.org/abs/1809.11096.
  Given a rank N >= 2 tensor, the regularizer computes
  the sum of off-diagonal entries of (W^T W)^2 where
  
  * W is the input tensor reshaped to a matrix by collapsing the
    leading N - 1 axes into the first one;
  * ^2 is the element-wise square.
  
  NB: that is equivalent to computing the off-diagonal sum of (W^T W - I)^2,
  as off-diagonal entries of I are 0.
  
  For example,
  
      >>> t = tf.reshape(tf.range(8, dtype=tf.float32), [2, 2, 2])
      >>> reg = snt.regularizers.OffDiagonalOrthogonal(0.01)
      >>> reg([t])
      <tf.Tensor: ...>
  
  corresponds to copmuting
  
      >>> w = tf.reshape(t, [-1, 2])
      >>> w_gram_sq = tf.square(tf.matmul(tf.transpose(w), w))
      >>> 0.01 * (tf.reduce_sum(w_gram_sq) - tf.linalg.trace(w_gram_sq))
      <tf.Tensor: ...>
docstr: See base class.
docstr_tok: ["See","base","class","."]
code: def __call__(self, tensors: Sequence[tf.Tensor]) -> tf.Tensor:
      """See base class."""
      if not tensors:
          return tf.zeros_like(self.scale)
  
      acc = []
      for t in tensors:
          shape = t.shape.with_rank_at_least(2)
          w = tf.reshape(t, [-1, shape[-1]])
          w_gram_sq = tf.square(tf.matmul(w, w, transpose_a=True))
          # (off-diagonal sum) = (full sum) - (diagonal sum = trace).
          acc.append(
              tf.reduce_sum(w_gram_sq) - tf.linalg.trace(w_gram_sq)
          )
      return self.scale * tf.add_n(acc)
  
imports: import abc
  from typing import Sequence
  from sonnet.src import types
  import tensorflow
label_desc: Use image node_id 3 for calling the OffDiagonalOrthogonal obj's underlying member method code with example usage: obj.__call__(tensors) and returns: unknown, tf