Skip to content
DeepForgeby svx
All problems
EasyInformation Theoryinfo-268

Token Perplexity

Problem

Convert an average negative log-likelihood per token measured in nats to perplexity:

perplexity = exp(nll_nats_per_token)

Hint

Perplexity is the effective number of equally likely next tokens.

Test cases

case 1
in: [0]
expected: 1
case 2
in: [0.6931471805599453]
expected: 2
case 3
in: [1.6094379124341003]
expected: 4.999999999999999
case 4
in: [2.302585092994046]
expected: 10.000000000000002
Starter codePython
import math
def token_perplexity(nll_nats_per_token):
    # Your code here
    pass

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