Introduction
Some tasks turn one sequence into another sequence of a different length: translating "I love deep learning" into French ("J'adore l'apprentissage profond"), summarizing an article into a few sentences, converting speech into text, or turning a question into an answer. The output length isn't known in advance, and the word order can be completely different.
The encoder–decoder (or sequence-to-sequence, seq2seq) architecture handles this with two networks:
- an encoder reads the whole input and summarizes it;
- a decoder writes the output one token at a time, using that summary and the tokens it has written so far.
Think of a human interpreter at a conference. They listen to the speaker's whole sentence first (encoder), form an understanding of its meaning, and then speak the translation word by word in the other language (decoder), each word depending on what they've already said.