Train byte-pair merges
Train a deterministic byte-pair merge table on a weighted token corpus.
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.
corpus contains {tokens, count} rows, where token IDs are nonnegative, counts are positive and next_id exceeds all initial IDs. Each round count adjacent pairs within rows, including overlapping occurrences and weighting by count. Choose most frequent, breaking ties lexicographically by pair. Replace its non-overlapping occurrences left to right with the next ID. Stop after steps merges or when no pair remains. Return merges as [left, right, id] rows and encoded as final token rows.
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
Train a deterministic byte-pair merge table on a weighted token corpus.
Reproduction
{"corpus":[{"tokens":[1,2,3],"count":1},{"tokens":[9,8],"count":5}],"steps":1,"next_id":100}{"merges":[[9,8,100]],"encoded":[[1,2,3],[100]]}{"corpus":[{"tokens":[1],"count":2},{"tokens":[],"count":1}],"steps":3,"next_id":100}{"merges":[],"encoded":[[1],[]]}{"corpus":[{"tokens":[5,5,5],"count":1}],"steps":1,"next_id":100}{"merges":[[5,5,100]],"encoded":[[100,5]]}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.