Skip to content
DeepForgeby svx
All problems
MediumInformation Theoryinfo-022

Perplexity from Log-Likelihood

Problem

Given a list of natural-log probabilities assigned to observed events, compute perplexity:

perplexity = exp(-mean(log_probs))

Assume the list is non-empty.

Hint

Exponentiate the mean negative log-likelihood.

Test cases

case 1
in: [[-0.6931471805599453,-0.6931471805599453,-0.6931471805599453,-0.6931471805599453]]
expected: 2
case 2
in: [[0,0]]
expected: 1
case 3
in: [[-1.6094379124341003,-1.6094379124341003]]
expected: 4.999999999999999
case 4
in: [[-2.302585092994046,-1.6094379124341003]]
expected: 7.071067811865476
Starter codePython
import math
def perplexity_from_log_likelihood(log_probs):
    # Your code here
    pass

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