Search

Search papers and lessons

Neural Machine Translation of Rare Words with Subword Units

Rico Sennrich, Barry Haddow, Alexandra Birch · 2015

Sennrich, Haddow and Birch adapt byte pair encoding to split rare words into subword pieces, so neural translation works on an open vocabulary and beats a dictionary back-off by up to 1.3 BLEU.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Linear algebra
  • Neural network basics
  • Architectures
  • Probability
  • ReadReady to readNot yet

TL;DR

Neural translation models have a fixed vocabulary, so any word outside it is lost or replaced by a placeholder. This paper keeps the vocabulary small by splitting rare words into pieces, using a compression method called byte pair encoding that repeatedly joins the most frequent adjacent pair of symbols. The model then translates over these pieces, so it can handle words it has never seen. On the WMT 2015 English to German and English to Russian tasks, subword models beat a back-off dictionary baseline, and the best BPE system gains 1.3 BLEU over that baseline on English to Russian.

Builds on: Subword Tokenization, Encoder-Decoder Architecture, Attention Mechanism · Leads to: sequence-to-sequence translation, attention-based translation

Why it mattered

Subword vocabularies built this way became common in later translation systems and language models. The method is simple: a list of merge rules learned from text, applied to any new word. Systems can handle names, compounds or inflected forms without a back-off dictionary. The paper reports its largest gains on rare and unseen words, which a word-level model handles poorly.

The problem

A word-level neural translator keeps a list of its most frequent words, typically 30,000 to 50,000, and maps every other word to a single unknown symbol. The paper states this limit directly: the vocabulary of neural models is typically limited to 30,000 to 50,000 words, but translation is an open-vocabulary problem. Names, compounds such as German nouns built from several words, and rare inflections fall outside the list.

The usual fix is a back-off dictionary. When the model emits an unknown symbol, the system looks up the source word in a dictionary and copies or translates it. The authors argue that this makes assumptions that often fail. There is not always a one-to-one match between source and target words, because of differences in morphology. Copying a name works for some language pairs and not for others, for example when the alphabets differ.

The question is therefore: can a neural translator work on an open vocabulary directly, with a fixed-size vocabulary of pieces, and do better than the back-off baseline?

How it works

The method has three parts: learn the subword vocabulary from text, split any new text with it, and train and run a translator on the split text.

  1. Start with characters. Take a training vocabulary of words and their counts. Represent each word as a sequence of characters, and add a special end-of-word symbol so that the original words can be restored after translation. In the notes below the end symbol is written as an underscore.
  2. Count adjacent pairs. Count every pair of neighbouring symbols across all words, weighted by how often each word occurs.
  3. Merge the most frequent pair. Replace every occurrence of that pair with one new symbol. The new symbol is a longer piece, for example an "er" from an "e" followed by an "r".
  4. Repeat. Recount the pairs with the merged symbols and merge again. Stop after a chosen number of merges. That number is the only hyperparameter of the method.
  5. Segment new text. For any word, including one never seen in training, split it into characters and apply the learned merges in the order they were learned. Each word becomes a sequence of known pieces.
  6. Train and translate. The translator reads and writes the pieces. After translation, joining the pieces and removing the end markers restores the words.

Here is a toy trace with four words and their counts: low (5), lowest (2), newer (6), wider (3). This toy is our own; the paper's Figure 1 uses similar words with different counts.

Step 1 has pair counts of (e,r)=9(e, r) = 9 and (r,_)=9(r, \_) = 9 from the words newer and wider. They tie, so take (e,r)(e, r) and merge it into "er". Now newer is n e w er _n\,e\,w\,er\,\_ and wider is w i d er _w\,i\,d\,er\,\_.

Step 2 counts the pairs again. The pair (er,_)(er, \_) now occurs in newer (6) and wider (3), so its count is 9. It is the most frequent pair, so merge it into "er_".

The merges learned so far are e re\,r and then er _er\,\_. Now segment the unseen word lower. Its characters are l o w e r _l\,o\,w\,e\,r\,\_. The first merge gives l o w er _l\,o\,w\,er\,\_, and the second gives l o w er_l\,o\,w\,er\_. The word splits into l∣o∣w∣er_l \mid o \mid w \mid er\_, and every piece is known. The unseen word newest contains none of the learned pairs, so it stays as characters. That is the fallback: a rare word is always representable, just in smaller pieces.

flowchart LR
  A["Training words with counts"] --> B["Start from characters plus end marker"]
  B --> C["Count adjacent pairs"]
  C --> D["Merge most frequent pair"]
  D -->|"repeat for N merges"| C
  D --> E["Apply the merges to any text"]
  E --> F["Train and run the NMT model on pieces"]

The paper also explains why this helps the translator, which learns vector representations of the pieces just as it would of words. Frequent words or common character sequences become single symbols, so they still cost one step. Rare words become several pieces, and each piece is a symbol the model has seen many times. The model therefore learns to translate the parts of a rare word, such as a name or a compound, even if the whole word appears only once.

The math

Let V0V_0 be the set of characters plus the end symbol. Let D\mathcal{D} be the training vocabulary, a list of words ww with counts f(w)f(w). For a current segmentation of each word into symbols, the count of an adjacent pair (a,b)(a, b) is

c(a,b)=∑w∈Df(w)⋅nab(w)c(a, b) = \sum_{w \in \mathcal{D}} f(w) \cdot n_{ab}(w)

where nab(w)n_{ab}(w) is the number of places in word ww where symbol aa is directly followed by symbol bb.

Step 2 and 3 in symbols: choose and merge

At each merge, choose the most frequent pair

(a⋆,b⋆)=arg⁡max⁡(a,b)c(a,b)(a^{\star}, b^{\star}) = \arg\max_{(a,b)} c(a, b)

and add the new symbol a⋆b⋆a^{\star}b^{\star} to the vocabulary. In the toy trace, c(e,r)=c(r,_)=9c(e, r) = c(r, \_) = 9, so either pair may be chosen, and the step takes (e,r)(e, r).

Step 4 in symbols: the vocabulary size

If the initial vocabulary has ∣V0∣|V_0| symbols and the method performs MM merges, the final symbol vocabulary has

∣V∣=∣V0∣+M|V| = |V_0| + M

symbols. The paper states this relation directly: the final symbol vocabulary size is the initial vocabulary plus the number of merge operations, and the number of merges is the only hyperparameter. A larger MM gives longer pieces and a shorter text, and a smaller MM gives shorter pieces and a longer text.

Step 5 in symbols: segmentation

Given the ordered merge list m1,…,mMm_1, \dots, m_M, a new word is segmented by starting from its characters and applying m1m_1, then m2m_2, and so on, each time to every place where the pair occurs. The output has no unknown symbols, provided every character of the word is in the character vocabulary. In the toy trace, applying e re\,r and then er _er\,\_ to lower gives l,o,w,er_l, o, w, er\_.

Step 6 in symbols: the translator

The translator is an encoder-decoder with attention, operating on the sequence of pieces. The paper says its approach is not specific to this architecture, and it trains the model with stochastic gradient descent on the piece sequences. At test time it searches for output with beam search.

Results

The paper evaluates on the WMT 2015 shared translation task. English to German uses 4.2 million sentence pairs, about 100 million tokens. English to Russian uses 2.6 million sentence pairs, about 50 million tokens. Scores are BLEU, the standard translation metric (see BLEU Score), and chrF3, a character n-gram score. Test sets are newstest2015. The paper also reports unigram F1 separately for rare words (not among the top 50,000 training words) and for out-of-vocabulary words (not in the training text).

English to German, Table 2 of the paper (single model, then ensemble of 8):

  • Back-off dictionary baseline WDict: BLEU 22.0 single, 24.2 ensemble.
  • BPE with 60,000 symbols on each side (BPE-60k): BLEU 21.5 single, 24.5 ensemble.
  • Joint BPE with 90,000 symbols (BPE-J90k): BLEU 22.8 single, 24.7 ensemble.
  • Character bigram model with a 50,000-word shortlist (C2-50k): BLEU 22.8 single, 25.3 ensemble, the best BLEU in the table.
  • Unigram F1 on rare words, ensemble: 36.8 for WDict, 41.8 for BPE-J90k.
  • Unigram F1 on out-of-vocabulary words, ensemble: 36.8 for WDict, 33.6 for BPE-J90k.

English to Russian, Table 3 (single, then ensemble of 8): WDict BLEU 19.1 single and 22.8 ensemble. BPE-J90k reaches 20.4 single and 24.1 ensemble. Unigram F1 on rare words rises from 26.5 for WDict to 29.7 for BPE-J90k.

The abstract summarises the gains as 1.1 BLEU on English to German and 1.3 BLEU on English to Russian over the back-off baseline. The English to German gain of 1.1 corresponds to the character-bigram system, C2-50k, at ensemble level (25.3 against 24.2). The English to Russian gain of 1.3 corresponds to BPE-J90k.

Limits the paper states itself. The rare and unseen words that the subword models help most make up only 9 to 11 percent of the test sets, so BLEU underestimates their effect on meaning. The gains are not uniform: for English to German out-of-vocabulary words, the copying baseline is stronger, because many such words are names that are copied across. The paper notes differences of up to 1 BLEU between models on its development set, so gaps of a few tenths of a BLEU point should be read with care.

Reading guide

The paper's sections, in order, and what each one needs. Unigram F1 is the harmonic mean of precision and recall over single words.

  • Introduction (section 1). Needs Encoder-Decoder Architecture and the idea of a fixed vocabulary. It states the open-vocabulary problem and the claims.
  • Related work and the back-off approach (section 3.1). Needs the idea of a fixed vocabulary from the introduction. It describes the dictionary back-off that the paper's baseline uses.
  • Byte pair encoding (section 3.2). Needs Subword Tokenization and the merge idea in this lesson. It gives the algorithm, which is the paper's core.
  • Experimental setup (section 4). Needs BLEU Score and Attention Mechanism. The model is an attention encoder-decoder.
  • Results (section 4.2). Needs the metrics above and the tables. Read the rare-word F1 and the out-of-vocabulary rows together with the BLEU rows.
  • Analysis and conclusion (sections 5 and 6). Needs the rare-word F1 measure and the limits listed under Results.

Check yourself

QuestionRecall: what problem does the paper's back-off dictionary baseline try to solve, and what limit does the paper give for neural vocabularies?Show answer
Words outside the model's vocabulary are unknown to the model. The baseline looks each unknown source word up in a dictionary and copies or translates it. The paper says neural models are typically limited to 30,000 to 50,000 words, while translation is an open-vocabulary problem.
QuestionComputation: the initial vocabulary has 30 symbols and the method performs 60 merges. What is the final symbol vocabulary size, and what is the vocabulary size if the method performs 90 merges?Show answer
The final size is 30+60=9030 + 60 = 90 symbols. With 90 merges it is 30+90=12030 + 90 = 120 symbols. The paper's rule is that the vocabulary size equals the initial size plus the number of merges.
QuestionWhy: the paper says the subword models help rare words most, yet the BLEU gains are small. Why might BLEU understate the effect on meaning?Show answer
Rare and unseen words make up only 9 to 11 percent of the test sets, so a change to them moves a score averaged over all words only a little. The paper also attributes part of the gap between metrics to BLEU's precision bias. It argues that rare words carry central information, so their effect on meaning may be larger than BLEU shows.
QuestionApplied: a team builds a translator for a language with many long compound words. Its word-level model maps unknown words to one placeholder. Should it use BPE, and what must it check after training?Show answer
Yes, subword pieces let the model represent a long compound as several known parts instead of a placeholder. The team should check the rare-word and out-of-vocabulary scores, not only BLEU, because the paper shows that gains concentrate there. It should also check whether copying names still works, since the paper found the copying baseline stronger for some out-of-vocabulary words.

Sources

Read the full paper

Rico Sennrich, Barry Haddow, Alexandra Birch, 2015. arXiv:1508.07909