Cross-Entropy Loss › Bits Per Character

Michael BrenndoerferFebruary 21, 20263 min read
Language AI HandbookAll chapters
Part 53 of 67Evaluation Fundamentals
Chapter 406Cross-Entropy Loss › Bits Per Character
Reading section 5 of 15 · Bits Per Character · 3 minSection 5 of 15 · 3 min

Book contents

Section 5 of 15 · 3 min read

Cross-Entropy Loss › Bits Per CharacterOne section · Sections in this chapter5 / 15 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

While cross-entropy measures bits per token, bits per character (BPC) provides a tokenization-agnostic metric for comparing model efficiency. Since different tokenizers produce different sequence lengths for the same text, BPC normalizes by the number of characters in the original text. This normalization is needed for fair comparison because a model using a more aggressive tokenizer (with larger tokens) will naturally achieve lower per-token perplexity than an equivalent model using character-level tokenization, even if both models capture the same underlying linguistic patterns.

Calculating BPC

Given a sequence with CC characters and cross-entropy loss HH (in bits), bits per character is:

BPC=H×TC\text{BPC} = \frac{H \times T}{C}

where:

  • BPC\text{BPC}: bits per character, measuring compression efficiency independent of tokenization
  • HH: the cross-entropy loss in bits (not nats)
  • TT: the number of tokens in the sequence
  • CC: the number of characters in the original text

For character-level language models where T=CT = C, BPC equals the cross-entropy. For subword tokenizers where T<CT < C (multiple characters per token), we must account for the compression ratio. The multiplication by TT converts the per-token loss to total bits for the sequence, while division by CC spreads those bits across the original characters.

BPC and Compression

BPC represents a basic limit on lossless compression. If a language model achieves 1.0 BPC on English text, it means no compression algorithm can compress English below 1 bit per character on average, assuming the model perfectly captures the true distribution of the language. This connects language modeling to data compression theory, where better language models yield better compression algorithms. In fact, arithmetic coding with a language model as the probability estimator is theoretically optimal: as the model improves, the compressed file size approaches the entropy of the text.

Current state-of-the-art language models achieve approximately 0.7-0.9 BPC on standard English text corpora, approaching but not reaching the estimated entropy of English (typically estimated between 0.6-1.0 BPC depending on the domain and estimation method). This gap suggests there remains room for improvement in language modeling, though diminishing returns may make further advances increasingly difficult.

Character-Level vs Subword Evaluation

When comparing models using different tokenization strategies, BPC provides fairer comparison than per-token metrics:

  • Character-level models: Directly report BPC as the loss, since each token corresponds to one character.
  • Subword models: Must divide total bits by character count to enable fair comparison with character-level models.
  • Byte-level models: Similar to character-level but operating on UTF-8 bytes, where one character may consist of multiple bytes.

This normalization is important when evaluating Byte Pair Encoding or SentencePiece tokenizers against character-level baselines, as the same model architecture can appear to have wildly different per-token perplexities solely due to tokenization differences. Without BPC normalization, you might conclude that a subword model is dramatically better than a character model, when in fact the improvement comes primarily from the tokenizer grouping characters into larger units rather than from better linguistic understanding.