Skip to content
The transformer architecture: an encoder and a decoder built from multi-head attention, feed forward and add and norm blocks, leading to a linear layer, a softmax and output probabilities.
Based on Figure 1 of Vaswani et al., Attention Is All You Need (2017).

Premium

Build an LLM from Scratch

Build a small GPT-style language model step by step, from the maths and tokens to a model that follows instructions.

Last updated Estimated reading time: 52minutes

Log in to enrol

Enrolling is free and keeps track of your progress.

Some lessons need Premium

One lesson is free to start now. The remaining 18 lessons are part of Premium membership. Log in if you’re a member, or see what membership includes.

About this course

Large language models can feel like magic. This course takes the magic apart by building one yourself, one piece at a time, so you understand what happens between the text you type and the answer you get back.

You start with the maths you need, vectors and matrices, and see how models handled sequences before transformers. Then you turn text into tokens and embeddings, build attention from scratch, and assemble the blocks into a complete GPT-style transformer. Finally, you pretrain the model, generate text with it and fine-tune it to follow instructions.

Who it's for: developers who know some Python and want to understand how LLMs work from the inside, not just how to call them.

What you’ll learn

  • Explain how a large language model turns text into predictions
  • Build a byte-pair encoding tokenizer
  • Implement self-attention and multi-head attention in PyTorch
  • Assemble a GPT-style transformer model
  • Pretrain the model and generate text
  • Fine-tune the model to follow instructions

Course outline

7 sections · 19 lessons