(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.
Samples a note from an array of softmax probabilities.
Samples a note from an array of softmax probabilities .
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
def sample_softmax ( softmax_vect ) : 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