Katkat

Derive and implement calibration via temperature scaling

NewsBreakMachine Learning Engineer · Technical Screen

Last updated

This interview question evaluates core ML concepts, assumptions, math intuition, training/evaluation trade-offs, and practical failure modes in a realistic interview setting. A strong answer for Derive and implement calibration via temperature scaling states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Given a trained softmax classifier with logits z, derive temperature scaling for probability calibration: define p_i(x; T) = softmax(z_i(x) / T). Formulate the negative log-likelihood on a held-out validation set and derive the gradient with respect to T. Then write Python code to learn T by minimizing this objective (e.g., with gradient descent) and a function that applies the learned T to calibrate new predictions.