Hands-On-Large-Language-Models README

The project's README from github.com/HandsOnLLM/Hands-On-Large-Language-Models. As one markdown file: README.md.

Hands-On Large Language Models

Welcome! In this repository you will find the code for all examples throughout the book Hands-On Large Language Models written by Jay Alammar and Maarten Grootendorst which we playfully dubbed:

"The Illustrated LLM Book"

Through the visually educational nature of this book and with almost 300 custom made figures, learn the practical tools and concepts you need to use Large Language Models today!


The book is available on:

Table of Contents

We advise to run all examples through Google Colab for the easiest setup. Google Colab allows you to use a T4 GPU with 16GB of VRAM for free. All examples were mainly built and tested using Google Colab, so it should be the most stable platform. However, any other cloud provider should work.

Chapter Notebook
Chapter 1: Introduction to Language Models Open In Colab
Chapter 2: Tokens and Embeddings Open In Colab
Chapter 3: Looking Inside Transformer LLMs Open In Colab
Chapter 4: Text Classification Open In Colab
Chapter 5: Text Clustering and Topic Modeling Open In Colab
Chapter 6: Prompt Engineering Open In Colab
Chapter 7: Advanced Text Generation Techniques and Tools Open In Colab
Chapter 8: Semantic Search and Retrieval-Augmented Generation Open In Colab
Chapter 9: Multimodal Large Language Models Open In Colab
Chapter 10: Creating Text Embedding Models Open In Colab
Chapter 11: Fine-tuning Representation Models for Classification Open In Colab
Chapter 12: Fine-tuning Generation Models Open In Colab

[!TIP] You can check the setup folder for a quick-start guide to install all packages locally and you can check the conda folder for a complete guide on how to setup your environment, including conda and PyTorch installation. Note that the depending on your OS, Python version, and dependencies your results might be slightly differ. However, they should this be similar to the examples in the book.

Reviews

"Jay and Maarten have continued their tradition of providing beautifully illustrated and insightful descriptions of complex topics in their new book. Bolstered with working code, timelines, and references to key papers, their book is a valuable resource for anyone looking to understand the main techniques behind how Large Language Models are built."

Andrew Ng - founder of DeepLearning.AI


"This is an exceptional guide to the world of language models and their practical applications in industry. Its highly-visual coverage of generative, representational, and retrieval applications of language models empowers readers to quickly understand, use, and refine LLMs. Highly recommended!"

Nils Reimers - Director of Machine Learning at Cohere | creator of sentence-transformers


"I can’t think of another book that is more important to read right now. On every single page, I learned something that is critical to success in this era of language models."

Josh Starmer - StatQuest


"If you’re looking to get up to speed in everything regarding LLMs, look no further! In this wonderful book, Jay and Maarten will take you from zero to expert in the history and latest advances in large language models. With very intuitive explanations, great real-life examples, clear illustrations, and comprehensive code labs, this book lifts the curtain on the complexities of transformer models, tokenizers, semantic search, RAG, and many other cutting-edge technologies. A must read for anyone interested in the latest AI technology!"

Luis Serrano, PhD - Founder and CEO of Serrano Academy


"Hands-On Large Language Models brings clarity and practical examples to cut through the hype of AI. It provides a wealth of great diagrams and visual aids to supplement the clear explanations. The worked examples and code make concrete what other books leave abstract. The book starts with simple introductory beginnings, and steadily builds in scope. By the final chapters, you will be fine-tuning and building your own large language models with confidence."

Leland McInnes - Researcher at the Tutte Institute for Mathematics and Computing | creator of UMAP and HDBSCAN


Bonus content!

We attempted to put as much information into the book without it being overwhelming. However, even with a 400-page book there is still much to discover!

We continue to create more guides that compliment the book and go more in-depth into new and exciting topics:

A Visual Guide to Mamba A Visual Guide to Quantization The Illustrated Stable Diffusion
A Visual Guide to Mixture of Experts A Visual Guide to Reasoning LLMs The Illustrated DeepSeek-R1

Citation

Please consider citing the book if you consider it useful for your research:

@book{hands-on-llms-book,
  author       = {Jay Alammar and Maarten Grootendorst},
  title        = {Hands-On Large Language Models},
  publisher    = {O'Reilly},
  year         = {2024},
  isbn         = {978-1098150969},
  url          = {https://www.oreilly.com/library/view/hands-on-large-language/9781098150952/},
  github       = {https://github.com/HandsOnLLM/Hands-On-Large-Language-Models}
}

Hands-On-Large-Language-Models (HandsOnLLM/Hands-On-Large-Language-Models)

Searching Database…

这是什么?这是 O'Reilly 图书《Hands-On Large Language Models》的官方代码仓库,也被称为 Illustrated LLM Book(图解大语言模型之书)。书中 12 章的每一章都对应一个 Jupyter 笔记本。
这是书本身,还是配套的代码?这是配套代码,不是书:每章一个笔记本。完整内容是一本付费书,通过 Amazon、O'Reilly、Kindle 和 Barnes & Noble 出售。
怎么运行这些笔记本?作者推荐使用 Google Colab:可以免费获得一块 16GB 显存的 T4 GPU,所有示例主要都是在那里构建和测试的,因此它也是最稳定的平台。
我可以在自己的电脑上运行吗?可以:setup 文件夹里有一份快速入门指南,教你如何在本地安装所有依赖包;conda 文件夹则完整演示了如何用 conda 和 PyTorch 搭建环境。其他云服务商应该也能用。
我的运行结果会和书里的一模一样吗?不一定:根据你的操作系统、Python 版本和依赖包的不同,结果可能会略有差异,不过应该和书中的示例基本一致。
我是 LLM 新手,该从哪里开始?从头开始:这本书以语言模型的入门章节开篇,难度循序渐进,到最后几章你就能微调自己的模型了。
为什么叫 Illustrated LLM Book?这本书采用视觉化教学:书中包含近 300 幅专门绘制的插图,配合实战代码讲解语言模型的工作原理。
使用这个仓库必须买书吗?这里的笔记本和附加指南在 Apache-2.0 许可证下免费开放,但完整内容是付费书,可以在 Amazon、O'Reilly、Kindle 和 Barnes & Noble 购买。
这本书附带哪些额外内容?作者还发布了超出这 12 章范围的额外图解指南,主题包括:Mamba、量化、混合专家模型(MoE)、推理 LLM、Stable Diffusion 和 DeepSeek-R1。
都有谁推荐过这本书?Andrew Ng、Nils Reimers(sentence-transformers 的作者)、Josh Starmer(StatQuest)、Luis Serrano,以及 UMAP 和 HDBSCAN 的作者 Leland McInnes,都在 README 里给出了热情的推荐语。
Creator
HandsOnLLM
Size
12.9 MB
Stars
29.7K
Updated
CommitApr 24
Age
2y
Commits · 90 Days