code: def multinomial_sample(x, vocab_size, temperature):
      """Multinomial sampling from a n-dimensional tensor."""
      if temperature > 0:
          samples = tf.multinomial(
              tf.reshape(x, [-1, vocab_size]) / temperature, 1
          )
      else:
          samples = tf.argmax(x, axis=-1)
      reshaped_samples = tf.reshape(
          samples, common_layers.shape_list(x)[:-1]
      )
      return tf.to_int32(reshaped_samples)
  
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 9 for calling a global function with example usage: multinomial_sample(x, vocab_size, temperature) and returns: tf