CSCE 471 Natural Language Processing · Spring 2027

Pre-Trained Decoder Models

Kuan-Hao Huang · Course Website

Note: This page was created with the help of AI as a supplementary reading. It may contain errors or simplifications. The lecture slides are the primary reference for this course; please refer to them first.

The third family of pre-trained Transformers keeps only the decoder: a stack of Transformer layers with causal (left-to-right) self-attention, trained to predict the next token. This is just a language model, the oldest idea in NLP, made very large. Starting with OpenAI's GPT series, decoder-only models grew into today's large language models.

After reading this, you should be able to contrast masked and causal language modeling · explain why every position of a sequence gives a training signal · summarize GPT-1, GPT-2, and GPT-3 · describe how GPT-1 was fine-tuned and how GPT-2/3 are used through prompting · explain zero-shot and few-shot in-context learning · compare encoder, encoder–decoder, and decoder-only models

1Causal language modeling

A decoder-only model is trained on plain text with the language modeling objective: maximize the probability of each token given all the tokens before it,

$$\mathcal{L}=-\sum_{t=1}^{T}\log P(x_t\mid x_1,\dots,x_{t-1}).$$

To make this work inside a Transformer, self-attention uses a causal mask: position $t$ may attend to positions $1,\dots,t$ but never to the future. Without the mask, the model could simply look at the word it is supposed to predict.

Input and prediction targets
Attention: who can see whom
Figure 1 (interactive). The same sentence under the two objectives. Green tokens are prediction targets (positions that contribute to the loss). In the attention grid, row = the position doing the attending, column = the position being attended to; dark cells are allowed.

Two differences stand out:

Figure 2. Real probabilities from GPT-2 (124M): for each position, the probability the model assigned to the token that actually came next, given only the tokens before it. Every row is one term of the loss. Content that cannot be predicted from the left context (“natural”, “trained”) gets low probability; continuations such as “class” after “natural language processing” are much easier.

2The GPT series

GPT-1 (2018)GPT-2 (2019)GPT-3 (2020)
Parameters117M1.5B175B
Layers / hidden size12 / 76848 / 160096 / 12288
Context length51210242048
Training dataBooksCorpus (≈7,000 books)WebText (40GB, 8M web pages)≈300B tokens (filtered Common Crawl, WebText2, books, Wikipedia)
How it is usedfine-tune on each taskzero-shot promptingfew-shot in-context learning
Scale:
Figure 3 (interactive). Parameter counts of the three GPT models. On a linear scale, GPT-1 and GPT-2 almost disappear next to GPT-3; on a log scale, each generation is a jump of roughly 10 to 100 times.

GPT-1: pre-train, then fine-tune

GPT-1 (“Improving Language Understanding by Generative Pre-Training”) used the same recipe that BERT made famous a few months later: pre-train, then fine-tune the whole model on each task. (BERT-base, 110M parameters, was deliberately sized to match GPT-1 for comparison.) To fine-tune, GPT-1 turns each input into a single token sequence using special start, delimiter, and extract tokens, and puts a linear classifier on the output at the final extract token, which has seen the whole input.

Figure 4 (interactive). GPT-1's input transformations for fine-tuning (Radford et al., 2018). Blue tokens are the special tokens; the classifier reads the output at [Extract]. Since a left-to-right model cannot see both sentences “at once” from the first one, tasks without a natural order process both orders.

GPT-2: tasks as text

GPT-2 (“Language Models are Unsupervised Multitask Learners”) made the model 10× larger and trained it on WebText, a large collection of web pages. Its main claim was that a big enough language model can do tasks without any fine-tuning, if the task is written as text that the model naturally continues. For example, appending TL;DR: to an article makes the model write a summary, because that pattern appears on the web. Results were far below fine-tuned models, but they showed that task ability can emerge from language modeling alone.

GPT-3: in-context learning

GPT-3 (“Language Models are Few-Shot Learners”) scaled up another 100×. Its key finding was in-context learning: put a task description and a few examples in the prompt, and the model performs the task on a new input, with no gradient updates. The paper distinguishes

Few-shot performance improved sharply with model size; small models barely benefit from the examples.

Prompt
What we want
fromage
Figure 5 (interactive). The prompt format from the GPT-3 paper (English→French). The task is specified entirely in the input; the model's parameters are not changed. For contrast, the readout shows what the small GPT-2 (124M) actually generates for these prompts.

3Generating text

A decoder generates text by repeatedly predicting a distribution over the next token, choosing a token, appending it to the input, and predicting again. Greedy decoding always takes the most probable token; sampling draws a token at random according to the probabilities, which gives more varied text. Each choice changes everything that follows.

Prompt:
Next-token distribution (top 5). Click one of the top 3 to append it.
Figure 6 (interactive). Real next-token probabilities from GPT-2 (124M), precomputed for up to four steps along every path through the top 3 choices. Tokens are subwords; a leading space is part of the token.

4Comparing the three families

Each family provides a good weight initialization, but for different uses:

Encoder-onlyEncoder–decoderDecoder-only
ExamplesBERT, RoBERTaBART, T5GPT, LLaMA
Objectivemasked tokensdenoisingnext token
Sees the inputbidirectionallybidirectionally (encoder)left to right
Generates textnoyesyes
Best forunderstanding, embeddingsinput → output tasks (translation, summarization)general-purpose generation, prompting

Why are today's LLMs decoder-only?

The cost is that a decoder reads the prompt only left to right. An encoder–decoder model reads its input bidirectionally, which can be more parameter-efficient for tasks with a clear input and output. At very large scale this difference matters less, and since GPT-3 most large language models (PaLM, LLaMA, GPT-4, and many others) have been decoder-only.

5Summary

6Practice

Exercise 1: training signal

A training sequence has 512 tokens. How many prediction targets does it provide for (a) BERT's masked LM, (b) a causal LM?

(a) About 15% of 512 ≈ 77 targets. (b) Every position predicts the next token: 511 targets (or 512 if a start token is prepended). The causal LM gets more than 6× as many training signals from the same text.

Exercise 2: causal mask

For the input “the cat sat on”, which positions can the token “sat” attend to in GPT? In BERT?

GPT: “the”, “cat”, and “sat” (itself and everything before it). BERT: all four tokens, including “on”.

Exercise 3: few-shot vs. fine-tuning

You give GPT-3 a prompt with 10 labeled sentiment examples followed by a new review. What happens to the model's parameters? How is this different from fine-tuning?

Nothing: the parameters stay the same. The examples only change the input, and the model infers the task from them in a single forward pass. Fine-tuning would compute gradients on the labeled examples and update the weights, producing a new model specialized for the task.

Quick quiz

7Further reading