Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-387

Length Normalized Beam Selection

Problem

Each beam candidate has a cumulative log probability and a length. Normalize each score as logprob / length^alpha and return the index of the best candidate, breaking ties toward the earliest index.

Given candidates as [logprob, length] rows and alpha, return the index.

Hint

Compare the normalized scores rather than raw log probabilities.

Test cases

case 1
in: [[[-2,4],[-3,3]],1]
expected: 0
case 2
in: [[[-1,2],[-1,2]],0.5]
expected: 0
case 3
in: [[[-5,1],[-4,2]],1]
expected: 1
Starter codePython
def length_normalized_beam_selection(candidates, alpha):
    # Your code here
    pass

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