MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / sample

Function sample

lstm-text-generation/model.js:157–165  ·  view source on GitHub ↗
(probs, temperature)

Source from the content-addressed store, hash-verified

155 * range of `[0, charSetSize - 1]`.
156 */
157export function sample(probs, temperature) {
158 return tf.tidy(() => {
159 const logits = tf.div(tf.log(probs), Math.max(temperature, 1e-6));
160 const isNormalized = false;
161 // `logits` is for a multinomial distribution, scaled by the temperature.
162 // We randomly draw a sample from the distribution.
163 return tf.multinomial(logits, 1, null, isNormalized).dataSync()[0];
164 });
165}

Callers 2

model_test.jsFile · 0.90
generateTextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected