GPT — Generative Pre-trained Transformer

Two-panel comic: 'Raw GPT' shows a robot buried in books labeled 'All of the Internet', asked 'What is the capital of France?' but spewing a ticker tape of text '...is a question frequently asked in geography textbooks published by...', captioned 'Predicts the next word. That's all.'; 'After Human Feedback' shows the same robot now wearing a headset and 'Helpful' badge, calmly answering 'Paris.' while a human holds up RLHF good/bad cards, captioned 'Now it actually helps.'
What You’ll Learn

You’ll learn how GPT uses next-token prediction to generate text, and why scale makes that simple objective surprisingly powerful. You’ll also see how sampling controls, scaling laws, in-context learning, and RLHF shape raw prediction into useful assistant behavior.

The Big Idea: Just Predict the Next Word

GPT’s training objective is the simplest possible:

Given all previous tokens, predict the next one.

That’s it. No masking, no fill-in-the-blank, no special objectives. Just relentlessly predict the next token, billions of times, on massive text corpora.

The remarkable discovery: this simple objective, at sufficient scale, produces general intelligence.


Architecture

GPT is the decoder stack from the Transformer — with causal (masked) self-attention:

StageWhat Happens
InputToken sequence (e.g., “The cat sat on the”)
EmbeddingToken + Position embeddings
Decoder layersN layers of causal self-attention + FFN
Output projectionHidden state → vocabulary probabilities
PredictionSample next token from distribution
ModelYearLayersd_modelParamsContext
GPT-1201812768117M512
GPT-220194816001.5B1024
GPT-320209612288175B2048
GPT-42023??~1T?128K

Interactive: Generation in Action

Experiment with autoregressive generation. Adjust temperature and top-k to see how sampling strategies change the output:

Autoregressive Generation

The cat ▌
Next token distribution:
"was"
30.3%
"sat"
21.1%
"ran"
13.5%
"is"
9.8%
"and"
5.2%
"small"
4.8%
"on"
4.3%
"your"
4.0%
"hat"
3.5%
"dog"
3.4%
"the"
0.0%
"a"
0.0%
Try: Set temperature to 0.1 (deterministic) vs 2.0 (random). Set top-k to 1 (greedy) vs 30 (diverse).

What to look for: Generate a few tokens at low temperature (0.1), then reset and try high temperature (2.0). Low temperature produces predictable, repetitive text. High temperature produces surprising, sometimes nonsensical text. Then experiment with top-k: setting it to 1 forces greedy decoding regardless of temperature.

Understanding the Controls

Temperature scales the logits before softmax — low temperature makes the model more deterministic, high temperature makes it more creative:

TemperatureDistributionEffect
T = 0.1Very peakedAlmost always picks the top token (deterministic)
T = 1.0StandardSamples naturally from learned distribution
T = 2.0FlattenedMore diverse, surprising choices

Top-k limits sampling to the top k most likely tokens, filtering out low-probability noise.

Top-p (nucleus sampling) includes the smallest set of tokens whose cumulative probability exceeds pp. Unlike top-k which always considers the same number of tokens, top-p is adaptive — it considers fewer tokens when the model is confident and more when it’s uncertain.

ContextTop-k (k=5)Top-p (p=0.9)
“The capital of France is”Always 5 tokensMaybe 1-2 tokens (high confidence)
“I feel really”Always 5 tokensMaybe 10+ tokens (uncertain)

This is why most production LLMs (including ChatGPT and Claude) use top-p rather than top-k.

Quick Check
If you set temperature to 0.1 and top-k to 1, what type of generation do you get?
Your turn
Choose an answer to check your understanding.

Scaling Laws: More Compute = Better Model

GPT-3’s paper revealed that model performance follows predictable power laws. In plain terms: if you want a better model, just make it bigger, feed it more data, and give it more compute. The improvement is smooth and predictable — no guesswork needed.

FactorPractical Meaning
More parameters10x more params gives roughly 16% loss reduction
More data10x more data gives roughly 20% loss reduction
More compute10x more compute gives roughly 11% loss reduction

Emergent Abilities

At certain scales, new capabilities appear suddenly — they’re nearly absent in smaller models:

AbilityAppears AroundExample
Few-shot learning~1B paramsLearning from examples in the prompt
Arithmetic~10B params”What is 47 × 83?”
Code generation~50B paramsWriting working Python functions
Chain-of-thought~100B params”Let me think step by step…”
Self-correction~100B+ params”Wait, that’s wrong. Let me reconsider…”

In-Context Learning: GPT’s Superpower

GPT-3’s most surprising ability: learning from examples in the prompt without updating weights.

Prompting StyleExample
Zero-shot”Translate to French: Hello world” → “Bonjour le monde”
One-shot”Good morning → Bonjour” then “Hello world →” → “Bonjour le monde”
Few-shotMultiple examples then query → model identifies the pattern

The model doesn’t update its parameters — it uses the attention mechanism to identify the pattern in the prompt and apply it. This is a form of meta-learning that emerges at scale.

Quick Check
During in-context learning (few-shot prompting), what happens to the model's weights?
Your turn
Choose an answer to check your understanding.
Fill in the Blanks
GPT uses self-attention, meaning each token can only attend to tokens. This enables autoregressive generation one token at a time.
Fill in every blank, then check your answer.

From GPT to ChatGPT: RLHF

Pre-trained GPT is a great text predictor but not a great assistant. Reinforcement Learning from Human Feedback (RLHF) bridges this gap:

StepProcessResult
1Pre-train on text (next-token prediction)Raw language model
2Supervised fine-tuning (SFT) on conversationsFollows instructions
3Train reward model from human preferencesKnows what “good” looks like
4Optimize with PPO/DPO using reward modelHelpful, harmless, honest

This process transforms a raw text predictor into ChatGPT, Claude, or other chat models.


Quick Summary

ConceptDetails
ArchitectureDecoder-only transformer with causal masking
TrainingNext-token prediction on massive text
Key innovationScale + simple objective = general intelligence
SamplingTemperature, top-k, top-p control generation diversity
Emergent abilitiesFew-shot learning, reasoning, code generation
RLHFAligns raw LLM with human preferences

Learning Checklist
  • I can explain GPT’s next-token prediction objective and why it produces general capabilities at scale
  • I understand how temperature, top-k, and top-p control generation diversity and can describe the tradeoffs
  • I can describe scaling laws and why bigger models with more data reliably improve
  • I understand in-context learning (zero-shot, one-shot, few-shot) and that no weights are updated during it
  • I can explain the RLHF pipeline that transforms a raw language model into a helpful assistant
  • I can compare GPT and BERT architecturally and explain why modern LLMs are decoder-only

Next: An Optional Training Lab, Then Agents

Use the training loop you learned to adapt an existing model in Fine-tune an Open Model (Optional) →. The lab starts with pretrained weights and saves a small LoRA adapter.

You can also continue directly to LLM Agents →, where a language model becomes part of a loop that calls tools and responds to their results.