Byte-Pair Encoding Tokens Explained With a Worked Merge
Neural translation models of that time kept a vocabulary of about 30,000 to 50,000 words, but translation is an open-vocabulary problem. Sennrich, Haddow, and Birch encode rare words as sequences of subword units instead, and build the units with byte-pair encoding.
The algorithm is short. Split every word into characters and add an end-of-word marker. Count each adjacent pair of symbols across the word list, weighting every word by its frequency. Merge the most frequent pair into a new symbol, and repeat for a chosen number of merges.
Take the dictionary in the paper's Algorithm 1: low (5), lower (2), newest (6), widest (3). The pair e s occurs in newest and widest, 6 + 3 = 9 times, so it is merged first, then es t (9 times) and est with the end marker (9 times). Next come l o (7 times, from low and lower) and lo w (7). After ten merges, running the paper's code leaves low and newest as single symbols, lower as low, e, r, and the end marker, and widest as wi, d, and est with its end marker.
One catch: the paper's Figure 1 prints a different merge list, starting r·, lo, low, er·, and its caption names the dictionary low, lowest, newer, wider. The printed code and the printed figure do not describe the same dictionary.
On English to German and English to Russian (WMT 15) the subword models improved over a back-off dictionary baseline by up to 1.1 and 1.3 BLEU.
Sennrich, Haddow, and Birch, ACL 2016, §3.2 (Algorithm 1, Figure 1) and abstract