All problems
Laplace Smoothed Unigram Probability
Problem
Laplace smoothing for a unigram adds one to every count: (count + 1) / (total_tokens + vocab_size).
Given the token count, the total tokens, and the vocabulary size, return the probability.
Hint
Every word in the vocabulary gets one pseudo-count.
Test cases
case 1
in: [5,100,50]
expected: 0.04
case 2
in: [0,10,5]
expected: 0.06666666666666667
case 3
in: [30,1000,100]
expected: 0.028181818181818183
Starter codePython
def laplace_smoothed_unigram_probability(count, total_tokens, vocab_size):
# Your code here
pass3 test cases · run your code against them in the editor