
Perplexity from log-probabilities (Kamath Ch 8)
Source:R/kamath_llm2_native.R
morie_kamath_perplexity.Rdexp(-mean log p); positive log-probabilities are refused because they are probabilities or logits, not natural logs.
Examples
morie_kamath_perplexity(c(-1, -2))
#> $estimate
#> [1] 4.481689
#>
#> $perplexity
#> [1] 4.481689
#>
#> $mean_nll
#> [1] 1.5
#>
#> $total_nll
#> [1] 3
#>
#> $bits_per_token
#> [1] 2.164043
#>
#> $base
#> [1] "e"
#>
#> $n
#> [1] 2
#>
#> $method
#> [1] "Perplexity exp(mean negative log-likelihood)"
#>