Skip to content
DeepForgeby svx
All problems
MediumStatisticsst-244

Temperature Scaling on Logits

Problem

Apply temperature scaling and return softmax(logits / temperature) as a list of probabilities. Use the max-subtraction trick for numerical stability. Return an empty list when logits is empty or temperature <= 0.

Test cases

case 1
in: [[1,2,3],1]
expected: [0.09003057317038046,0.24472847105479764,0.6652409557748218]
case 2
in: [[0,0],2]
expected: [0.5,0.5]
case 3
in: [[1,1],2]
expected: [0.5,0.5]
case 4
in: [[],1]
expected: []
case 5
in: [[2],0]
expected: []
Starter codePython
import math
def temperature_scale(logits, temperature):
    # Your code here
    pass

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