Lecture 5: Large Language Models (LLMs)

What makes a language model large, why does size matter so much — and how do you build a ChatGPT from scratch? Watch the lecture in short chapters with English and Chinese subtitles, follow the lecture map below, then try the ideas in Colab.

📅 Oct. 23rd, 2026 🎥 chapters · min 🖼 slides 💬 EN + 中文 subtitles 🧭 Lecture map 💻 Colab notebooks ⬇ Slides (PDF)
Transcript follows the video · click a sentence to jump · Shift + ←/→ jumps between slides

1The lecture map

What makes a language model large, why does size matter — and how is a ChatGPT built, step by step?

Five acts, eleven chapters. First we see why scale turns a next-word predictor into a general problem solver, then follow the ChatGPT story and the cheapest way to use such a model. Then we build one: tokenizer, pretraining, instruction tuning and RLHF — and finally compare the stages and ask whether bigger is still better. Click a chapter to watch it.

IWhy large
Scale turns a next-word predictor into a general problem solver
IIThe ChatGPT story
GPT-3 + code + instructions + human feedback
IIIUse it
Prompts and agents, no training needed
IVBuild it
Tokens → pretraining → SFT → RLHF
VReflect
Compare the stages; what comes after scaling
Chapter by chapter what each chapter covers, and the question it leaves for the next
  1. IWhy largeScale turns a next-word predictor into a general problem solver
  2. 1

    What's New, a Transformer Recap and Why Scale Matters

    The field moves in weeks: new models, film-quality video and an agent that “actually does things”. Back to the Transformer: less built-in structure scales better, loss falls along a power law, and some abilities only switch on at scale.

    → So what exactly is a “large” language model?
  3. 2

    What Is an LLM? Compression, AGI and How Large Is Large

    One model for nearly everything. Predicting the next word well forces a network to compress the internet — and the facts in it. “Large” means billions of parameters, enormous compute and trillions of tokens (36 trillion for Qwen3).

    → Why is all that size worth it?
  4. 3

    Why Larger Models: Emergent Abilities and Generalization

    Bigger models know more, learn tasks from a few examples or a plain description, and generalize by recombining what they have seen. Even techniques such as chain-of-thought and RLHF only start to help above a certain size.

    → How did these ingredients come together in practice?
  5. IIThe ChatGPT storyGPT-3 + code + instructions + human feedback
  6. 4

    A Case Study: From GPT-3 to ChatGPT, GPT-4 and o1

    ChatGPT was GPT-3 plus code training, instruction tuning and RLHF — a breakthrough in interaction more than in knowledge. Then GPT-4, GPT-4V, Sora and o1, and three trends of the modern LLM: large-scale RL, looped Transformers and on-policy distillation.

    → How can you use such a model yourself?
  7. IIIUse itPrompts and agents, no training needed
  8. 5

    Using LLMs, Level 1: Prompt Engineering and Agents

    Use the model as a fixed black box: prompt it in a chat window or through an API, or wrap it in an agent with memory, tools, planning and actions — from LangChain and Dify to Manus in the cloud and OpenClaw on your own machine.

    → Agents are easy to build — but what happens inside the model when you train your own?
  9. IVBuild itTokens → pretraining → SFT → RLHF
  10. 6

    Training from Zero: The Pipeline and Tokenization (BPE)

    A model learns like a student: words, textbooks, exercises, a teacher's feedback. Step zero is tokenization: subwords balance vocabulary size and sequence length, BPE learns them by merging frequent pairs, and a tokenizer that ignores your language makes everything slower and costlier.

    → With tokens in hand, how does the model read its textbooks?
  11. 7

    Pretraining: Language Modeling and Eight Data Tips

    Pretraining is next-token prediction over trillions of tokens, and the secret sauce is the data: sources and mixing ratios, continued pretraining, and eight tips — filter, reformat, deduplicate, mix, order, scale (Chinchilla), mask and synthesize.

    → A base model continues text — how do we make it follow instructions?
  12. 8

    Instruction Finetuning (SFT): Hypotheses and Tips

    Language modeling is not assisting users. SFT trains on instruction–response pairs; it mostly teaches format (LIMA), sometimes knowledge, and generalizes with diverse tasks (FLAN). Tips: distillation, self-instruct, loss on the output only, complex instructions.

    → The token-level loss treats every mistake alike — can we optimize directly for what humans prefer?
  13. 9

    RLHF: Reward Models, InstructGPT and ChatGPT

    Comparing answers is easier than writing them. Learn a reward model from human comparisons, then optimize the policy against it with PPO. A 1.3B RLHF model beat a 12.9B supervised one; InstructGPT scaled the recipe and ChatGPT added conversation — but human judges have biases.

    → Where do the rest of us get conversation data — and how do the stages compare?
  14. VReflectCompare the stages; what comes after scaling
  15. 10

    Multi-turn Data, PlatoLM and Pretraining vs. SFT vs. RL

    ShareGPT gave open models real conversations; PlatoLM trains a user simulator to ask like people do. Pretraining and SFT share one loss, so documents can be turned into Q&A. RL generalizes where SFT memorizes: incentivize, don't teach.

    → If data and RL matter so much, do we still need ever-larger models?
  16. 11

    Small LLMs, the Densing Law and the End of Scaling?

    Data and hardware put walls in front of scaling. Small models on phones, Phi-4 built on synthetic data, and capability density that keeps rising. Pretraining as we know it may end — next come test-time scaling, agents, denser models and applications.

2Try it in Colab

Three short notebooks turn the lecture into experiments. Click Open in Colab, then Runtime → Run all. Each ends with exercises. All three run on a free CPU runtime; notebook 2 trains six small models, so a free T4 GPU (Runtime → Change runtime type) cuts it from about ten minutes to a couple. To fine-tune and RL-train real models, continue with Tutorial 2: Training Your Own LLMs.

Notebook 1 · Chapter 6 · ~3 min

Tokenizers: BPE from scratch

  • Replay slide 83's merges: aaabdaaabac → XdXac
  • Train your own BPE and watch “tokenizing” split into subwords
  • See the original LLaMA tokenizer turn 28 Chinese characters into 35 tokens
  • Compare GPT-2, LLaMA and Qwen on English, Chinese and Arabic
Open in Colab .ipynb · CPU
Notebook 2 · Chapters 1 & 7 · ~10 min

Scaling laws: fit your own power law

  • Train six tiny GPTs (3K–800K parameters) on Shakespeare
  • Fit loss = a·N−α + c on a log-log plot and extrapolate
  • Split a compute budget between parameters and tokens with the Chinchilla law
  • See two fits of the same data disagree (~70 vs. ~20 tokens per parameter)
Open in Colab .ipynb · CPU (T4 GPU faster)
Notebook 3 · Chapters 3 & 8 · ~5 min

Base vs. instruction-tuned: prompting a small LLM

  • Ask SmolLM2-135M base and instruct the moon-landing question of slide 106
  • Zero-shot vs. few-shot sentiment, scored by next-token probabilities
  • Look at the chat template: what SFT data really looks like
  • Build the “loss on the output only” mask of slide 119
Open in Colab .ipynb · CPU

3Concept index

Key terms of the lecture. Each link opens the video at the slide where the idea is explained.

5Quotes & reading

"The biggest lesson that can be read from 70 years of AI research is that general methods that leverage computation are ultimately the most effective, and by a large margin."

The idea behind slide 9: less hand-built structure, more scale.

"The dialogue format makes it possible for ChatGPT to answer followup questions, admit its mistakes, challenge incorrect premises, and reject inappropriate requests."

ChatGPT's breakthrough was in interaction and alignment, not in raw knowledge.

"Almost all knowledge in large language models is learned during pretraining, and only limited instruction tuning data is necessary to teach models to produce high quality output."

The superficial alignment hypothesis of slide 112 — with its question mark.

"Pre-training as we know it will end. … Data is not growing: we have but one internet, the fossil fuel of AI."

Ilya Sutskever, NeurIPS 2024 talk, shown on slide 166
Why the lecture ends with denser models, reasoning and agents instead of “just scale”.

Further reading

6About this video

This is an AI-narrated version of the lecture. The slides are the ones used in class. The spoken script was written from the slides with AI assistance and is read in an AI clone of Prof. Benyou Wang's voice (MiniMax speech synthesis); the picture in the corner is a still photo. The red dot points at what is being discussed. When the narration and the slides disagree, trust the slides and the in-class lecture — and please tell us, so we can fix it.
CSC5051/CSC6052/MDS5110 Natural Language Processing · CUHK-Shenzhen · Fall 2026 · Back to the course page