# Hands-On Large Language Models: what the O'Reilly book's code repository actually gives you

> The official notebook repository for Jay Alammar and Maarten Grootendorst's book. It is a twelve-chapter Colab-first teaching path through transformers, embeddings, RAG and fine-tuning, not a library you install.

**HandsOnLLM/Hands-On-Large-Language-Models** — Official code repo for the O'Reilly Book - "Hands-On Large Language Models"

- Repository: https://github.com/HandsOnLLM/Hands-On-Large-Language-Models
- Website: https://www.llm-book.com/
- Stars: 29,151 · Forks: 6,662
- Language: Jupyter Notebook
- License: Apache-2.0
- Published: 2026-09-09 · Updated: 2026-09-09 · Language: en
- Canonical page: https://hysenlabs.com/projects/handsonllm-hands-on-large-language-models

## What this repository is, and who it is not for

This is the code companion to Hands-On Large Language Models by Jay Alammar and Maarten Grootendorst, published by O'Reilly. The README opens by saying the repository holds "the code for all examples throughout the book," and the book's own subtitle in the README is "The Illustrated LLM Book," built around almost 300 custom figures. The homepage points at llm-book.com, and the README lists Amazon, Shroff, O'Reilly, Kindle, Barnes and Noble and Goodreads as places to get the book.

The repository is twelve chapter directories, chapter01 through chapter12, plus a bonus directory, an images directory, a .setup directory, an environment.yml, a requirements.txt and a requirements_min.txt. There is no Python package, no command line entry point, and no releases. The primary language is Jupyter Notebook. If you arrived looking for a library to add to a dependencies file, this is the wrong artifact.

The audience is narrower than the topic. It suits an engineer who has bought or borrowed the book and wants the cells that produce the figures, or someone working through the material independently who is comfortable reading notebooks as documentation. It does not suit a team that needs a maintained SDK, because the repository is a teaching artifact and its chapters are frozen against a specific dependency set.

## How the chapters are laid out and what each one depends on

The README's table of contents maps one notebook per chapter, each with an Open in Colab badge pointing at a file under that chapter's directory on the main branch. The progression is deliberate: Chapter 1 introduces language models, Chapter 2 covers tokens and token embeddings, Chapter 3 looks inside transformer LLMs, then the path splits into classification (Chapter 4), clustering and topic modeling (Chapter 5), prompt engineering (Chapter 6), advanced generation (Chapter 7), semantic search and retrieval-augmented generation (Chapter 8), multimodal models (Chapter 9), creating text embedding models (Chapter 10), fine-tuning representation models for classification (Chapter 11) and fine-tuning generation models (Chapter 12).

Dependencies are split in two. The requirements.txt comments label a block "Hard dependencies throughout the entire book" and a second block "Chapter-specific dependencies." That second block is where the design of the book becomes visible as an installation problem. It contains datamapplot, faiss-cpu, bertopic, annoy, llama_cpp_python, numexpr, langchain, langchain-community, langchain-openai, duckduckgo-search, gensim, setfit, seqeval, trl, peft, accelerate, bitsandbytes and mteb. A reader who installs everything gets a heavy environment; a reader who installs only the hard block will hit ImportError somewhere around Chapter 5 or Chapter 10.

The hard block is pinned exactly: torch == 2.3.1, transformers == 4.41.2, sentence-transformers == 3.0.1, scikit-learn == 1.5.0, numpy == 1.26.4, pandas == 2.2.2, datasets == 2.20.0, matplotlib == 3.9.0, sentencepiece == 0.2.0, nltk == 3.8.1, evaluate == 0.4.2, with scipy >= 1.15.0 as the one floating constraint. Cloud provider clients are pinned too: openai == 1.34.0 and cohere == 5.5.8. Those exact pins are the reason the notebooks run at all, and the reason they age.

## Running it in Google Colab, which is the setup the README recommends

The README's setup advice is explicit: run all examples through Google Colab, which gives a T4 GPU with 16GB of VRAM for free, and the examples were mainly built and tested there, so it should be the most stable platform. The repository does not document a local install procedure beyond shipping requirements.txt and environment.yml.

If you want a local environment instead of Colab, the two files in the repository root are the starting point. The requirements file is an environment description, not an installer script, so the practical move is to create an isolated environment and install from it.

```bash
python -m venv .venv
source .venv/bin/activate
pip install -r requirements_min.txt
```

requirements_min.txt is the smaller list; requirements.txt is the full one with the chapter-specific packages. Start with the minimal file if you only care about the early chapters, and expect to install the chapter-specific packages later.

Once the environment exists, launch JupyterLab, which the hard dependency block pins at 4.2.2 alongside ipywidgets 8.1.3.

```bash
jupyter lab
```

Then open the notebook for the chapter you are reading. The first real use is Chapter 2, which the README titles Tokens and Token Embeddings. In that notebook the flow is to load a tokenizer through transformers, encode text, and inspect the resulting token IDs and embedding vectors. Because the pins are exact, a mismatched transformers version is the most likely cause of a cell failing before any of the interesting output appears.

## The pinned versions are the main failure mode

Exact pins cut both ways. torch == 2.3.1 and transformers == 4.41.2 are what the authors built and tested the notebooks against, so a fresh environment that resolves to newer versions can break cells in ways that look like notebook bugs but are dependency drift. This is the most common way a reader concludes the repository is broken when it is not.

The chapter-specific block makes this worse rather than better. llama_cpp_python appears with a build argument in the requirements file, llm_cpp_python == 0.2.78 -C cmake.args="-DLLAMA_BLAS=ON", which is a pip flag that only some pip versions accept in a requirements file. bitsandbytes, peft, trl and accelerate are all pinned to specific 2024-era releases, and those four are exactly the packages where the wider ecosystem moves fastest. A reader who upgrades one of them to fix an unrelated problem may break the fine-tuning chapters.

There is a second, quieter limitation. Several chapters call hosted APIs through the openai and cohere clients, and the README does not document where credentials come from or what happens when a key is missing. The repository has no .env example in its top-level entries. If you plan to run the generation chapters, expect to supply your own keys and to read the notebook cells to find the variable names.

Finally, the hardware assumption is baked in. The README's recommendation of a free T4 with 16GB of VRAM is the target. Fine-tuning chapters and any local model loading through llama_cpp_python will not behave the same on a laptop CPU, and the repository does not document a reduced configuration.

## How it differs from a from-scratch LLM book's code

The related searches around this repository are dominated by other books: Build a Large Language Model (From Scratch) by Sebastian Raschka, the LLM Engineer's Handbook by Maxime Labonne, Building LLMs for Production by Louis-François Bouchard, and Prompt Engineering for LLMs. The comparison that matters is with the from-scratch book, because the two teach opposite halves of the same subject.

A from-scratch book builds the model: attention, training loop, tokenizer, all written by the reader in code that has no pretrained weights behind it. This repository does the reverse. It starts from pretrained models loaded through transformers and sentence-transformers and spends its chapters on what you do with them: embed text, classify it, cluster it, retrieve with it, fine-tune it with peft and trl, and evaluate it. Chapter 3 looks inside transformer LLMs, but looking is not building.

That difference changes what you can verify. A from-scratch codebase lets you check your implementation against a reference loss curve. This repository lets you check your environment against pinned versions and your output against the figures in the book. Neither is better in the abstract; they answer different questions. If you need to debug a training run you own, the from-scratch path teaches the internals. If you need to ship a RAG pipeline next month, Chapter 8 is closer to the work.

## Licence, maintenance and the cost of keeping it running

The repository is Apache-2.0. That is a permissive licence for the code in the notebooks, and it means you can reuse snippets in your own work with the usual attribution and notice requirements. It says nothing about the book text, the almost 300 figures, or the pretrained model weights the notebooks download, which carry their own licences from their own publishers. If you plan to redistribute anything from the images directory, check the source of those images separately rather than assuming Apache-2.0 covers them.

The last push to the main branch was on 2026-04-24, and the repository is not archived. There are no retrieved releases, so there is no versioned artifact to pin against and no changelog to read before upgrading. Upgrades in practice mean pulling the notebooks and re-resolving dependencies, which is where the exact pins in requirements.txt become a cost rather than a guarantee.

Budget for that cost honestly. A reader who runs the notebooks on Colab pays almost nothing in maintenance because Colab's image and the requirements file drift together and the README already points there. A reader who maintains a local environment for a course or a workshop is signing up to re-test the chapter-specific packages each term, because bertopic, langchain, trl and peft are the ones most likely to have moved.

## Conclusion

Adopt this repository if you are learning LLM engineering and want runnable notebooks that match a book chapter by chapter, or if you teach a course and need a Colab-ready path with a T4 GPU. Do not adopt it if you need a supported library, an API, or code you can import into production; there are no releases, no package on any index, and the notebooks are tied to the exact versions in requirements.txt. Before you commit time, open the chapter notebook you care about on Colab, check that its cell-level imports match the pinned versions in requirements.txt, and confirm the chapter-specific dependencies for that notebook are installed in the same runtime. The repository's own answer to setup is Colab, and that is the only path the README endorses.

## FAQ

### Is there a PDF version of the book Hands-On Large Language Models?

The repository does not distribute one. The README links to Amazon, Shroff Publishers, O'Reilly, Kindle, Barnes and Noble and Goodreads as the places the book is available, and the code repository is separate from the book text.

### What are the top 5 LLM models?

The repository does not rank models. It teaches techniques across chapters such as text classification, semantic search and fine-tuning, and the README's table of contents names chapters rather than a model leaderboard.

### Is ChatGPT an LLM?

The repository does not address ChatGPT specifically. Its scope is the practical concepts behind large language models, covered across twelve chapters from tokens and embeddings through to fine-tuning generation models.

### Is hands-on machine learning good?

The repository does not evaluate other machine learning books. It is the code companion to Hands-On Large Language Models, with one notebook per chapter covering tokens, embeddings, classification, semantic search, multimodal models and fine-tuning.

## Sources

- [HandsOnLLM/Hands-On-Large-Language-Models on GitHub](https://github.com/HandsOnLLM/Hands-On-Large-Language-Models)
- [Issues](https://github.com/HandsOnLLM/Hands-On-Large-Language-Models/issues)
- [License: Apache-2.0](https://github.com/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/LICENSE)
- [Project website](https://www.llm-book.com/)
- [README](https://github.com/HandsOnLLM/Hands-On-Large-Language-Models/blob/main/README.md)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/handsonllm-hands-on-large-language-models
