PythiloLesson 1 of 8 · progress kept in this browser

Stable Softmax & Temperature

Subtract the largest logit before exponentiating. Temperature changes concentration without changing rank, and equal scores share probability.

import math
logits = [1000, 1000]
weights = [math.exp(x-max(logits)) for x in logits]
print([x/sum(weights) for x in weights])
Your task

softmax(logits, temperature) returns normalized probabilities for finite logits and temperature > 0. Return [] for empty input. Avoid overflow for large logits.