No, nats-per-byte is not tokenizer agnostic
I’ve noticed people assume you can normalize out the effect of using a different tokenizer for some model by reporting nat/bits-per-byte as the loss.
I believe this is incorrect. To show this I’ll use a super simple corpus, and a super simple model (unigram), while trying two different token sets. If we could normalize out the choice of tokenizer, the
Take a Corpus: "a cat sat. a bat bit." (\(N_{\text{bytes}} = N_{\text{chars}} = 21\))
And remember:
\[H(V) = -\sum_{x \in V} p(x) \ln p(x) \qquad \text{and} \qquad \text{Nats/byte} = H(V) \cdot \frac{N_{\text{tokens}}}{N_{\text{bytes}}}\]First let’s just use characters, so Vocabulary A (8 Characters: \(\lvert V_A \rvert = 8\), \(N_{\text{tokens}} = 21\))
- \(p(\text{" "}) = p(\text{"a"}) = \frac{5}{21}\)
- \(p(\text{"t"}) = \frac{4}{21}\)
- \(p(\text{"."}) = p(\text{"b"}) = \frac{2}{21}\)
- \(p(\text{"c"}) = p(\text{"s"}) = p(\text{"i"}) = \frac{1}{21}\)
This leads to
\[H(V_A) = 1.882 \text{ nats/token}\] \[\text{Nats/byte}_A = 1.882 \cdot \frac{21}{21} = \mathbf{1.882 \text{ nats/byte}}\]Now let’s use a different token set, which includes “at”. So we have Vocabulary B (Adds "at": \(\lvert V_B \rvert = 9\), \(N_{\text{tokens}} = 18\))
- \(p(\text{" "}) = \frac{5}{18}\)
- \(p(\text{"at"}) = \frac{3}{18}\)
- \(p(\text{"a"}) = p(\text{"."}) = p(\text{"b"}) = \frac{2}{18}\)
- \(p(\text{"c"}) = p(\text{"s"}) = p(\text{"i"}) = p(\text{"t"}) = \frac{1}{18}\)
So despite using the exact same model and normalizing for byte counts, we get a different loss. Therefore bits/nats per byte is not tokenizer agnostic.
You may object at the idea of using a unigram model which has the same distribution for any position. But using a bigram model leads to the same result: Adding at lowers the loss from 0.709 to 0.498 nats per byte on this corpus.