Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-386

Beam Score Length Normalization

Problem

Length-normalized beam scoring divides the cumulative log probability by length^alpha.

Given the log probability, the sequence length, and alpha, return the normalized score.

Hint

Alpha equal to one is the plain average log probability.

Test cases

case 1
in: [-2,4,1]
expected: -0.5
case 2
in: [-6,3,0.5]
expected: -3.464101615137755
case 3
in: [0,1,2]
expected: 0
Starter codePython
def beam_score_length_normalization(logprob, length, alpha):
    # Your code here
    pass

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