Skip to content

A free, hands-on book for business students

Teach Your Computer to Write

Build and Train an LLM from Zero

You use chatbots every week. In this book you build the kind of model that sits inside one, one short step at a time, until it is a machine you understand well enough to doubt. The model is small enough to read from the first line to the last, and all you need is a web browser or your own computer. You do not need a technical background.

No GPU. No cloud. No magic.

Start reading Run a chapter in your browser

The cover of the book

  • 17 short chapters, one idea each
  • 824,832 numbers inside the model you train
  • 20 to 30 minutes of training on an ordinary laptop
  • Free to read online, as a PDF or as an EPUB

"Any sufficiently advanced technology is indistinguishable from magic." (Arthur C. Clarke)

"Until you build it yourself, then it's just a lot of matrix multiplications." (This book)

What You Will Be Able to Do

  • Explain how a chatbot answers. You can say in plain words how it turns a question into an answer, one predicted piece at a time.
  • Know when to doubt an answer. You know why a model can state something false in confident prose, and what to check before you trust it.
  • Train a model yourself. You have trained a working language model on your own laptop and watched it write text nobody wrote before.

Who This Book Is For

  • Business students. You use AI tools every week and want to know what is inside them. Every idea comes with a picture, an everyday comparison and an example from work.
  • The instructors who teach them. Every chapter has a lecture deck timed for one class, a 15-minute assignment and a notebook that runs in a browser. See Teach With This Book.
  • Managers and analysts. You buy, approve or supervise AI tools. After this book you can ask a vendor better questions, because you have built the thing they are selling.

You do not need calculus, linear algebra or any machine learning background. Every script in the book is already written. You run it, read what each line does, and change one number at a time. If you have seen a little Python, the code will read faster.

What You Will Build

A small language model that writes in the style of Shakespeare. It has the same design as the models behind today's chatbots, made small enough to read. It holds 824,832 adjustable numbers, where a commercial model has billions. After 20 to 30 minutes of training on a laptop with no graphics card, it writes this:

Terminal
ROMEO:
Praviour soul to shall that that are the and not,

The shape of Shakespeare is there and the sense is not, because the model learned which characters tend to follow which and nothing about what the words mean. Once you have watched that happen on your own screen, you read a polished answer from a large model differently.

The book used to be called Building an LLM from Zero. The text, the code and the address are the same.

How Every Chapter Works

Every chapter has the same parts in the same order, and every part has its own look. You always know what you are reading and what to do with it. The lecture slides use the same colors for the same parts. Across the 17 chapters that comes to 69 figures, 17 lecture decks, 17 browser notebooks and 17 assignments.

  • The map Where the chapter sits in the whole machine, so you never lose your place.
  • Words to know The chapter's new terms, each in one plain sentence.
  • The idea One idea, with a picture and an everyday comparison, before any code.
  • The code A few numbered lines in an editor window, explained line by line. The full script is already written for you to run.
  • The run What the computer printed when the code ran, copied from a real run.
  • Try it One small change to make yourself, and what happens when you do.
  • In business What the idea means at work.
  • Watch out The mistake most people make, and how to avoid it.
  • Summary The chapter in four or five lines.
  • Assignment Fifteen minutes: run it, change one number, say what you saw.

Before you start, note that the source files are numbered one lower than the chapters. Chapter 4, for example, runs src/ch03_tokenizer.py.

Three Ways to Follow Along

  • Read it. Every chapter shows the code and what it printed, so the book works on a phone or on paper.
  • Run it in your browser. Each chapter opens as a notebook in Google Colab, with the code ready to run. There is nothing to install.
  • Build it on your laptop. Chapter 1 sets up Python step by step. Training needs no graphics card and no cloud account.

The Big Picture

The full journey from text to trained model The big picture: how text becomes a trained model, and new text.

A language model looks complex, but the path through it is a straight line:

  1. Text: We start with plain words (or characters).
  2. Tokens: We chop the text into small pieces.
  3. Embeddings: We turn those pieces into lists of numbers that capture meaning.
  4. Attention: The tokens look at each other to understand context.
  5. Transformer Blocks: The model thinks deeper and deeper.
  6. Next-Token Scores: It guesses what comes next.
  7. Training: We correct its guesses so it learns.
  8. Generation: We use the trained model to write new text.

Contents

Roadmap of the three modules The three modules of this book.

Preface: Why This Book Exists ยท Introduction: Five Phases, One Loop

Module 1: Foundations

Set up, learn what a language model does, and turn text into numbers it can use.

Chapter Title Key Idea
Ch 01 Setting Up Your Environment Python, Git, PyTorch
Ch 02 What Is an LLM? Next-token prediction
Ch 03 Tensors and PyTorch The "smart array"
Ch 04 Tokenization Text to numbers
Ch 05 Embeddings Numbers to meaning

Module 2: Building the Model

Build the parts of a GPT model, from attention to the full architecture.

Chapter Title Key Idea
Ch 06 Self-Attention (Single Head) Tokens talking to each other
Ch 07 Multi-Head Attention Multiple perspectives
Ch 08 Feed-Forward and Norms Thinking it over
Ch 09 The Transformer Block One complete unit
Ch 10 The Full GPT Architecture The whole stack
Ch 11 Causal Language Modeling No cheating!

Module 3: Training and Generation

Teach the model to write, then use it to generate new text.

Chapter Title Key Idea
Ch 12 Dataset and DataLoader Loading the dishwasher
Ch 13 The Training Loop Repeat until smart
Ch 14 Checkpointing Saving your game
Ch 15 Greedy and Sampling Safe vs. risky
Ch 16 Temperature and Top-k The creativity dial
Ch 17 Putting It All Together The full pipeline

Other Ways to Read

The book is written to be read a chapter at a time, and that is what the contents on the left are for. If a chapter at a time is not what you want:

Format Good for
The whole book on one page Searching the whole text at once, or printing
PDF Reading offline, or on paper
EPUB A Kindle, Kobo or Apple Books reader
Notebooks Running a chapter in Colab or Jupyter, nothing to install
Lecture slides Teaching a chapter, or paging through it in ten minutes

About the Author

Truong (Jack) Luu is an Assistant Professor of Information Systems and Analytics at the McCoy College of Business, Texas State University, and holds a Ph.D. in Information Systems from the University of Cincinnati (2026). His research examines privacy and cybersecurity threats in the AI era, including the impact of generative AI on cybercrime. He teaches generative AI development for business and the training and fine-tuning of large language models, including the graduate course ISAN5365 Developing Generative AI for Business (from Spring 2027). He developed and maintains AI Sec Watch, an open-access, real-time AI security monitoring tool serving over 8,000 monthly users (as of September 2026). More at jackluu.io.

Found a Mistake?

This book is read online and corrected in place, so a mistake found today can be fixed today. If a number looks wrong, a script will not run, or an explanation does not land, please open an issue. Corrections to the text are as welcome as bug reports about the code.

First draft: December 17, 2025. Last updated: October 2026.

Start with the Introduction. It is a short read and needs no computer.

Start reading