code: def padded_accuracy_topk(
      predictions, labels, k, weights_fn=common_layers.weights_nonzero
  ):
      """Percentage of times that top-k predictions matches labels on non-0s."""
      with tf.variable_scope(
          "padded_accuracy_topk", values=[predictions, labels]
      ):
          (
              padded_predictions,
              padded_labels,
          ) = common_layers.pad_with_zeros(predictions, labels)
          weights = weights_fn(padded_labels)
          effective_k = tf.minimum(
              k, common_layers.shape_list(padded_predictions)[-1]
          )
          _, outputs = tf.nn.top_k(padded_predictions, k=effective_k)
          outputs = tf.to_int32(outputs)
          padded_labels = tf.to_int32(padded_labels)
          padded_labels = tf.expand_dims(padded_labels, axis=-1)
          padded_labels += tf.zeros_like(outputs)  # Pad to same shape.
          same = tf.to_float(tf.equal(outputs, padded_labels))
          same_topk = tf.reduce_sum(same, axis=-1)
          return same_topk, 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 7 for calling a global function with example usage: padded_accuracy_topk(predictions, labels, k, weights_fn) and returns: same_topk,  weights