What is softmax and what does temperature do to it?medium
Softmax converts raw logits to a probability distribution: softmax(z_i) = e^z_i / Σe^z_j.
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.