Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-082

Beam Length Normalization

Problem

Return the length-normalized beam score score / (length ** alpha).

Return 0.0 when length is not positive.

Hint

Dividing a negative log score by a growing length makes it less negative.

Test cases

case 1
in: [-2,2,1]
expected: -1
case 2
in: [-4,4,0.5]
expected: -2
case 3
in: [0.5,1,0.7]
expected: 0.5
case 4
in: [-3,0,1]
expected: 0
case 5
in: [-8,2,2]
expected: -2
Starter codePython
def beam_length_normalization(score, length, alpha):
    # Your code here
    pass

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