Sahin Boydas
Random theme
Select theme
Build a Large Language Model (From Scratch) cover

Build a Large Language Model (From Scratch) by Sebastian Raschka: understanding GPT by coding one

by Sebastian Raschka Β· Manning, 2024

By Sahin Boydasβœ“ Updated December 2026On 1 book list

Sebastian Raschka taught statistics at the University of Wisconsin-Madison before moving into industry research, and he wrote two widely used machine learning books for Python programmers. Build a Large Language Model (From Scratch), published by Manning in 2024, takes one goal and follows it to the end: write a working GPT-style model yourself in PyTorch, with no language-model library doing the work.

The chapters follow the order a model is built. Chapter 2 turns raw text into tokens and embeddings. Chapter 3 codes attention, from a simple version up to multi-head causal attention. Chapter 4 assembles the transformer blocks into a GPT model. Chapter 5 pretrains it and then loads OpenAI's released GPT-2 weights into the same code. Chapters 6 and 7 fine-tune the model, first to classify spam and then to follow instructions. Appendices add a PyTorch primer and fine-tuning with LoRA.

Everything runs on a laptop, which is a large part of its appeal. The code repository has grown past the book, with bonus notebooks that convert the same code to newer open models such as Llama, Qwen3 and Gemma 3, and a follow-up on reasoning models.

How Tech People Read It

Chip Huyen

Huyen, author of Designing Machine Learning Systems and AI Engineering, praised Raschka on the publisher's page for pairing depth with practical engineering and for making hard ideas simple. Her own books are about deploying models in production. She points engineers to this one for the layer underneath: what the model they are deploying actually computes.

Cameron Wolfe

Wolfe, a senior research scientist at Netflix who writes a widely read newsletter on language model research, called it the most understandable and complete explanation of language models he had seen. For someone who reads papers every week, the value is that each idea in the literature has a short, runnable version in the book.

Software engineers moving into AI

The deep learning list on this site recommends it to anyone who codes in Python and wants to understand a language model by building one. An engineer who has only called model APIs comes away knowing what tokens, context windows, temperature and fine-tuning really mean in code. That makes later debugging and model choices far less of a guess.

The Main Ideas

  • A language model is a stack of attention and feed-forward layers trained to predict the next token.
  • Causal self-attention lets each token draw on earlier tokens only, which is what makes the model generate text left to right.
  • Pretraining on unlabeled text teaches general language ability, and the same code can load published weights such as GPT-2's.
  • Fine-tuning a pretrained model for classification or instruction following takes far less data and compute than pretraining.
  • Parameter-efficient methods such as LoRA fine-tune a model by training a small number of added weights.

Who Should Read It

Read it if you can write Python, know a little PyTorch or are willing to learn it from the appendix, and want to understand language models from the inside. Work through it with the code open. Skip it if you want to use language models in products without building them; Hands-On Large Language Models on the same list is the better fit for that.

The Book

Cover of Build a Large Language Model (From Scratch) by Sebastian Raschka

Book 01 Intermediate

Build a Large Language Model (From Scratch)

by Sebastian Raschka

Publisher
Manning, 2024
Free online
No (the code is free)
Goodreads
4.57 of 5 from 430 ratings

Why read it

You write a GPT-style model in PyTorch step by step, with no LLM library: tokenising text, attention, the transformer blocks, pretraining, loading open weights, then fine-tuning the model to classify text and to follow instructions. The model is small enough to run on a laptop. Read it if you can code in Python and want to understand a language model by building one.

What people said

  • β€œSebastian combines deep knowledge with practical engineering skills and a knack for making complex ideas simple. This is the guide you need!”

    Chip Huyen, author of Designing Machine Learning Systems and AI Engineering manning.com β†—

  • β€œThe most understandable and comprehensive explanation of language models yet!”

    Cameron Wolfe, Senior Scientist, Netflix manning.com β†—

Watch

πŸ“š Meet the Author: Sebastian Raschka β€” Build a Large Language Model (From Scratch)Manning PublicationsThe author on why he wrote the book and how to work through it.
Build an LLM from Scratch 1: Set up your code environmentSebastian RaschkaThe first of the author's code-along videos for the book.

On These Book Lists

Frequently Asked Questions

Do I need a GPU for Build a Large Language Model (From Scratch)?

No. The models are kept small enough to train and run on an ordinary laptop, though a GPU makes the pretraining chapter faster.

What do you build in the book?

A GPT-2-style language model in PyTorch, from tokenizer to attention to the full model, then pretraining and fine-tuning it for classification and instruction following.

Is the code free?

Yes. All the book's code and many bonus notebooks are free in the official GitHub repository. The book itself is sold by Manning.

Who is Sebastian Raschka?

A machine learning researcher and former statistics professor at the University of Wisconsin-Madison, and author of Python Machine Learning and Machine Learning with PyTorch and Scikit-Learn.

What should I read after it?

Hands-On Large Language Models for applications such as retrieval and fine-tuning, or Understanding Deep Learning for the wider theory. Both are on this site's deep learning list.