bugger.
All challenges/Pythonmediumllm-bpe-training-v1
THE INVESTIGATION

Train byte-pair merges

Train a deterministic byte-pair merge table on a weighted token corpus.

LLM ArchitectureTokenization

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

01 A weighted minority row wins
{"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]]}
02 Rows with no adjacent pair
{"corpus":[{"tokens":[1],"count":2},{"tokens":[],"count":1}],"steps":3,"next_id":100}
{"merges":[],"encoded":[[1],[]]}
03 Overlaps are counted but replacements are disjoint
{"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.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.