code: def sample_softmax(softmax_vect):
      """Samples a note from an array of softmax probabilities.
  
      Tries to do this with numpy, which requires that the probabilities add to 1.0
      with extreme precision. If this fails, uses a manual implementation.
  
      Args:
        softmax_vect: An array of probabilities.
      Returns:
        The index of the note that was chosen/sampled.
      """
      try:
          sample = np.argmax(
              np.random.multinomial(1, pvals=softmax_vect)
          )
          return sample
      except:  # pylint: disable=bare-except
          r = random.uniform(0, np.sum(softmax_vect))
          upto = 0
          for i in range(len(softmax_vect)):
              if upto + softmax_vect[i] >= r:
                  return i
              upto += softmax_vect[i]
          tf.logging.warn(
              "Error! sample softmax function shouldn't get here"
          )
          print("Error! sample softmax function shouldn't get here")
          return len(softmax_vect) - 1
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import os
  import random
  from magenta.contrib import training
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 7 for calling a global function with example usage: sample_softmax(softmax_vect) and returns: sample, unknown, i