October 2018
Intermediate to advanced
472 pages
10h 57m
English
In text generation, the way we choose the succeeding character is crucial. The most common way (greedy sampling) leads to repetitive characters that does not produce a coherent language. This is why we use a different approach called stochastic sampling. This adds a degree of randomness to the prediction probability distribution.
Use the following code to re-weight the prediction probability distribution and sample a character index:
def sample(preds, temperature=1.0): preds = np.asarray(preds).astype('float64') preds = np.log(preds) / temperature exp_preds = np.exp(preds) preds = exp_preds / np.sum(exp_preds) probas = np.random.multinomial(1, preds, 1) return np.argmax(probas)
Now, we iterate the training ...
Read now
Unlock full access