On the path Attention paperHow the training sentences were cut into a shared vocabulary of about 37,000 tokens.
Words are too many, letters too small
A vocabulary of whole words is never complete: names, numbers, rare and new words keep appearing, and each unknown word would become one “unknown” token. A vocabulary of characters is complete but makes sequences long and leaves the network to learn every word from its letters. Byte-pair encoding (BPE) sits between the two: frequent words stay whole, rare ones are written in pieces, and any text can be written at all.
Learning the merges
Start from a corpus with every word cut into characters. Count every pair of neighbouring pieces, each word counted as often as it occurs. Merge the most frequent pair into a new piece everywhere, add it to the vocabulary, and count again. Repeat until the vocabulary has the size wanted; the list of merges, in order, is the result.
A small example: the words low (5 times), lower (2), newest (6) and widest (3). The pair e s occurs 6 + 3 = 9 times, more than any other (ties go to the pair seen first), so it merges into es; then es t (9), l o (7), lo w (7), n e (6), ne w (6). After six merges low is one piece, newest is new + est, and widest is w i d + est.
To cut a new text, apply the merges in the order they were learned. A word never seen, such as lowest, is still written, as low + est. The method comes from data compression; Sennrich, Haddow and Birch brought it to translation in 2016. Variants work on bytes instead of characters, so that no character is ever unknown.
On the path Attention paper
In the paper. The 4.5 million English–German sentence pairs were encoded with byte-pair encoding into one vocabulary of about 37,000 tokens shared by both languages; the 36 million English–French pairs used 32,000 word-pieces, a close relative (section 5.1). The shared vocabulary is what let the paper use one matrix for both embeddings and the output layer (tokens and embeddings). Batches were made of sentence pairs of similar length, about 25,000 source and 25,000 target tokens each.
Test yourself
In the example, why is e s merged first?
It occurs 9 times (6 in newest, 3 in widest), as often as s t and more than any other pair; ties go to the pair seen first.
How is a word the merges never saw written?
In smaller pieces: apply the learned merges in order, and whatever cannot be merged stays as single characters (or bytes). lowest becomes low + est.
What did the shared English–German vocabulary allow the paper to do?
Use one embedding matrix for the encoder, the decoder and the output layer.
Where it leads
Kept in this browser only, never sent.
Paths through it
- Attention paperstep 12 of 17Follow this path