Part II of Cartesia's "From Tokens to Bytes" builds a BLT-like baseline: a separately trained byte-level proxy model predicts each next byte, and a new chunk starts wherever the entropy of that prediction exceeds a fixed threshold. The threshold is tuned on validation data to hit a target compression (bytes per chunk). Implement the pieces.
Row of probs is the proxy's distribution over byte given bytes . Boundary flags mark chunk starts.
next_byte_entropy(probs)
probs is an array-like whose rows sum to 1. Return a list of Python floats, the entropy of each row in bits, , with .entropy_boundaries(entropies, threshold)
threshold (strictly; an entropy equal to the threshold is not a boundary).bytes_per_chunk(boundaries)
fit_threshold(entropies, target, iters=60)
ValueError if there are fewer than 2 entropies or target is outside .iters halvings on the bracket lo = min(H[1:]) - 1, hi = max(H[1:]), keeping the compression at hi at least target throughout, and return hi.target.hi = max(H[1:]) only byte 0 is a boundary, so the compression is and the invariant "compression at hi is at least target" holds from the start.