Build a Large Language Model (From Scratch)

Notes by Peter Bessman on the book by Sebastian Raschka

Section Description Notebook
Chapter 2 Working with text data ipynb
Chapter 3 Coding attention mechanisms ipynb
Chapter 4 Implementing a GPT model from scratch to generate text ipynb
Chapter 5 Pretraining on unlabeled data ipynb
↳ Exercise 4 Pretraining for one more epoch ipynb
Chapter 6 Fine-tuning for classification ipynb
Chapter 7 Fine-tuning to follow instructions Coming Soon
Appendix A Intro to PyTorch ipynb
Appendix D Adding bells and whistles to the training loop Coming Soon
Appendix E Parameter-efficient fine-tuning with LoRA Coming Soon
Python Code Code refactored out of notebooks for reuse —

These are my notebooks produced by working through this wonderful book. Many thanks to Dr. Raschka for the time and effort he invested into this. If you're on the fence, I highly recommend it. He assumes next to no background knowledge, and I found it a relative breeze to work through. That said, I've previously studied deep learning and linear regression with some rigor, so YMMV.

These are rough notes, some of which feature wild digressions as I worked things out to ensure my own idiosyncratic needs for understanding. You will find much more polish in the official repo for the book. I'm publishing these mostly so that I have convenient access to these insights as I may need them in other contexts. If they help anybody else, that's a nice bonus.

My general method for this kind of thing is to type up notes as I'm reading through the book, with a focus on whatever is new and striking to me. After I've digested a chunk of a chapter, I'll then try to implement the code referencing my notes and library docs, not the book — though if I get stuck, I'll check the book and/or have an LLM check my work. I also just copy-paste sample code for anything I already know cold or that seems like unedifying boilerplate.