An encoder-decoder architecture maps one sequence to another. The encoder converts a fixed source sequence into a representation; the decoder uses that representation and previous target tokens to predict the next token. section 15.2 section 15.6
Figure 15.1 Sequence-to-sequence learning: the source sequence is processed by the encoder and is then sent to the decoder. The decoder looks at the target sequence so far and predicts the target sequence offset by one step in the future. During inference, we generate one target token at a time and feed it back into the decoder.
Trace the source sequence through the encoder and into the decoder, which predicts the target sequence one position ahead. section 15.2
Use two operating modes:
- During training, provide the target sequence so the decoder learns next-token prediction conditioned on the encoded source and previous target tokens. section 15.2
- During inference, seed the decoder with a start token, feed each prediction back as the next input, and stop at an end token. section 15.2
- For an RNN design, encode the entire source before decoding; use the encoder representation as the decoder’s initial state. section 15.2.2
R-based GRU translation model
A practical Keras construction embeds the English source, processes it with a bidirectional GRU, and uses the resulting representation to initialize a Spanish decoder GRU. A dense softmax layer predicts the Spanish vocabulary at every step. Compile with Adam and sparse categorical cross-entropy, then generate translations token by token. Example outputs include “You know that.” → “[start] tú lo sabes [end]” and “I will tell you tomorrow.” → “[start] te lo voy mañana a decir [end]”. section 15.2.2









