HandsOnLLM/Hands-On-Large-Language-Models

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

What is this project?

This repository is the official companion code for the book "Hands-On Large Language Models", written by Jay Alammar and Maarten Grootendorst. The authors playfully call it "The Illustrated LLM Book" because it relies heavily on visuals — almost 300 custom-made figures — to teach how large language models (LLMs) work and how to use them.

The book itself is a 400-page guide published by O'Reilly, and this GitHub repo contains all the code examples from it, organized into 12 chapters.

What does it contain?

Each chapter has a Jupyter notebook (an interactive coding document) that walks you through a hands-on example. The chapters progress from basics to advanced topics:

  1. Introduction to Language Models — what LLMs are and how they fit into the AI landscape
  2. Tokens and Embeddings — how text is broken into pieces and converted into numbers
  3. Looking Inside Transformer LLMs — the internal architecture that powers modern LLMs
  4. Text Classification — teaching models to sort text into categories
  5. Text Clustering and Topic Modeling — grouping similar texts and finding themes
  6. Prompt Engineering — crafting instructions to get better responses from LLMs
  7. Advanced Text Generation Techniques and Tools — more sophisticated ways to generate text
  8. Semantic Search and Retrieval-Augmented Generation — searching by meaning and combining retrieval with generation
  9. Multimodal Large Language Models — models that work with images, audio, and other data types beyond text
  10. Creating Text Embedding Models — building your own models that convert text into vectors
  11. Fine-tuning Representation Models for Classification — adapting pre-trained models for classification tasks
  12. Fine-tuning Generation Models — adapting pre-trained models for text generation

How do you use it?

The README strongly recommends running the notebooks through Google Colab, a free cloud service that provides a T4 GPU with 16GB of VRAM. All examples were built and tested on Colab, so it's the most stable environment. Other cloud providers should work too, but results may vary slightly depending on your operating system, Python version, and dependencies.

For those who prefer to run things locally, there's a .setup folder with a quick-start guide for installing all packages, and a .setup/conda folder with a complete environment setup guide including conda and PyTorch installation.

Bonus content

The authors also maintain a set of bonus visual guides that go deeper into topics beyond the book. These include illustrated guides to:

  • Mamba (a type of sequence model)
  • Quantization (compressing models to run faster)
  • Stable Diffusion (image generation)
  • Mixture of Experts (a model architecture technique)
  • Reasoning LLMs (models that think step-by-step)
  • DeepSeek-R1 (a specific reasoning model)

These are linked from the repository and are free to read.

Who is it for?

Based on the reviews quoted in the README, the book is aimed at people who want to understand LLMs deeply and practically — from beginners to those wanting to fine-tune their own models. Reviewers include Andrew Ng (founder of DeepLearning.AI), Nils Reimers (creator of sentence-transformers), Josh Starmer (StatQuest), Luis Serrano, and Leland McInnes (creator of UMAP and HDBSCAN).

Key facts

  • Authors: Jay Alammar and Maarten Grootendorst, both well-known AI educators
  • Publisher: O'Reilly (2024)
  • ISBN: 978-1098150969
  • Available at: Amazon, O'Reilly, Kindle, Barnes and Noble, Shroff Publishers (India), Goodreads
  • Format: 12 Jupyter notebooks, one per chapter, each with a one-click "Open in Colab" button
  • Cost: The code is free on GitHub; the book itself is a paid product

In short: if you want to learn LLMs by doing — with clear visuals and working code — this repository gives you all the examples from a highly regarded book, ready to run in your browser.

Related

  • Project
  • Project
  • Project
  • Project