Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-127

Language Model Interpolation Weights

Problem

Compute interpolation weights from held-out perplexities: each weight is proportional to the inverse perplexity, 1 / ppl, normalized so the weights sum to 1.

Return the weights in the same order as the input, and an empty list for empty input.

Hint

Invert each perplexity, then divide every inverse by the total.

Test cases

case 1
in: [[2,4]]
expected: [0.6666666666666666,0.3333333333333333]
case 2
in: [[1]]
expected: [1]
case 3
in: [[10,10]]
expected: [0.5,0.5]
case 4
in: [[]]
expected: []
Starter codePython
def lm_interpolation_weights(perplexities):
    # Your code here
    pass

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