By Dr. J. Paul Liu
"You don't need billion-dollar infrastructure to build powerful AI."
This book proves that one person with a laptop, curiosity, and $10/month can build production-quality language models that solve real problems. What started as lecture notes for a "Generative AI for Science" course evolved through real deploymentsβgeologists analyzing hazard data, legal researchers processing court documents, historians studying archaic texts, and businesses building multilingual support systems.
This is not an AI research paper. It's a builder's manual.
| Feature | Description |
|---|---|
| π±οΈ | Click, Run, Learn, Modify β All code runs in Google Colab. No installations, no expensive hardware. |
| π§ | Understanding Before Optimizing β Build GPT from scratch first, then learn to customize it. |
| π° | Real Constraints, Real Solutions β Costs in dollars, training time in hours, specific GPU models. |
| βοΈ | Honest About Trade-offs β When to use small models vs. APIs, local vs. cloud, scratch vs. fine-tuning. |
| π¬ | Battle-Tested β Validated by hundreds of practitioners from research to production. |
π FOUNDATIONS
βββ Chapter 1: Introduction
β βββ Why Small Language Models Matter, Use Cases, Hardware Requirements
β
βββ Chapter 2: Let's Build GPT from Scratch β±οΈ 60 min
β βββ Tokenization β Self-Attention β Transformer Blocks β Complete GPT
β
βββ Chapter 3: Quick Start β Fine-Tune Your First Model β±οΈ 30 min
βββ Google Colab β Load Model β Prepare Data β Fine-Tune β Test
π CORE SKILLS
βββ Chapter 4: Dataset Preparation
β βββ Tokenization Deep Dive, Data Sources, Cleaning, Quality Checks
β
βββ Chapter 5: Model Architecture & Configuration
β βββ Parameters, Four Key Decisions, Pre-configured Architectures
β
βββ Chapter 6: Training Loop & Monitoring
β βββ Production Training, Logging, Checkpointing, Troubleshooting
β
βββ Chapter 7: Evaluation & Benchmarks
βββ Perplexity, Metrics, Baselines, Generation Quality, Readiness Checks
π THE THREE-STAGE PIPELINE β±οΈ 20-30 hrs
βββ Chapter 8: Stage 1 β Pre-training from Scratch (MiniMind)
β βββ Data Prep β Tokenizer Training β Model Training β Analysis
β
βββ Chapter 9: Stage 2 β Supervised Fine-Tuning (SFT)
β βββ Task Performance, SFT Data, Training, Testing
β
βββ Chapter 10: Stage 3 β Direct Preference Optimization (DPO)
βββ Alignment, Preference Data, Safety, Production Deployment
π PRODUCTION & ETHICS β±οΈ 10-15 hrs
βββ Chapter 11: Production Deployment
β βββ Optimization, Quantization (INT8), Deployment Options, Cost Analysis
β
βββ Chapter 12: Complete Production Projects & Ethics
β βββ Project 1: Medical Q&A Assistant
β βββ Project 2: Code Documentation Generator
β βββ Project 3: Multilingual Customer Support
β βββ Ethics, Safety & Responsible AI
β
βββ Appendices
βββ A: Resource Calculator
βββ B: Quick Reference
βββ C: Dataset & Model Zoo
|
Scientists wanting AI that understands their domainβgeology, law, history, biologyβrunning on their own infrastructure. |
Engineers and developers building specialized AI systems without API costs or privacy concerns. |
Anyone who's wondered: "Can I build my own AI?" Yes, you can. This book shows you how. |
By completing this book, you will:
| Milestone | Description |
|---|---|
| β | Build a working GPT model from scratch and deeply understand transformers |
| β | Pre-train models on custom datasets (125Mβ350M parameters on consumer hardware) |
| β | Fine-tune using Supervised Fine-Tuning (SFT) |
| β | Align models with Direct Preference Optimization (DPO) |
| β | Deploy production systems with safety, monitoring, and ethics |
| β | Navigate the complete pipeline: Data β Architecture β Training β Evaluation β Deployment |
|
Total Cost: Under $50 to production expertise |
"The barrier between 'AI user' and 'AI builder' is thinner than you think. It's not talent or resourcesβit's understanding and practice."
"By Chapter 2, you'll have built a tiny but working GPT model. By Chapter 3, you'll understand why fine-tuning is revolutionary. By Chapter 10, you'll have trained a small but complete modern language model. By Chapter 12, you'll have deployed production systems."
"But tools are only as good as the wisdom with which we wield them. Build models that respect privacy, acknowledge limitations, and fail gracefully. Let the AI propose; let humans decide; let ethics guide."
β Dr. J. Paul Liu, Winter 2025
| Resource | Link |
|---|---|
| π PDF Edition | Leanpub |
| π¦ Paperback | Amazon |
| π» Code Downloads | rewriting.ai/bookcode/slm.php |
| π§ Contact | support@rewriting.ai |
@book{liu2025slm,
author = {Liu, J. Paul},
title = {How to Build and Fine-Tune a Small Language Model},
publisher = {Leanpub},
year = {2025},
pages = {479},
isbn = {979-8-2747-6622-7}
}Text citation: Liu, J. Paul. 2025. How to Build and Fine-Tune a Small Language Model. Leanpub. 479 p.
The future of AI isn't just in the hands of big tech. It's also in yours.
Now, let's build something remarkable together.
Β© 2025 Dr. J. Paul Liu. All rights reserved.
