Highlights

Contents

Part VII
07

Measuring the predictor

Fitting seen text differs from improving on new text. Scoring conventions can also create misleading comparisons. Separate training and validation, then explain what perplexity and byte-normalized loss actually measure.

THE TRAINING CHAPTER: TEN PARTS, ONE COMPLETE MODEL1. features2. output3. examples + loss4. optimizer5. precision6. resume + loop7. evaluation8. experiments9. decoding10. whole pipelineforward computation → learn parameters → measure results → generate

#Section 21Training loss versus validation loss

Suppose Finch-24’s training loss keeps falling while its held-out loss bottoms out and then rises. The optimizer is succeeding at its assigned job: fitting the examples it sees. That does not mean the predictor is improving on new text. We need separate measurements of fitting and transfer.

Training loss measures next-token error on the training distribution under a declared measurement procedure. Validation loss measures that error on held-out examples used for choices such as the learning-rate schedule or checkpoint selection. Generalization is the ability to retain useful predictive behavior on examples outside the fitted sample. The earlier loss-curve introduction provides the basic picture; here the emphasis is on making those curves comparable.

An online training loss can include dropout, data augmentation, changing batches and parameters updated throughout the reporting interval. Validation normally uses fixed weights, evaluation mode and a stable held-out set. For a cleaner comparison, periodically score a fixed training subset with the same evaluation settings as validation. Otherwise some of the gap is measurement policy rather than memorization. With Finch-24’s no-dropout configuration, differences in data selection and timing still remain.

Reading the curve without inventing a diagnosis

Overfitting means further fitting to the training sample harms, or fails to improve, the chosen held-out objective. Underfitting means the model has not fitted the relevant predictive structure well enough. Insufficient capacity can cause underfitting, but so can a poor optimizer, too few updates, harmful regularization or broken labels. A high loss by itself does not identify which explanation is correct.

The illustrated validation curve bottoms out while training loss continues falling. The best held-out checkpoint can therefore precede the best-fitting training checkpoint. These curves are illustrative, not measured Finch results.

BETTER FIT TO TRAINING TEXT CAN COINCIDE WITH WORSE HELD-OUT FITNLL / token234504006001000trainingvalidationbest held-out pointillustrative update count; not measured results
Figure 3.38Illustrative curves show training loss continuing downward after validation loss reaches its minimum at update 600. Orange marks the held-out curve and the model-selection point; these are not measured training results.

A flat pair of curves can mean optimization has converged, capacity is limited, or the learning rate is too small. A noisy validation curve may come from a small evaluation set or changing random windows. A sudden jump can mean a learning-rate change, a data-mixture change, a corrupt checkpoint or nonfinite arithmetic. Read the logs and inspect the data before assigning a story to the line.

Aggregation and honest selection

Sum negative log-likelihood and valid targets over the evaluation set, then divide once. Averaging batch means equally gives the wrong result when their target counts differ.

L^val=∑bSb∑bnb.\widehat{\mathcal L}_{\mathrm{val}}=\frac{\sum_b S_b}{\sum_b n_b}.

Read this as total validation loss divided by total supervised tokens: SbS_b is the summed next-token NLL in batch bb, and nbn_b is its valid-target count. Accumulate these totals with sufficient numerical precision and evaluate the same token positions for every model. Padding, context-only overlap and ignored targets contribute neither NLL nor denominator.

THE DENOMINATOR BELONGS TO TOKENS, NOT BATCHESbatch Abatch B224444442 tokens × 2 = 46 tokens × 4 = 2428 nats / 8 tokens = 3.5each label gets the same vote
Figure 3.39Two illustrative evaluation batches contain different token counts. Token weighting gives 28 divided by 8, or 3.5; treating the batches equally gives 3.

Validation is for development decisions; the test split is for an evaluation after those decisions are fixed. Repeatedly optimizing architecture and data choices against validation can overfit that split too. Record what was selected, how often the split was inspected, and whether the reported metric came from validation or an untouched test set. A model's best checkpoint is defined relative to the chosen objective, not every possible user task.

#Section 22Perplexity

A target probability of one quarter costs −ln⁡(1/4)=ln⁡4-\ln(1/4)=\ln4 nats. Exponentiate that loss and you get 4. We have converted a logarithmic penalty into a reciprocal-probability scale. That is the starting point for understanding perplexity, abbreviated PPL.

For one target, the exponentiated NLL is its reciprocal probability. For an evaluation set, perplexity is the exponential of the mean token NLL, not the arithmetic mean of per-token reciprocals. It describes the geometric average penalty assigned to the observed continuations. Lower is better for the same data and evaluation contract.

PPL⁡=exp⁡ ⁣(−1n∑i=1nln⁡pi)=(∏i=1n1pi)1/n.\operatorname{PPL}=\exp\!\left(-\frac{1}{n}\sum_{i=1}^{n}\ln p_i\right) =\left(\prod_{i=1}^{n}\frac{1}{p_i}\right)^{1/n}.

Read this as the geometric mean of reciprocal correct-token probabilities: nn is the number of supervised targets and pip_i is the probability assigned to target ii under its declared context. The equality follows by exponentiating the average of logarithms. Here loss is in nats; if it were in bits, the corresponding exponential would use base 2.

A worked comparison

Perplexity exponentiates mean negative log-likelihood. It corresponds to a geometric average of inverse target probabilities, not an arithmetic average of per-token perplexities.

PERPLEXITY IS A GEOMETRIC AVERAGE OF RECIPROCAL PROBABILITIES0.520.2540.12580.1258(2 × 4 × 8 × 8)¹ᐟ⁴ = 4.756828target probabilities below; reciprocal penalties above
Figure 3.40Four illustrative token probabilities turn into reciprocal penalties. Dataset perplexity is their geometric mean, 4.756828, rather than their arithmetic mean, 5.5.

A model choosing uniformly among four candidates would also have PPL 4 on those targets. This gives a useful “effective branching” intuition, but a real model need not be uniform, and PPL is not a literal count of equally plausible next tokens. A loss improvement of 0.5 nats changes PPL by a factor of e0.5=1.648721e^{0.5}=1.648721. Ratios are often easier to interpret than subtracting PPL values.

Tokenizer and context dependence

Changing tokenizers changes the prediction events and the denominator. A tokenizer can make the same string into fewer, harder-to-predict tokens or more, easier-to-predict tokens. Perplexity is therefore unsuitable for a direct cross-tokenizer ranking unless the tokenization is held fixed. The earlier vocabulary discussion introduces this problem; Section 23 works through a denominator that is shared by the raw text.

Context policy changes the conditionals too. Resetting at every disjoint chunk deprives boundary tokens of previous context. A sliding or strided window can preserve more context, but overlapping context tokens must not be counted again as fresh targets. The Transformers evaluation guide documents this fixed-context issue. Choose a policy, score each target once, and disclose stride, maximum context, boundary handling and any excluded initial targets.

OVERLAP IS CONTEXT; ONLY NEW TARGETS ENTER THE METRICtarget index123456789101112window 1✓✓✓✓✓✓✓✓window 2····✓✓✓✓four reused context targetsfour newly scored targets
Figure 3.41Illustrative overlapping evaluation windows use earlier tokens as context while scoring only newly introduced targets. Orange means “count this target once,” not “hide this token from attention.”

Perplexity measures likelihood on the chosen corpus, not factual accuracy, helpfulness, reasoning reliability or calibration on every task. Label smoothing, class weighting and auxiliary objectives also mean a reported “training loss” may not be plain token NLL; exponentiating that mixed objective does not produce ordinary perplexity. Compute the metric from the actual unweighted next-token log probabilities. Evaluate the model distribution, before generation temperature or truncation.

#Section 23Bits per byte

Two tokenizers encode the same eight bytes, but one uses four tokens and the other uses eight. Suppose both assign their chosen encodings the same total NLL, 8ln⁡2=5.5451778\ln2=5.545177 nats. The first gets PPL 4 and the second gets PPL 2. There is no likelihood improvement in this example. The unit of averaging changed.

Bits per byte, or BPB, divides total negative log probability in bits by the number of evaluated raw bytes. A bit is the base-2 information cost of halving probability; a nat is the corresponding natural-log unit. To convert nats to bits, divide by ln⁡2\ln2. Byte normalization supplies a denominator tied to text rather than the tokenizer's segmentation.

BPB⁡=−∑i=1nln⁡piMln⁡2=nLMln⁡2.\operatorname{BPB}=\frac{-\sum_{i=1}^{n}\ln p_i}{M\ln2} =\frac{n\mathcal L}{M\ln2}.

Read this as total coding cost in bits divided by evaluated bytes: MM is the byte count of the same scored text span, nn is its token count, and L\mathcal L is its mean token NLL in nats. The formula does not average per-token BPBs. It uses one text-level numerator and denominator.

The same sequence probability can produce different perplexities under different tokenizations. Dividing its information cost by the same raw bytes gives a common denominator, as the figure shows.

A COMMON RAW-BYTE DENOMINATOR SURVIVES A TOKENIZER CHANGEraw bytesb1b2b3b4b5b6b7b8tokenizer Atokenizer Btoken 1token 2token 3token 412345678PPL 4 versus PPL 2BPB 1 for bothsame eight bits of total coding cost
Figure 3.42Illustrative tokenizers segment the same eight raw bytes differently. Equal total NLL gives equal BPB, even though token-normalized perplexities differ.

Bytes mean bytes

Use an explicit encoding such as UTF-8. The string café has four Unicode code points and five UTF-8 bytes in its composed form. A decomposed accent can encode differently; normalization decisions are part of the data contract. len(text) in Python counts code points, while len(text.encode("utf-8")) counts bytes. Count the actual canonical evaluation stream.

Special tokens have no ordinary text-byte contribution. Decide consistently whether document boundaries, BOS and EOS are scored and how their costs belong in the text-level numerator. Excluding a prefix from loss while counting its bytes in the denominator artificially improves BPB. Context-only bytes are conditioning information, not fresh evaluated bytes. Store scored spans or offsets so numerator and denominator refer to the same material.

What BPB fixes and what it does not

BPB removes the arbitrary number-of-tokens denominator, making a cross-tokenizer comparison more meaningful on the same losslessly represented byte stream. It does not make preprocessing, context length or dataset choice irrelevant. Different tokenizers also expose different numbers of raw bytes within a fixed token context; disclose that difference or control the raw-context policy where the experiment requires it.

A token model assigns probability to token sequences. If multiple token sequences decode to the same byte string, the likelihood of one canonical encoding is not necessarily the model’s marginal probability of that string, which would sum over all matching encodings. Standard BPB reporting uses a declared canonical encoding and its sequence likelihood. It is a useful reproducible comparison, not a proof that every tokenizer induces the same byte-level probability model.

Property Perplexity Bits per byte
Numerator Next-token NLL Same NLL converted to bits
Denominator Valid predicted tokens Corresponding raw bytes
Output Exponentiated mean Mean bits per byte
Shared tokenizer needed Yes for direct ranking Not for the denominator
Shared data policy needed Yes Yes
Measures task success directly No No