function sample(probs, temperature) {
  return tf.tidy(() => {
    const logits = tf.div(tf.log(probs), Math.max(temperature, 1e-6));
    const isNormalized = false;
    // `logits` is for a multinomial distribution, scaled by the temperature.
    // We randomly draw a sample from the distribution.
    return tf.multinomial(logits, 1, null, isNormalized).dataSync()[0];
  });
}
Draw a sample based on probabilities.

@param {tf.Tensor} probs Predicted probability scores, as a 1D `tf.Tensor` of
  shape `[charSetSize]`.
@param {tf.Tensor} temperature Temperature (i.e., a measure of randomness
  or diversity) to use during sampling. Number be a number > 0, as a Scalar
  `tf.Tensor`.
@returns {number} The 0-based index for the randomly-drawn sample, in the
  range of `[0, charSetSize - 1]`.