def sample_softmax(softmax_vect):
    'Samples a note from an array of softmax probabilities.\n\n  Tries to do this with numpy, which requires that the probabilities add to 1.0\n  with extreme precision. If this fails, uses a manual implementation.\n\n  Args:\n    softmax_vect: An array of probabilities.\n  Returns:\n    The index of the note that was chosen/sampled.\n  '
    try:
        sample = np.argmax(np.random.multinomial(1, pvals=softmax_vect))
        return sample
    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)
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.
def sample_softmax(softmax_vect):
    'Samples a note from an array of softmax probabilities.\n\n  Tries to do this with numpy, which requires that the probabilities add to 1.0\n  with extreme precision. If this fails, uses a manual implementation.\n\n  Args:\n    softmax_vect: An array of probabilities.\n  Returns:\n    The index of the note that was chosen/sampled.\n  '
    try:
        sample = np.argmax(np.random.multinomial(1, pvals=softmax_vect))
        return sample
    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)