(preds, temperature=1.0)
| 20 | |
| 21 | |
| 22 | def 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 | |
| 32 | X, y, text, chars, char_indices, indices_char = load_nietzsche() |
no outgoing calls
no test coverage detected