liveBook · Manning

Encoder-decoder architecture

As explained in Deep Learning with R, Third Edition

A sequence-to-sequence model predicts a target sequence from a separate source sequence, typically conditioning each target token on prior target tokens.

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.
figure

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

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains encoder representations, decoder conditioning, training, inference, and an RNN implementation, while stopping short of detailed derivations.
Examples
Demonstrates English-to-Spanish translation with GRU layers, start and end tokens, generated outputs, and an R/Keras training setup.
What it assumes
Builds on language modeling and next-token prediction while introducing source-sequence encoding and decoder initialization.
What you can do after
Build it from scratch in R/Keras and generate target sequences autoregressively from source inputs.
How it connects
Connects sequence-to-sequence modeling with language modeling, RNNs, GRUs, bidirectional processing, attention, and Transformers.

Also explained in

Compare how 10 books explain encoder-decoder architecture →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.