Is Softmax And What Does Temperature Do To It

Deep Learning interview question · Medium difficulty

What is softmax and what does temperature do to it?medium

Status
✓
Type
conceptual
Topic
is-softmax-and-what-does-temperature-do-to-it
Frequency
common
Tags
deep-learning, softmax, logits, temperature
Answer

Softmax converts raw logits to a probability distribution: softmax(z_i) = e^z_i / Σe^z_j.

Explanation

Softmax converts raw logits to a probability distribution: softmax(z_i) = e^z_i / Σe^z_j. Logits themselves are unbounded raw scores, not probabilities — for a tiny vocabulary of {Delhi, Mumbai, apple, running, .}, the model might output logits like Delhi → 9.2, Mumbai → 5.1, apple → -1.3, running → 0.4, . → 2.0, and softmax turns those into something like Delhi → 0.91, Mumbai → 0.06, . → 0.02, apple → 0.001. Temperature T scales logits before softmax: softmax(z_i/T). T<1 (e.g., 0.3): sharpens → more deterministic. T>1 (e.g., 1.5): flattens → more random/creative. T→0 → argmax (greedy). Use low temperature for extraction tasks (a document extraction pipeline), higher for creative generation.

Follow-upCan you give a production example?
Follow-upWhy can't a decoding strategy just always pick the highest-probability token?