All problems
Perplexity from Log Probabilities
Problem
Perplexity is exp(-mean(log probabilities)) over the observed tokens.
Given the list of per-token log probabilities (natural log), return the perplexity.
Hint
Average the negative log-likelihood and exponentiate.
Test cases
case 1
in: [[-1,-2,-3]]
expected: 7.38905609893065
case 2
in: [[0,0]]
expected: 1
case 3
in: [[-0.6931471805599453,-0.6931471805599453]]
expected: 2
Starter codePython
def perplexity_from_log_probabilities(log_probs):
# Your code here
pass3 test cases · run your code against them in the editor