Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-354

Unigram Sentence Log Probability

Problem

Under a unigram model, the sentence log probability is the sum of the log probabilities of its tokens. Return None when any token is missing from the table.

Given the tokens and a probability table keyed by token strings, return the log probability.

Hint

Logs turn the product of probabilities into a sum.

Test cases

case 1
in: [["a","b"],{"a":0.5,"b":0.5}]
expected: -1.3862943611198906
case 2
in: [["a"],{"a":0.25}]
expected: -1.3862943611198906
case 3
in: [["a"],{"b":1}]
expected: null
Starter codePython
def unigram_sentence_log_probability(tokens, probs):
    # Your code here
    pass

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