Part II of Cartesia's From Tokens to Bytes posts trains two tokenizers on the same corpus at the same vocabulary size: BPE, which runs inside pretokens, and BPE-NP, which runs on the raw text with no pretokenization. Build that comparison and measure compression, how often tokens cross a word boundary, and the token lengths.
The trainer and encoder (the same as in the byte-level BPE trainer problem)
(left, right) tuple of bytes, and replace it left to right without overlap. Stop after vocab_size - 256 merges or when no pair is left.crossing_share(tokens, pieces)
tokens and pieces are lists of bytes that join to the same byte string; raise ValueError if they do not.0.0 when there are no tokens).compare_bpe(text, vocab_size, split)
text is a non-empty str; split(text) returns its pretokens as strings. Raise ValueError if the pieces do not join back to text, if text is empty, or if vocab_size < 256.text and the pieces as UTF-8. Train BPE on the list of pieces and BPE-NP on [text] (one chunk), both up to vocab_size.{"bpe": stats, "bpe_np": stats}, where each stats dict has:
"tokens": the list of bytes tokens;"bytes_per_token": UTF-8 bytes of the text divided by the number of tokens;"crossing_share": crossing_share(tokens, pieces) against the pieces from split;"length_hist": a dict from token length in bytes to the number of tokens with that length, keys in increasing order.