Skip to content
DeepForgeby svx
All problems
HardML Fundamentalsml-247

Temperature from NLL Grid

Problem

Choose the temperature minimizing the multiclass negative log-likelihood. For each temperature compute softmax(logits / T) per sample and average -log p[true].

Return [best_temperature, best_nll]; ties keep the earlier candidate, and empty input returns [0.0, 0.0].

Hint

Evaluate the NLL on a grid of candidate temperatures and keep the minimum.

Test cases

case 1
in: [[[2,0],[0,2]],[0,1],[0.5,1,2]]
expected: [0.5,0.01814992791780973]
case 2
in: [[[1,0]],[1],[0.5,1,2,5]]
expected: [5,0.7981388693815918]
case 3
in: [[[0,0]],[0],[1,2]]
expected: [1,0.6931471805599453]
case 4
in: [[],[],[1]]
expected: [0,0]
Starter codePython
import math
def temperature_from_nll(logits, y_true, temperatures):
    # Returns [best_temperature, best_nll]
    # Your code here
    pass

4 test cases · run your code against them in the editor