Compare validation loss on a fixed, counted evaluation contract
Decompose token-weighted domain loss, derive perplexity correctly, and keep tokenizer, context, masks, and evaluation mixture stable.
On this page
The question for today
What you’ll understand
- Calculate a pooled validation loss from domain numerators and valid-token counts.
- Explain why pooled perplexity is not an arithmetic mean of domain perplexities.
- Distinguish model changes from evaluation-mixture and context-policy changes.
Validation loss has meaning only alongside the evaluated tokens and their conditioning context. A model can appear worse when a report silently includes more difficult domains, or appear better when more prefix context is supplied. Tokenizers also change the prediction units. Freeze the evaluation contract and retain domain-level numerators and counts so changes can be explained. A single pooled perplexity is a compact statistic, not a complete description of language quality, downstream usefulness, or every domain's behavior.
Preserve what each reported token was allowed to see
Record evaluation document identities, tokenizer artifact, serialization, truncation or sliding-window policy, target eligibility, document boundaries, and numerical evaluation mode. The same raw text can have different negative log-likelihood when context resets more often. If overlapping windows are used, distinguish context-only tokens from newly scored targets so repeated context is not counted as new evaluation evidence. Disable or explicitly control stochastic effects and state whether the result is deterministic within the chosen environment.
Keep evaluation material separate from tokenizer fitting and model training according to the declared split. Development losses can guide hyperparameters, but repeated selection adapts the experiment to that development set; a final untouched test serves a different role. An evaluation contamination scan can identify known overlaps under its method, not prove the absence of every semantic duplicate. Attach the actual scan scope and corpus versions rather than turning a clean report into an unrestricted no-leakage guarantee.
Exponentiate the pooled mean, not each mean before averaging
Perplexity for a natural-log token loss is exp(L). The pooled perplexity is therefore a weighted geometric combination of domain perplexities, because pooling happens in log-loss space. An arithmetic average of perplexities generally gives a different number. Retain sufficient precision in summed losses and counts before exponentiation, and do not mix bits with nats. If losses are measured in bits, the corresponding base is two rather than e.
Cross-tokenizer perplexities are not directly comparable as though tokens were identical units. Even with one tokenizer, changed context-window stride or boundary rules can alter the task. A raw-byte-normalized description can sometimes support another declared comparison, but it still needs a precisely defined serialization and likelihood calculation; it is not obtained by casually relabeling per-token perplexity. For quality assessment, report domain behavior and relevant controlled evaluations alongside the aggregate rather than claiming that one lower number settles every use case.
Keep the comparison mixture explicit
Report the observed token-weighted validation mixture and, when useful, a separately fixed reporting mixture. These answer different questions. If domain losses remain constant while the report shifts toward a harder domain, the pooled loss can rise with no within-domain regression. Conversely, a large easy domain can hide a decline on a small important domain. Compare the domain values first, then state the weighting decision that produces the headline number.
The probability lab provides a simple two-domain count model under hypothetical independent assignment. Reset, set both p=0.1 and n=20, predict two expected assignments to the minority domain, then Play or Step. Reset and set both p=0.5,n=20 for ten expected assignments. The exact binomial bars describe count uncertainty under that model, not token losses, perplexity, document correlation, or a real held-out sample. Actual validation weights should come from measured valid-token counts, not from this toy expectation.
Work it through
Pool two domains before computing perplexity
A fixed validation set has 900 valid targets in domain A with loss two nats per token and 100 in B with loss four. Use the same tokenizer, contexts, masks, and model for both domains.
The domain loss sums are 900×2=1,800 nats and 100×4=400 nats. The total is 2,200 nats over 1,000 valid targets.
The pooled loss is 2.2 nats per token and pooled perplexity is exp(2.2)≈9.0250. Domain perplexities are exp(2)≈7.3891 and exp(4)≈54.5982.
The arithmetic weighted average 0.9×7.3891+0.1×54.5982≈12.1100 is not the pooled perplexity. Pool the log-loss numerators and counts, then exponentiate the resulting mean.
The reported pooled perplexity is approximately 9.0250 under this fixed token-weighted contract. Domain values remain necessary to interpret the aggregate.
The living notebook
Explore the model
Interactive lab · probability
Inspect one hypothetical domain-count mechanism
Fresh Reset → set both p=0.1,n=20 predicts mean count 2; Reset → set both p=0.5,n=20 predicts mean 10. Play or Step highlights exact binomial outcomes, not sampled documents. No loss, perplexity, context policy, or corpus correlation is modeled.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forEvaluation composition affects aggregates, so preserve measured domain counts beside losses.
Pause & reason
Check your understanding
Your turn
Try it yourself
Keep domain losses A=2 and B=4 but change the report to 100 valid A tokens and 900 B tokens. Calculate the new pooled loss. Under a separately fixed 50/50 reporting mixture, what loss would both reports have?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use valid-token weights for the observed report, then deliberately replace them with equal fixed reporting weights for the second question.
Compare with the solution
The new observed loss is (100×2+900×4)/1000=3.8 nats per token, compared with 2.2 in the original mixture. Under a fixed equal-domain mixture, both have 0.5×2+0.5×4=3. This distinguishes a composition change from a within-domain quality change. The equal-domain report is a different declared aggregation, so label it explicitly rather than replacing the measured token-weighted statistic without explanation.
Keep the idea
Take it with you
- Validation metrics need fixed tokenization, context, target, and split policies.
- Pool negative log-likelihood using valid counts before exponentiating.
- Domain values and mixture weights explain changes that one headline metric hides.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.