Encode and decode with byte-pair ranks
Encode UTF-8 bytes with ranked merges and reconstruct the text from token IDs.
What’s going wrong
Original LLM Architecture lab. Implement the missing behavior in solve(data) and keep the supplied JSON interface. Use Python’s standard library.
Input text is one Unicode string. Each merge [left,right,id] references byte IDs 0–255 or previously defined merged IDs, and the array order defines rank. Repeatedly choose the available adjacent pair with the lowest rank and replace all non-overlapping occurrences left to right. Return tokens and decoded. Treat the whole text as one pretokenized span.
Small, well-formed JSON inputs and standard-library Python arithmetic. Keep full precision during computation. The supplied output wrapper rounds results to six decimal places.
Expected behavior
Encode UTF-8 bytes with ranked merges and reconstruct the text from token IDs.
Reproduction
{"text":"abc","merges":[[98,99,256],[97,98,257]]}{"tokens":[97,256],"decoded":"abc"}{"text":"é😀","merges":[]}{"tokens":[195,169,240,159,152,128],"decoded":"é😀"}{"text":"aaa","merges":[[97,97,256]]}{"tokens":[256,97],"decoded":"aaa"}Before you begin
- Python functions, lists and dictionaries
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.