MCPcopy Create free account
hub / github.com/rushter/MLAlgorithms / sample

Function sample

examples/nnet_rnn_text_generation.py:22–29  ·  view source on GitHub ↗
(preds, temperature=1.0)

Source from the content-addressed store, hash-verified

20
21
22def sample(preds, temperature=1.0):
23 # helper function to sample an index from a probability array
24 preds = np.asarray(preds).astype("float64")
25 preds = np.log(preds) / temperature
26 exp_preds = np.exp(preds)
27 preds = exp_preds / np.sum(exp_preds)
28 probas = np.random.multinomial(1, preds, 1)
29 return np.argmax(probas)
30
31
32X, y, text, chars, char_indices, indices_char = load_nietzsche()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected