A byte-level language model runs a small network on every byte and a large one only on some of them. The H-Net paper (Hwang, Wang and Gu, 2025) measures its learned chunking against two fixed rules, and you will implement both. Each rule returns a boolean tensor b with one entry per byte, where b[i] is True when position i begins a new chunk.
pool_boundaries(data, k)
data is a Python bytes object, k >= 1 an integer.torch.bool tensor of shape (len(data),) with True at every k-th position, starting at position 0.is_spacelike(byte)
byte is an integer in [0, 255]. Return a Python bool.A-Z, a-z), an ASCII digit (0-9) or a UTF-8 continuation byte (0x80 to 0xBF).0xC0 to 0xFF) are all space-like.spacelike_boundaries(data)
torch.bool tensor of shape (len(data),).i >= 1, position i is a boundary when data[i-1] is space-like and data[i-2] is not space-like. If i == 1 there is no data[i-2], so only the first condition applies.split_chunks(data, b)
bytes objects obtained by cutting data at each True in b. Joining the list must give data back.An empty data returns an empty tensor from both boundary functions and [] from split_chunks.