liveBook · Manning

Generation

As explained in Transformers in Action

Natural language generation is the computational production of human-readable language from learned representations or structured information.

Natural language generation produces human-readable sequences by predicting output tokens from context. Earlier sequence-to-sequence systems encoded an input sentence into a fixed-length representation, then generated the target one word at a time; decoder-only transformers instead reuse their own preceding outputs. section 2.1 section 3.2

Decoder-only generation depends on three linked mechanisms:

  • Causal attention prevents a prediction from attending to future tokens, so each output uses only the preceding context. section 3.2
  • Autoregressive decoding predicts one token, feeds it back into the input stream, and repeats the process. section 3.2
  • Next-token prediction trains the model to continue sequences within its context window. section 3.2
  • Decoding and sampling choices shape output quality: greedy and beam search are deterministic, while top-k, top-p, and temperature sampling are probabilistic. section 4.0

From text to generated tokens

An input encoder can convert raw Unicode text into byte-pair-encoded subwords and vocabulary IDs. A decoder-only model processes those IDs through masked self-attention and transformer blocks, predicts the next token, and appends it before making the following prediction.

How Transformers in Action covers it

How deep it goes
Descends from sequence-level intuition to causal masking, tokenization, transformer blocks, and decoding strategies.
Examples
Uses translation, chatbot responses, story generation, GPT-2-style BPE encoding, and masked-attention code.
What it assumes
Assumes familiarity with sequence modeling while contrasting recurrent encoder-decoder systems with transformer architectures.
What you can do after
Evaluate generation pipelines by relating architecture, masking, tokenization, decoding, sampling, and prompting choices to output quality.
How it connects
Connects sequence-to-sequence learning, transformers, causal attention, tokenization, sampling, and prompting.

Also explained in

Compare how 20 books explain generation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Transformers in Action. The section links point to the parts of the book it draws on.