anaksor-ocr
Sokheng · Kit
Reads Khmer and English text from documents, receipts and photos of signs, using a detector for text lines and a recogniser for each line. Suits developers who…

The official code for Sebastian Raschka’s book on building a GPT-like LLM in PyTorch, one chapter at a time. The notebooks cover text data, attention, pretraining and finetuning. The setup notes cover uv, pixi, Conda, Docker, Lightning and Colab.
Build a Large Language Model (From Scratch) is an open-source project on GitHub in the Education category, listed by Mindket. It is free. This is version 2, last updated on . Install it from GitHub as its README says. Get Mindket’s setup notes on your Mindket account, as a zip.
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git cd LLMs-from-scratch
This is the official code repository for Sebastian Raschka’s book Build a Large Language Model (From Scratch), which Manning publishes. Its README says you build a GPT-like LLM in PyTorch step by step, from text data through pretraining to finetuning, without any external LLM libraries. The method for training this small model mirrors the approach used to build large models such as those behind ChatGPT. The repository holds the book’s notebooks, scripts and bonus material. The book itself is a separate product that the README links at Manning and Amazon.
Programmers who know Python and want to see how an LLM works by coding one. The README calls a strong foundation in Python the most important prerequisite. Experience with deep neural networks helps, and PyTorch basics are useful but not required. Appendix A is a short introduction to PyTorch.
| Industry | Who uses it | How they use it | Example |
|---|---|---|---|
| Self-taught developers | Programmers who know Python | Read a chapter, run its notebook and check the exercise solutions | A developer runs ch03.ipynb to code attention, then opens exercise-solutions.ipynb in the same folder. |
| Students and study groups | Learners in a machine learning course | Go chapter by chapter and test themselves with the free quiz PDF from Manning | A study group finishes Chapter 4, then works through that chapter’s quiz questions in the PDF. |
| Machine learning engineers | Engineers who call LLMs through APIs | Read the bonus folders to see how newer architectures are built from scratch | An engineer opens the Qwen3 folder in chapter 5 to read a from-scratch Qwen3 model. |
| Instructors | Teachers and workshop leads | Assign a chapter notebook and its code-along video | An instructor assigns Chapter 2 and plays the author’s video on working with text data. |
Skip it if you want a ready model to call or a library to build products on. The README describes the model you train as small but functional, made for education.
The code is Jupyter notebooks and Python scripts that use PyTorch. Chapters 5 to 7 also use TensorFlow to read the GPT-2 weights. The README says the main chapters run on a conventional laptop with no special hardware, and use a GPU automatically when one is there. The setup page says an NVIDIA GPU in the cloud helps most in chapters 5 to 7.
Get it saves a zip of Mindket’s setup notes in your downloads folder, with each route’s steps from the repository’s setup pages. If Python is already installed, the setup page’s quickest route is one line from the repository’s root folder: pip install -r requirements.txt. The author’s own route adds a uv virtual environment first.
| Need | Detail |
|---|---|
| Python | 3.10 to 3.12 for every chapter. pyproject.toml allows >=3.10,<3.15 but installs TensorFlow, which chapters 5 to 7 use to load the GPT-2 weights, only below 3.13. The check script flags only versions below 3.9 |
| Git | To clone the repository. The README also offers a Download ZIP button |
| A network connection | Chapters 5 to 7 download the GPT-2 weights, and the notebooks load their pictures from the author’s website |
| An NVIDIA GPU | Optional. The code uses one automatically when it finds it |
| Ollama | For chapter 7’s evaluation step, which the main chapter describes and ollama_evaluate.py summarizes, and for the chapter 7 bonus notebooks that use Ollama |
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git cd LLMs-from-scratch
pip install uv uv venv --python=python3.10 source .venv/bin/activate uv pip install -r requirements.txt
On Windows, the setup tips say you may have to replace the activate line with source .venv/Scripts/activate or .venv/Scripts/activate. If a dependency fails, fall back to plain pip.
pip install -r requirements.txt
python setup/02_installing-python-libraries/python_environment_check.py jupyter lab
For Windows the author recommends pixi over the native uv commands, because some dependencies in pyproject.toml cause problems there. On Google Colab, put this line at the top of a notebook:
pip install uv && uv pip install --system -r https://raw.githubusercontent.com/rasbt/LLMs-from-scratch/refs/heads/main/requirements.txt
Read a chapter, then open its notebook. A chapter notebook holds all the code as it appears in the book, and chapters 2 to 7 and Appendix A each have an exercise-solutions notebook. The README’s table gives each chapter’s main notebook and a folder of bonus material.
| Chapter | Main notebook | Folder |
|---|---|---|
| 2: Working with Text Data | ch02.ipynb | ch02/01_main-chapter-code |
| 3: Coding Attention Mechanisms | ch03.ipynb | ch03/01_main-chapter-code |
| 4: Implementing a GPT Model from Scratch | ch04.ipynb | ch04/01_main-chapter-code |
| 5: Pretraining on Unlabeled Data | ch05.ipynb | ch05/01_main-chapter-code |
| 6: Finetuning for Text Classification | ch06.ipynb | ch06/01_main-chapter-code |
| 7: Finetuning to Follow Instructions | ch07.ipynb | ch07/01_main-chapter-code |
| Appendix A: Introduction to PyTorch | code-part1.ipynb, code-part2.ipynb | appendix-A/01_main-chapter-code |
Chapters also have standalone scripts that summarize them, such as gpt_train.py in chapter 5. Chapter 7’s main code README shows how to run two of its scripts, which sit in the ch07/01_main-chapter-code folder:
python gpt_instruction_finetuning.py python ollama_evaluate.py --file_path instruction-data-with-response-standalone.json
The README’s sample output for the second one starts with “Ollama running: True”.
You want to follow the attention chapter. You activate your environment, start JupyterLab from the repository folder and open ch03/01_main-chapter-code/ch03.ipynb.
cd LLMs-from-scratch source .venv/bin/activate jupyter lab
Run the cells from the top. When you finish the chapter, open exercise-solutions.ipynb in the same folder and compare it with your own work. The troubleshooting page says these main notebooks are kept in sync with the printed book.
If you are new. A large language model, or LLM, is the kind of model behind chat tools such as ChatGPT. The book teaches how one works, so you can start without knowing. Read the setup recommendations in the README table. Chapter 1 has no code, so the first notebook is Chapter 2’s. If Python is new to you, learn it first. If PyTorch is new, read Appendix A. The README also links the author’s post on how to best read the book.
For experts. The optional llms-from-scratch package on PyPI imports the chapters’ code, such as MultiHeadAttention from llms_from_scratch.ch03, and has KV-cache versions of GPT-2, Llama 3 and Qwen3.
Bonus folders in chapter 4 cover grouped-query, multi-head latent and sliding window attention, Gated DeltaNet and Mixture-of-Experts. Chapter 5 adds from-scratch Llama 3.2, Qwen3, Gemma 3 and Olmo 3 models, and chapter 7 adds DPO. The bonus notebooks need more packages, which one uv line installs:
uv pip install --group bonus
Appendix A’s multi-GPU demo is a script, run as python DDP-script.py, with a torchrun version beside it. On an Apple Silicon Mac, the troubleshooting page says many scripts skip the mps backend on purpose, so rerun on cpu first if the losses diverge. The author’s sequel, Build A Reasoning Model (From Scratch), has its own repository, and the README links bonus material from it.
The code and notebooks run on your machine. Installing the packages and the first run of chapters 5 to 7 need the network, and the notebooks load their pictures from the author’s website each time you open one.
This kit holds setup notes only. Mindket wrote them. The code, notebooks and bonus material stay in Sebastian Raschka's repository: https://github.com/rasbt/LLMs-from-scratch
These notes are not made or endorsed by Sebastian Raschka or Manning. The README says the repository "contains the code for developing, pretraining, and finetuning a GPT-like LLM and is the official code repository for the book Build a Large Language Model (From Scratch)". The notes were written from the README, the setup pages and the files named under Sources, read on 3 November 2026.
License: the LICENSE.txt file is the Apache License 2.0 with one changed definition. Its "Source" form is "the preferred form for making modifications, explicitly excluding any books specific to this software and any related images". The copyright line names Sebastian Raschka, and GitHub's license field reads "Other". This kit holds neither the book nor its images. Source: https://github.com/rasbt/LLMs-from-scratch/blob/main/LICENSE.txt
The README says that in the book you "learn and understand how large language models (LLMs) work from the inside out by coding them from the ground up, step by step", and that the method for training "your own small-but-functional model for educational purposes" mirrors the approach used for large foundational models such as those behind ChatGPT. The book also has code for loading the weights of larger pretrained models for finetuning. The README links the book at Manning, the publisher, and on Amazon. Source: https://github.com/rasbt/LLMs-from-scratch/blob/main/README.md
The code uses PyTorch and, in the README's words, no external LLM libraries. The most important prerequisite is "a strong foundation in Python programming". Experience with deep neural networks helps, and PyTorch basics are useful but not required, because Appendix A is a concise introduction to PyTorch.
| Chapter | Folder | Code |
|---|---|---|
| 1: Understanding Large Language Models | Not listed | None |
| 2: Working with Text Data | ch02 | Yes |
| 3: Coding Attention Mechanisms | ch03 | Yes |
| 4: Implementing a GPT Model from Scratch | ch04 | Yes |
| 5: Pretraining on Unlabeled Data | ch05 | Yes |
| 6: Finetuning for Text Classification | ch06 | Yes |
| 7: Finetuning to Follow Instructions | ch07 | Yes |
| Appendix A: Introduction to PyTorch | appendix-A | Yes |
| Appendix B: References and Further Reading | appendix-B | None |
| Appendix C: Exercise Solutions | appendix-C | Links to each chapter's solutions |
| Appendix D: Adding Bells and Whistles to the Training Loop | appendix-D | Yes |
| Appendix E: Parameter-efficient Finetuning with LoRA | appendix-E | Yes |
Each folder with code has a 01_main-chapter-code folder with the notebooks that match the book, and the chapter folders also hold numbered bonus folders beside it. Titles and folders are copied from the README's table. The main notebook of each chapter is listed in setup/chapter-map.md.
uv sync and uv run.uv add commands.llms-from-scratch package, which imports the chapters' code.pyproject.toml file says >=3.10,<3.15, and its TensorFlow lines apply only below Python 3.13. See setup/troubleshooting.md for where the pages disagree.Source: https://github.com/rasbt/LLMs-from-scratch/blob/main/README.md and https://github.com/rasbt/LLMs-from-scratch/blob/main/setup/README.md
The README gives two ways: the Download ZIP button, or this command. Source: https://github.com/rasbt/LLMs-from-scratch/blob/main/README.md
git clone --depth 1 https://github.com/rasbt/LLMs-from-scratch.git
The Download ZIP link the README uses is https://github.com/rasbt/LLMs-from-scratch/archive/refs/heads/main.zip
If you want to keep your own changes and still receive updates, fork the repository first. See setup/troubleshooting.md.
The pages give no update step for a plain clone. The troubleshooting page adds an upstream remote for a fork, shown in setup/troubleshooting.md. For a clone you did not fork, git pull inside the folder updates it, which is Mindket's line and not the author's.
To remove it, delete the folder. A virtual environment made by uv lives in the .venv folder in it, and the native uv page says you can simply delete that folder to start from scratch. The Docker page gives docker image ls and docker image rm [IMAGE_ID_OR_NAME] for the DevContainer's image, as shown in setup/docker-dev-container.md.
README.md 8 KB setup/chapter-map.md 5 KB setup/colab-and-lightning.md 2 KB setup/conda.md 3 KB setup/docker-dev-container.md 5 KB setup/native-uv.md 3 KB setup/pip-package.md 3 KB setup/pixi.md 3 KB setup/troubleshooting.md 5 KB setup/uv-and-pip.md 5 KB setup/vs-code-and-jupyter.md 2 KB
Updated by Mindket to the current version of this kit.
Listed GitHub projects in the same category that share the most topics with this one.
| Product | Stars | Activity | Language | License | Last change |
|---|---|---|---|---|---|
| Build a Large Language Model (From Scratch) This page | 107,934 | — | — | — | — |
| AI Engineering from ScratchShares from-scratch · deep-learning · generative-ai | 77,834 | — | — | MIT | — |
| Generative AI for BeginnersShares gpt · language-model · generative-ai | 123,169 | Active | Jupyter Notebook | MIT | |
| AI For BeginnersShares artificial-intelligence · deep-learning · ai | 70,626 | — | — | MIT | — |
| LLM CourseShares large-language-models · llm | 84,938 | — | — | Apache-2.0 | — |
Posts and comments that name this project on Hacker News, Bluesky, X, Reddit, Facebook and YouTube, found by a weekly search and on Trendshift. Mindket doesn’t write or check them. Open one to read it where it was posted.
Sokheng · Kit
Reads Khmer and English text from documents, receipts and photos of signs, using a detector for text lines and a recogniser for each line. Suits developers who…
Qwen · Kit
Qwen2.5-7B-Instruct as GGUF files in eight quantization sizes, to chat with locally through llama.cpp. For people who want a capable 7.6B model on their own co…
ACE-Step · Kit
Generates music from text with a 4B diffusion decoder, 50 steps and guidance control, aiming for higher audio quality than the base. For creators with a GPU of…
rohitg00 · Kit
Rohit Ghumare’s free, MIT-licensed course that builds AI from raw math up to agents and production, in twenty phases. Tutor skills for Claude Code, Codex and C…
microsoft · Kit
Microsoft Cloud Advocates’ free course on building generative AI apps, in 21 lessons. Learn lessons explain a concept, and Build lessons add Python and TypeScr…
langgenius · Kit
LangGenius’s open-source platform for building LLM apps: visual workflows, RAG, model management and agents with a sandbox. Its difyctl tool and skill let Clau…