Language Model Cross-Entropy Loss (Nats & Bits/Byte) to Perplexity Calculator

Convert LLM cross-entropy validation loss into Perplexity (e^Loss) and Bits-Per-Byte.

Model Perplexity (PPL = e^Loss) 6.36 PPL
Bits Per Token (BPT) 2.67 bits/tok
Bits Per UTF-8 Byte (BPB) 0.7 bits/byte
Mean Next-Token Branching Factor 6.36 choices
Inputs
Try:
nats
Average token cross-entropy validation loss in nats.
bytes/tok
Average UTF-8 bytes per tokenizer subword token.
Results & Graph
Model Perplexity (PPL = e^Loss)
6.36 PPL
Bits Per Token (BPT)
2.67 bits/tok
Bits Per UTF-8 Byte (BPB)
0.7 bits/byte
Mean Next-Token Branching Factor
6.36 choices

Model Perplexity (PPL = e^Loss)

Graph 1 • How the inputs feed Cross-Entropy & Perplexity
Language Model Cross-Entropy Loss (Nats & Bits/Byte) to Perplexity Calculator • Custom Domain Schematic (Machine Learning & Evaluation) crossEntavgBytesCross-Entropy & Perple Cross Entropy Loss Nats: 1.85 nats • Avg Bytes Per Token: 3.80 bytes/tok MODEL PERPLEXITY (PPL = E^ 6.36 PPL • Bits Per Token (BPT): 2.67 bits/tok • Bits Per UTF-8 Byte (B: 0.7 bits/byte Eq: Perplexity = exp(CrossEntropyLos
Graph 2 • Model Perplexity (PPL = e^Loss) as Cross Entropy Loss Nats changes (40% to 160% of current)
0 PPL 10.62 PPL 21.23 PPL 2.10 0.740nats 3.03 1.11nats 4.39 1.48nats 6.36 1.85nats 9.21 2.22nats 13.33 2.59nats 19.30 2.96nats
Graph 3 • Cross Entropy Loss Nats and Avg Bytes Per Token together Compares Model Perplexity (PPL = e^Loss) when Avg Bytes Per Token is shifted +25% (solid) vs. −25% (dashed).
0 PPL 6.09 PPL 12.19 PPL --- Avg Bytes Per Token @ 75% 3.65 -30% 4.82 -15% 6.36 +0% 8.39 +15% 11.08 +30%
Summary: A cross-entropy validation loss of 1.85 nats equals a Perplexity of 6.36, 2.669 bits/token, and 0.702 bits/byte.
Summary: A cross-entropy validation loss of 1.85 nats equals a Perplexity of 6.36, 2.669 bits/token, and 0.702 bits/byte.
Interactive chart & math engine powered by CalculatorGraph

Formula: Cross-Entropy & Perplexity Systems Engineering Formula

Perplexity = exp(CrossEntropyLossnats)
BitsPerToken = Lossnats / ln(2)
BPB = BitsPerToken / BytesPerToken
Perplexity = exp(CrossEntropyLoss_nats); BitsPerToken = Loss_nats / ln(2); BPB = BitsPerToken / BytesPerToken
  • crossEntropyLossNats: Cross Entropy Loss Nats (nats)
  • avgBytesPerToken: Avg Bytes Per Token (bytes/tok)

Frequently Asked Questions

Is a perplexity of 6.36 good?

It depends on the dataset, the tokenizer and the context length, so there is no universal threshold. A perplexity only means something next to another model scored on the same text with the same tokens. For a tokenizer-neutral comparison, look at the 0.702 bits per byte line and compare it with other models measured in bits per byte on the same evaluation set.

Should I enter training loss or validation loss?

Validation loss, computed over a full held-out split. Training loss is measured on data the model is learning from, so it is optimistic and keeps falling even when the model starts to overfit. A gap between the two is itself useful: a training loss well below the validation loss means the perplexity you would quote from training is not one the model achieves on new text.

How do I measure bytes per token?

Tokenize your evaluation text with the same tokenizer the model uses, count the tokens, count the UTF-8 bytes of the original text, and divide bytes by tokens. Do not count characters instead of bytes; accented letters and non-Latin scripts take two to four bytes each. The default 3.8 is a placeholder, not a property of any particular tokenizer.

Why does bits per byte change when perplexity does not?

Perplexity depends only on loss, while bits per byte also divides by bytes per token. Change the second input from 3.8 to 4.5 and bits per byte falls from 0.702 to 0.593, with perplexity fixed at 6.36. Each token now covers more text, so the same bits are spread across more bytes. Only the description of the text changed.

My framework reports loss in bits. What do I enter?

Convert to nats first by multiplying by ln 2, about 0.693. For example, 2.669 bits per token becomes 1.85 nats, the default. Entering a bits figure directly as nats would make the perplexity far too high, because e raised to the bit value is larger than 2 raised to it. Check the documentation of your evaluation harness for the log base.

What perplexity would a model get by guessing at random?

A model that spread its probability evenly across its whole vocabulary would have a perplexity equal to the vocabulary size, and a loss equal to the natural log of that size. That is the upper bound for a model that has learned nothing. Real trained models sit far below it, which is why perplexities in single or low double digits, like the 6.36 default, are typical.

Can perplexity be lower than 1?

No. Perplexity is e raised to a non-negative loss, so its minimum is 1, reached only if the model predicts every token with certainty. The calculator will show values below 1 if you type a negative loss, but that result is meaningless. A negative input usually means a log-probability was entered with the wrong sign.

Does a lower perplexity always mean better generated text?

Not always. Perplexity measures how well the model predicts held-out text token by token. It says nothing directly about factual accuracy, instruction following or style. Two models with close perplexities can feel very different in use, and fine-tuning for helpfulness often raises perplexity on general text. Use it to track pretraining progress, alongside task evaluations.

How much does a 0.1 nat improvement change perplexity?

It divides perplexity by e to the 0.1, about 1.105, so roughly a 10% reduction whatever the starting point. From the default 6.36 that brings perplexity to about 5.75, which you can confirm by entering 1.75 nats. In bits, the same improvement is 0.144 bits per token, or 0.038 bits per byte at 3.8 bytes per token.

Why is bits per byte used for compression benchmarks?

Because it is exactly the compressed size an ideal arithmetic coder would achieve using the model's predictions, measured against the raw bytes. A score of 0.702 bits per byte means about 0.702 bits of output for every 8 bits of input. Since it is defined on bytes, it compares language models, classic compressors and byte-level models on one scale.

What does the branching factor line add?

Nothing numerically; it is the perplexity again, labelled as choices. It is there as an interpretation aid. A perplexity of 3, as in the 1.1 nat preset, means the model is as unsure as a uniform pick among three tokens. It should not be read as the size of a shortlist the model actually keeps.

Can I convert perplexity back to loss?

Yes, take the natural logarithm. A perplexity of 16.44 corresponds to 2.8 nats, and a perplexity of 3 to about 1.1 nats. This is useful when a report quotes only perplexity and you want bits per byte: get the loss with ln, enter it here with the right bytes per token, and read the third line.

A validation loss of 1.85 nats is a perplexity of 6.36

Paste in the loss your training script printed, and the calculator raises e to that power. The default 1.85 nats gives a perplexity of 6.36. That is the whole perplexity calculation; everything else on the panel is a change of units.

The branching factor line repeats the same 6.36 on purpose. Perplexity has a plain reading: the model is, on average, as uncertain about the next token as it would be if it were choosing uniformly among about 6.36 equally likely options. It is not saying the model literally keeps six candidates. A model might put most of its probability on one token and scatter the rest thinly, and still land on the same average uncertainty.

Read the number as a geometric average over every token in the evaluation set. Some tokens, the second half of a common word for instance, are nearly certain and contribute almost nothing. Others, such as the first word of a new sentence, are hard. The 6.36 is what they average to when combined in log space.

Only two inputs drive the whole panel. The loss sets perplexity and bits per token on its own; bytes per token touches nothing except the bits per byte line. So if you only care about perplexity, the second field can stay at its default.

Nats, bits and dividing by ln 2

Cross-entropy loss in PyTorch, JAX and most training frameworks uses the natural logarithm, so the unit is nats. Information theory more often counts in bits, which use base-2 logarithms. Converting is a single division by ln 2, about 0.693. The default 1.85 nats becomes 2.669 bits per token, shown on the panel as 2.67.

A handy reference point: a loss of 0.693 nats is exactly one bit per token and a perplexity of 2, the uncertainty of a fair coin toss. Run it and the calculator shows 1 bit per token and a perplexity of 2. Every extra bit of loss doubles the perplexity.

Check which unit your number is in before entering it. Some evaluation harnesses already report bits per token or bits per byte, and entering a bits figure as nats will overstate the perplexity. If you have bits, multiply by 0.693 to get nats first. Loss computed with base-10 logarithms is rare in machine learning, but it would need multiplying by ln 10, about 2.303, instead.

The conversion runs the other way for sanity checks. If a paper quotes 2.67 bits per token, multiplying by 0.693 recovers 1.85 nats, and entering that here should reproduce the perplexity of 6.36 it implies.

From 2.669 bits per token to 0.702 bits per byte

Bits per byte divides bits per token by the average number of UTF-8 bytes each token covers. On the default 3.8 bytes per token, 2.669 bits becomes 0.702 bits per byte. The full formula is loss divided by (ln 2 × bytes per token).

The bytes per token figure has to describe the same text and the same tokenizer that produced the loss. Measure it directly: count the UTF-8 bytes in the evaluation set, count the tokens the tokenizer produced for it, and divide. Guessing it from a different corpus is the most common way to get this line wrong. Text in languages that use multi-byte characters, source code, and numbers all tokenize differently from plain English prose.

The effect of this input is large. Keep the loss at 1.85 and raise bytes per token to 4.5, and bits per byte falls to 0.593 while perplexity stays at 6.36. Nothing about the model changed. Only the description of the text did.

Bits per byte also has a physical meaning. A model with this score could, in principle, drive an arithmetic coder that compresses the text to 0.702 bits for every 8 bits of input, under 9% of its original size.

Comparing two models that use different tokenizers

Perplexity is defined per token, so it only compares fairly when both models cut the text into the same tokens. A model with a larger vocabulary usually produces fewer, longer tokens. Each token then carries more information and is harder to predict, so its per-token loss and perplexity rise even if it models the text just as well.

Bits per byte removes that problem. Both models are scored against the same fixed count of UTF-8 bytes, so the tokenizer drops out. If model A has a loss of 1.85 at 3.8 bytes per token and model B has a higher loss spread over more bytes per token, compare the two bits per byte figures, not the two perplexities.

Character-level and byte-level models fit the same framework. A byte-level model has exactly 1 byte per token, so its bits per token and bits per byte are the same number. Entering 1 here shows that: with the default loss, both lines read 2.67.

The same caution applies to published numbers. A perplexity quoted in a paper is only comparable with yours if the tokenizer, the dataset and the evaluation split all match.

Why perplexity jumps between 1.1, 1.85 and 2.8 nats

Because perplexity is an exponential of the loss, equal steps in loss are not equal steps in perplexity. The Lower preset at 1.1 nats gives a perplexity of 3. The default at 1.85 gives 6.36. The Higher preset at 2.8 gives 16.44. Each step of roughly 0.75 to 0.95 nats more than doubles the figure.

The bit figures stay linear. Bits per token run 1.587, 2.669 and 4.04, and bits per byte run 0.418, 0.702 and 1.063, each in proportion to the loss.

This matters when reading training curves. Late in training a loss improvement of 0.05 nats looks tiny on a loss plot, yet it cuts perplexity by about 5%. Early in training, when the loss is high, the same 0.05 nats moves perplexity by many whole points. Quoting progress in perplexity can make early gains look dramatic and late gains look trivial, when in log terms they are the same size.

For that reason many teams track loss or bits per byte on their dashboards and only convert to perplexity for reports, where readers expect it.

Averaging loss across batches before taking e to the power

Evaluation usually runs over many batches. The correct way to combine them is to take the token-weighted mean of the losses, then exponentiate once. Exponentiating each batch first and averaging the perplexities gives a larger number, because the exponential function curves upward. A batch with a loss of 2.8 contributes 16.44 to that average, far more than its share.

Weighting matters too. If batches contain different numbers of real tokens, for example because sequences are padded, a plain mean of batch losses over-weights short batches. Sum the per-token negative log-likelihoods and divide by the total token count instead.

Many frameworks report the mean loss of the last batch or a smoothed running average during training. Neither is the validation loss. Run a full pass over the validation split, collect the summed loss and the token count, and enter that ratio here.

Masked tokens, padding and what the loss covers

The figure you enter is only as meaningful as the set of tokens it was averaged over. Padding tokens should be excluded; if they are included and easy to predict, they drag the loss down and flatter the perplexity. In instruction tuning, the prompt part of each example is often masked so only the response is scored, which typically raises the loss because responses are harder to predict than templates.

Sequence length changes the answer as well. A model evaluated with long context has more information for later tokens and usually scores a lower loss than the same model scored on short windows. Two runs at 1.85 nats with different context lengths are not the same result.

Label smoothing is another trap. If the training loss includes a smoothing term, it is not a pure cross-entropy, and its exponential is not a true perplexity. Report the unsmoothed validation loss for this conversion.

Write down these choices next to the number. A loss of 1.85 recorded as "validation, padding masked, full context, no smoothing" can be compared with next month's run. A bare 1.85 cannot.

A loss of zero or below, and very small bytes per token

Cross-entropy cannot be negative, and a loss of exactly 0 would mean the model assigned probability 1 to every correct token. The calculator still accepts both. At 0 it shows a perplexity of 1. At −0.5 it returns a perplexity of 0.61 and negative bits, which have no meaning. If you see that, the number you pasted was probably a log-probability with its sign flipped, or a difference between two losses.

Bytes per token is quietly floored at 0.5. Enter 0.1 and bits per byte reads 5.34, which is the default 2.669 bits divided by 0.5, not by 0.1. Real UTF-8 text always has at least 1 byte per token for byte-level models and more for subword tokenizers, so this floor should rarely matter in practice.

A useful sanity bound runs the other way. A model that guessed uniformly over its whole vocabulary would score a loss equal to the natural log of the vocabulary size. Any trained model should be far below that.