Lesson 3 of 5 · 2 min
Temperature changes the dice
Temperature reshapes the probabilities before one token is picked. Low values make the favourite win nearly always. High values give unlikely tokens a chance.
import math
scores = {"Paris": 5.0, "London": 3.0, "banana": 0.5}
def probabilities(temperature):
exps = {k: math.exp(v / temperature) for k, v in scores.items()}
total = sum(exps.values())
return {k: round(v / total, 3) for k, v in exps.items()}
for t in (0.2, 1.0, 2.5):
print(t, probabilities(t))
