liveBook · Manning

Transformer decoder

As explained in Deep Learning with R, Third Edition

A Transformer decoder is an architectural component that generates sequence representations or outputs using attention and feedforward processing.

A Transformer decoder generates target-sequence predictions by combining a target sequence with the context-aware output of a Transformer encoder. Attention replaces recurrent layers as the mechanism for passing information across the sequence, while positional encoding preserves word order. section 20.1.6 section 15.3.4

English-to-Spanish translation

Build an encoder with hidden size 256, feedforward dimension 2,048, and eight attention heads. Embed the English source sequence, pass it through the encoder, embed the Spanish target sequence, and pass both target embeddings and encoder output to the decoder. Apply dropout and a vocabulary-sized softmax to produce token predictions, then train with sparse categorical cross-entropy and accuracy.

A decoder is useful when:

  • The task maps one sequence to another, such as machine translation or question answering. section 20.1.6
  • The model must use encoder context while predicting the next target word. section 20.1.6
  • Attention should connect sequence elements without relying on recurrent computation. section 15.3.4

How Deep Learning with R, Third Edition covers it

How deep it goes
Explains encoder context, attention, positional encoding, embeddings, feedforward dimensions, masking, and softmax outputs through a working architecture.
Examples
Uses English-to-Spanish translation and identifies machine translation and question answering as representative applications.
What it assumes
Assumes integer source and target sequences, token embeddings, vocabulary prediction, and a TransformerEncoder supplying contextual output.
What you can do after
Apply via R/Keras by constructing encoder-decoder layers, wiring target and source sequences, and training vocabulary predictions.
How it connects
Connects TransformerDecoder with TransformerEncoder, attention, positional encoding, embeddings, feedforward blocks, and sequence-to-sequence learning.

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.