Skip to main content

Perplexity Calculator (from Log-Probs)

Computes the perplexity of a language model on a piece of text from its per-token log-probabilities, along with mean negative log-likelihood, bits per token and each token's surprisal.

For anyone evaluating a model from API logprobs or eval output.

Last updatedHow we build & check our tools
Results will appear here once you enter your values.

What it calculates

Paste one log-probability per token, separated by commas or whitespace, and pick the log base. The tool outputs four things.

  • Perplexity = exp(mean NLL), where NLL is measured in nats (natural log).
  • Mean NLL = average of −ln p across tokens, in nats per token.
  • Bits per token = mean NLL / ln 2.
  • Per-token surprisal in bits, in input order.

This is the language-model evaluation metric from information theory. It has no connection to any search product of a similar name.

Worked examples

  • Defaults: −0.5, −1.2, −0.3, −2.0 in natural log. Mean NLL 1.0, perplexity 2.7183, bits per token 1.4427. Token surprisals are 0.7213, 1.7312, 0.4328 and 2.8854 bits; the fourth token contributes most.
  • Base check: four values of −1 read as base 2 mean each token had probability 0.5. The mean NLL is ln 2 = 0.6931, perplexity is exactly 2 and bits per token is 1.
  • Perfect model: all zeros give perplexity 1 and 0 bits per token.

Caveats and sources

  • Context handling: the tool does not know how the log-probabilities were produced. Whether the first token was scored, how long context was, and whether a sliding window was used all change the numbers you paste in.
  • Tokenizer dependence: perplexity is only comparable between runs with the same tokenizer and text.
  • Single sequence: for a corpus, pool all token log-probabilities into one list rather than averaging per-document perplexities.

Sources: Jelinek, F., Mercer, R. L., Bahl, L. R. and Baker, J. K. (1977), Perplexity: a measure of the difficulty of speech recognition tasks, Journal of the Acoustical Society of America 62(S1), S63. Hugging Face Transformers documentation, Perplexity of fixed-length models.

Frequently Asked Questions

Common questions about the Perplexity Calculator (from Log-Probs)

Perplexity is the exponential of the mean negative log-likelihood: exp(−(1/N) Σ ln p(token)). The tool converts your values to natural logs if they are base 2 or base 10, averages the negatives, and exponentiates. Four tokens with natural-log probabilities −0.5, −1.2, −0.3 and −2.0 sum to −4.0, so the mean NLL is 1.0 and perplexity is e, about 2.718.

From the same team

Stop paying per token — route AI requests to your own GPU

Wide Area AI is a local-first AI gateway: repeated requests hit an edge cache, the rest run free on your own hardware, and the cloud is only a failover. OpenAI-compatible endpoint, free tier.

Start routing — free

Explore More Tools

Explore these related tools for your next step.

ai
ai
ai
ai
ai
ai