How Translation Went From Dictionary Lookup to Attention

3 min read

Machine translation is one of the oldest tasks in AI, and this Stanford lecture tells its history in three acts: dictionaries, statistics, and neural networks. The first act starts in 1954, with a famous demo. A $500,000 machine translated Russian to English in front of the press, and the people running it claimed it would replace most human translators within about five years, at one to two million words an hour. It was mostly a bilingual dictionary on magnetic tape, looking up words one by one. The hype was already there in 1954. So was the overpromising.

The second act is statistical machine translation, which ruled from the 1990s to about 2013. The idea is to learn a probability model from data. You want the best English sentence y for a French sentence x, which means finding the y that maximizes P(y|x). Using Bayes' rule, that splits into two parts: a translation model P(x|y), which knows how words and phrases map between languages, and a language model P(y), which knows how to write good English. The translation model is learned from parallel data, text that exists in both languages. The Rosetta Stone is the classic example. The language model just needs lots of English text.

To learn the translation model you need alignment, a map of which words correspond to which. Sometimes it is one-to-one. Sometimes it is many-to-one or one-to-many. A word that maps to several words is called fertile. The lecture's best example is the French verb entarter, to hit someone with a pie, which has no single-word equivalent in English at all. And a phrase like "don't have any money" can map to a French phrase, "sont demunis", with no clean way to break it into word-to-word pairs. That is many-to-many alignment.

Finding the best translation means searching through possible sentences and pruning the ones with low probability as you go. That search is called decoding. Statistical systems got extremely good, the best translation systems in the world, but they were enormously complex. Hundreds of details, many separately designed sub-components, heavy feature engineering, and separate resources for every language pair. Adding a language meant multiplying the work.

Then 2014 happened, and the third act is neural machine translation. Instead of many sub-components, one neural network does the whole job. The architecture is called sequence-to-sequence, or seq2seq: two RNNs. The encoder reads the source sentence and compresses it into a final hidden state. The decoder, a conditional language model, generates the target sentence one word at a time, feeding each word back in as it goes, stopping at the end token. At test time it generates. At training time it learns from the full sentence at once.

What I liked most is how general seq2seq turned out to be. Summarization is seq2seq: long text in, short text out. Dialogue is seq2seq. Parsing can be framed that way. Even code generation is translation, from English to Python. The lecture ends where the next one begins, with attention, the mechanism that fixes the biggest weakness of seq2seq: squeezing a whole sentence into a single vector. But the history matters on its own. Translation went from a dictionary on tape, to a statistical machine with hundreds of hand-built parts, to a single network that learns the whole job from data.

Try this

bash
pip install transformers
python -c "import transformers; print(transformers.__version__)"

Sources

Source: Stanford CS224N: NLP with Deep Learning | Winter 2019 | Lecture 8 - Translation, Seq2Seq, Attention - Stanford Online