code: def set_precision(
      predictions, labels, weights_fn=common_layers.weights_nonzero
  ):
      """Precision of set predictions.
  
      Args:
        predictions : A Tensor of scores of shape [batch, nlabels].
        labels: A Tensor of int32s giving true set elements,
          of shape [batch, seq_length].
        weights_fn: A function to weight the elements.
  
      Returns:
        hits: A Tensor of shape [batch, nlabels].
        weights: A Tensor of shape [batch, nlabels].
      """
      with tf.variable_scope(
          "set_precision", values=[predictions, labels]
      ):
          labels = tf.squeeze(labels, [2, 3])
          weights = weights_fn(labels)
          labels = tf.one_hot(labels, predictions.shape[-1])
          labels = tf.reduce_max(labels, axis=1)
          labels = tf.cast(labels, tf.bool)
          return tf.to_float(tf.equal(labels, predictions)), 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 22 for calling a global function with example usage: set_precision(predictions, labels, weights_fn) and returns: tf,  weights