Losses in nats per token, and data mixtures measured in tokens, change when the tokenizer changes. Cartesia's From Tokens to Bytes posts therefore report bits per byte and match data mixtures by bytes. Implement the conversions.
bytes_per_token(docs)
docs is a list of (source, n_bytes, n_tokens) tuples, possibly several per source.(per_source, overall): per_source maps each source (in order of first appearance) to its total bytes divided by its total tokens, and overall is all bytes over all tokens. Use totals, never the mean of per-document ratios.token_mix_to_byte_mix(token_mix, bpt)
token_mix maps each source to its share of the tokens (any positive weights; normalize them), bpt maps it to bytes per token.byte_mix_to_token_mix(byte_mix, bpt)
mixture_bytes_per_token(byte_mix, bpt)
byte_mix.bits_per_byte(nats_per_token, bytes_per_token)