PythiloLesson 6 of 8 · progress kept in this browser

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"])
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).