code: def padded_variance_explained(
      predictions, labels, weights_fn=common_layers.weights_all
  ):
      """Explained variance, also known as R^2."""
      predictions, labels = common_layers.pad_with_zeros(
          predictions, labels
      )
      targets = labels
      weights = weights_fn(targets)
  
      y_bar = tf.reduce_mean(weights * targets)
      tot_ss = tf.reduce_sum(weights * tf.pow(targets - y_bar, 2))
      res_ss = tf.reduce_sum(weights * tf.pow(targets - predictions, 2))
      r2 = 1.0 - res_ss / tot_ss
      return r2, tf.reduce_sum(weights)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import six
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.utils import bleu_hook
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import rouge
  from tensor2tensor.utils import sari_hook
  import tensorflow.compat.v1
  from tensorflow.python.util import tf_inspect
label_desc: Use image node_id 6 for calling a global function with example usage: padded_variance_explained(predictions, labels, weights_fn) and returns: r2,  tf