Byte-pair Merge Step
A BPE training step counts adjacent token pairs, chooses the most frequent, then merges non-overlapping occurrences left to right. This is a token-string teaching model, not a production tokenizer.
tokens = ["a", "a", "a"]
print(list(zip(tokens, tokens[1:])))
print(["aa", "a"])From arithmetic to an experiment
A BPE training step counts adjacent token pairs, chooses the most frequent, then merges non-overlapping occurrences left to right. This is a token-string teaching model, not a production tokenizer. The trace reads the local variables of your function as it executes. Change one input or parameter, predict the result, then run the checks again. A small deterministic example makes arithmetic mistakes easier to locate than a long training run. State the shape and meaning of the returned value before coding. Keep preprocessing, evaluation and model updates in their proper order, and examine the boundary case in each check. The companion lab lets you replay intermediate values while the same algorithm runs.
Your task
merge_pair(tokens) returns (new_tokens, selected_pair) after one BPE merge. Ties choose the lexicographically smallest pair; joining concatenates token strings. With fewer than two tokens, return (a copy, None).
The explanation opens here once every check passes.