WeCodeAcademy

Generating Text and Temperature

To generate text, predict a word, add it, and repeat. Always choosing the single most likely word gives dull, repetitive text. Choosing at random in proportion to the probabilities gives variety. Temperature controls this: low temperature favours the likeliest words, high temperature flattens the odds and makes output more surprising (and more error-prone).

Examplepython
Open in editor »
Quick check

What does a higher temperature do?

Your turn: write the code

Print the probability of each word following 'the' (as a dict of word to fraction, rounded to 2 decimals).

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.