Tokens, probabilities, temperature, training, embeddings, context windows, prompts, and hallucinations — how large language models really work, learned by building a tiny one yourself.
Everyone is using AI assistants, and almost everyone has the same questions. Is it really thinking? Why does it sometimes make things up with total confidence? Why does the same question give a different answer each time? Why does it forget what I said ten minutes ago? Why does it cost money per word? If you build software in the AI era, you will be asked these questions by your users, your teammates, and your students, so it helps to know the real answers instead of guessing.
This series explains how a large language model (LLM) works, in plain language and with code instead of math. You will see that the core idea is surprisingly small: a model reads text, predicts the next piece, adds it, and repeats. Everything else (the clever answers, the long essays, the code it writes) grows out of doing that one thing at enormous scale. You will learn what tokens are and why they decide your bill, how a model turns scores into probabilities, what "temperature" really does, how a model learns from text, how words become numbers (embeddings), why a model has a limited memory (the context window), how prompts and roles steer it, and why hallucinations happen and what you can do about them.
You won't just read about it. Across the series you build llmlab,
a small JavaScript toolkit that runs on your own computer: a toy
tokenizer, a tiny language model that writes text, a sampler with
temperature, a training loop that you can watch learn, a word-similarity
search, a conversation memory manager, a prompt builder, and a grounded
answer checker. Real LLMs are millions of times bigger, but they follow
the same ideas, and a model you built yourself is the best way to
understand one you did not.
You need to be comfortable with the basics of JavaScript — variables,
functions, arrays, objects, loops, and import/export — from
JavaScript & TypeScript
Fundamentals, and with
the terminal from Command Line Basics.
The Probability
Basics chapter of
Math for Programmers is a helpful warm-up for chapters 3 and 4. You need
Node.js (the LTS version) and a code editor such
as Visual Studio Code. No API keys, no
accounts, and nothing costs money. The next series, Build a Chatbot with
an LLM API, is where you call a real hosted model.
Every chapter ends with a Quick Review: Common Questions section: short, honest answers to the questions beginners most often ask about that chapter's topic. Try answering each one yourself first, then check your answer. If you can explain it in your own words, you understood the chapter.