# Teach Your Computer to Write: Build and Train an LLM from Zero Teach Your Computer to Write is a free, hands-on book by Truong (Jack) Luu, written for business students with no technical background and for the instructors who teach them. The reader builds a GPT-style large language model from scratch in Python and PyTorch: a character-level model with 824,832 parameters, trained on the Tiny Shakespeare dataset on an ordinary computer, with no GPU. Every script is already written, every chapter has a browser notebook, a lecture deck and a 15-minute assignment, and every idea is tied to a business use. The book spans 17 chapters across 3 modules. It was first published as "Building an LLM from Zero". ## Module 1: Foundations: From Text to Numbers - [Setting Up Your Environment](https://jackluu.io/book/section-1-foundations/ch01-environment-setup/) - Chapter 1 shows how to set up your environment to build a GPT from scratch in Python. Install PyTorch and download the Tiny Shakespeare dataset. - [What Is an LLM?](https://jackluu.io/book/section-1-foundations/ch02-what-is-an-llm/) - Chapter 2 explains how large language models work for beginners. Learn about next-token prediction, autoregressive generation, and language model concepts. - [Tensors and PyTorch](https://jackluu.io/book/section-1-foundations/ch03-tensors-and-pytorch/) - Chapter 3 is a PyTorch transformer tutorial for beginners. Learn about tensors, matrix multiplication, and PyTorch basics to build an LLM from scratch. - [Tokenization](https://jackluu.io/book/section-1-foundations/ch04-tokenization/) - Chapter 4 tokenization explained. Build a character-level language model tokenizer in Python to process the Tiny Shakespeare dataset for a GPT model. - [Embeddings](https://jackluu.io/book/section-1-foundations/ch05-embeddings/) - Chapter 5 embeddings explained. Learn how neural networks map tokens to vectors of meaning by building embeddings from scratch in PyTorch. ## Module 2: Building the Model - [Self-Attention (Single Head)](https://jackluu.io/book/section-2-attention/ch06-self-attention/) - Chapter 6 self-attention explained. Learn how tokens look at each other using queries, keys, and values. Build a causal mask for an LLM from scratch. - [Multi-Head Attention](https://jackluu.io/book/section-2-attention/ch07-multi-head-attention/) - Chapter 7 multi-head attention explained. Discover how multiple heads process different perspectives in a PyTorch transformer tutorial for beginners. - [Feed-Forward and Norms](https://jackluu.io/book/section-2-attention/ch08-feedforward-and-norms/) - Chapter 8 explains feed-forward networks and layer normalization. Build these components in Python to process context found by multi-head attention. - [The Transformer Block](https://jackluu.io/book/section-3-the-transformer/ch09-transformer-block/) - Chapter 9 the transformer block explained for business readers and beginners. Combine multi-head attention and feed-forward layers in PyTorch. - [The Full GPT Architecture](https://jackluu.io/book/section-3-the-transformer/ch10-full-gpt-architecture/) - Chapter 10 build a GPT from scratch in Python. Combine transformer blocks into a full architecture that maps embeddings to next-token probabilities. - [Causal Language Modeling](https://jackluu.io/book/section-3-the-transformer/ch11-causal-language-modeling/) - Chapter 11 causal language modeling explained. Build logic to ensure the language model only uses past context when predicting the next token. ## Module 3: Training and Generation - [Dataset and DataLoader](https://jackluu.io/book/section-4-training/ch12-dataset-and-dataloader/) - Chapter 12 data loader tutorial. Learn to train a language model on a CPU without a GPU by building a PyTorch dataset for the Tiny Shakespeare text. - [The Training Loop](https://jackluu.io/book/section-4-training/ch13-training-loop/) - Chapter 13 PyTorch training loop tutorial for beginners. Learn how to train a large language model from scratch in Python to predict the next token. - [Checkpointing](https://jackluu.io/book/section-4-training/ch14-checkpointing/) - Chapter 14 checkpointing explained. Save and load large language models in PyTorch. Ensure you don't lose progress when you build an LLM from scratch. - [Greedy and Sampling](https://jackluu.io/book/section-5-generation/ch15-greedy-and-sampling/) - Chapter 15 text generation explained. Learn to generate text with greedy decoding and sampling in a character-level language model using PyTorch. - [Temperature and Top-k](https://jackluu.io/book/section-5-generation/ch16-temperature-and-topk/) - Chapter 16 text generation with temperature and top-k sampling. Adjust large language model creativity in a PyTorch transformer tutorial for beginners. - [Putting It All Together](https://jackluu.io/book/section-5-generation/ch17-putting-it-all-together/) - Chapter 17 build an LLM from scratch. The full pipeline to build a GPT from scratch in Python, train a language model on a CPU, and generate text. ## 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](https://aisecwatch.com), an open-access, real-time AI security monitoring tool serving over 8,000 monthly users (as of September 2026). More at [jackluu.io](https://jackluu.io). ## For instructors - [Teach With This Book](https://jackluu.io/book/teach/) - A class-by-class plan: one chapter per 75-minute class, each with a lecture deck, a 15-minute assignment and a browser notebook. It also lists what a student can do after each class and gives one rubric for every assignment. - [How This Book Is Checked](https://jackluu.io/book/checked/) - Where the book's printed output, figures and references come from, and what is tested before a change is published. - [Lecture Slides](https://jackluu.io/book/slides/) - One deck per chapter, as PDF. - [Glossary](https://jackluu.io/book/glossary/) - Every term the book defines, in plain words. ## Links - [Read online](https://jackluu.io/book/) - [PDF version](https://jackluu.io/files/teach-your-computer-to-write.pdf) - [EPUB version](https://jackluu.io/files/teach-your-computer-to-write.epub) - [Full text for language models](https://jackluu.io/book/llms-full.txt) - [Source code and chapter notebooks](https://github.com/jackluucoding/build-llm-from-zero) ## License Book text and lecture decks: CC BY-NC-ND 4.0. Code and notebooks: MIT. Exercises: CC BY-NC 4.0.