All problems
Softmax Denominator From Logsumexp
Problem
Compute the log-sum-exp denominator of each score row with the stable max-subtraction trick: m + log(sum(exp(x - m))).
The signature is softmax_logsumexp(scores). Return one value per row; this is the logarithm of the softmax denominator.
Hint
Subtracting the row maximum prevents overflow while leaving the log-sum-exp value unchanged.
Test cases
case 1
in: [[[0,0]]]
expected: [0.6931471806]
case 2
in: [[[1,2,3]]]
expected: [3.4076059644]
case 3
in: [[[1000,1000]]]
expected: [1000.6931471806]
case 4
in: [[[-1,-1,-1]]]
expected: [0.0986122887]
case 5
in: [[[5]]]
expected: [5]
Starter codePython
import math
def softmax_logsumexp(scores):
# Your code here
pass5 test cases · run your code against them in the editor