code: def top_k_softmax(x, k):
      """Calculate softmax(x), select top-k and rescale to sum to 1."""
      x = tf.nn.softmax(x)
      top_x, _ = tf.nn.top_k(x, k=k + 1)
      min_top = tf.reduce_min(top_x, axis=-1, keepdims=True)
      x = tf.nn.relu((x - min_top) + 1e-12)
      x /= tf.reduce_sum(x, axis=-1, keepdims=True)
      return x, tf.reduce_max(top_x, axis=-1)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import functools
  import math
  import os
  from six.moves import range
  from tensor2tensor.layers import common_attention
  from tensor2tensor.layers import common_image_attention
  from tensor2tensor.layers import common_layers
  from tensor2tensor.layers import discretization
  from tensor2tensor.layers import latent_layers
  from tensor2tensor.layers import modalities
  from tensor2tensor.models import transformer
  from tensor2tensor.utils import beam_search
  from tensor2tensor.utils import contrib
  from tensor2tensor.utils import expert_utils
  from tensor2tensor.utils import registry
  from tensor2tensor.utils import t2t_model
  import tensorflow.compat.v1
  from tensorflow.compat.v1 import estimator
label_desc: Use image node_id 4 for calling a global function with example usage: top_k_softmax(x, k) and returns: x,  tf