Skip to content
DeepForgeby svx
All problems
MediumML Fundamentalsml-065

Temperature Scaling

Problem

Apply temperature scaling to logits: return the probabilities softmax(logits / temperature).

If logits is empty or temperature <= 0, return [].

Hint

Divide every logit by the temperature before applying a numerically stable softmax.

Test cases

case 1
in: [[2,0],0.5]
expected: [0.9820137900379085,0.017986209962091555]
case 2
in: [[2,0],10]
expected: [0.549833997312478,0.4501660026875221]
case 3
in: [[1,1],5]
expected: [0.5,0.5]
case 4
in: [[2,0],1]
expected: [0.8807970779778823,0.11920292202211755]
Starter codePython
import math
def temperature_scaled_softmax(logits, temperature):
    # Your code here
    pass

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