Skip to content
DeepForgeby svx
All problems
HardNLPnlp-353

Interpolated Bigram Probability

Problem

Interpolated language modeling mixes bigram and unigram estimates: lam * (bigram_count / bigram_total) + (1 - lam) * (unigram_count / unigram_total).

Given lam, the counts and totals for the bigram and unigram tables, return the probability.

Hint

The mixing weight trades specificity for coverage.

Test cases

case 1
in: [0.7,10,100,20,1000]
expected: 0.076
case 2
in: [0.5,0,50,5,500]
expected: 0.005
case 3
in: [1,4,8,1,100]
expected: 0.5
Starter codePython
def interpolated_bigram_probability(lam, bigram_count, bigram_total, unigram_count, unigram_total):
    # Your code here
    pass

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