liveBook · Manning

GPT model

As explained in Deep Learning with PyTorch, Second Edition

A decoder-only transformer architecture used for autoregressive text generation without a separate encoder stack.

A GPT model is a decoder-only transformer for generating coherent, contextually relevant text from an input sequence. GPT stands for Generative Pre-Trained Transformer; these models train on large text collections and generate text token by token without a separate encoder stack. section 9.6.1 section 9.12

A practical GPT-style decoder combines several familiar neural-network components:

  • Multiheaded attention projects queries, keys, and values through parallel heads, allowing different heads to capture different relationships in a sequence. section 9.6.1
  • Residual connections, also called skip connections, provide direct paths for gradients through deep networks. section 9.6.1
  • Layer normalization, a multilayer perceptron, token or character embeddings, positional embeddings, and a final projection produce vocabulary scores. section 9.6.1

A small character-level GPT-style model

A compact PyTorch implementation embeds input characters and positions, passes them through six transformer blocks, and projects the resulting representations to vocabulary scores. Training this model on names can produce outputs such as “journe,” “green,” “huxson,” and “robinna.”

How Deep Learning with PyTorch, Second Edition covers it

How deep it goes
Builds a small PyTorch decoder from attention blocks, embeddings, normalization, residual connections, and output projection.
Examples
Demonstrates a character-level names model that generates short invented names after training.
What it assumes
Assumes attention and multilayer-perceptron work, then develops the additional components needed for a full decoder block.
What you can do after
Build it from scratch in PyTorch and generate character-level samples with a compact transformer decoder.
How it connects
Connects transformer decoders with attention, residual connections, layer normalization, tokenization, and encoder-decoder transformers.

Also explained in

Compare how 18 books explain GPT model →

Related concepts

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