Introduction to Large Language Models and the Book
The model reads the previous outputs, produces a next output, and that output is appended to the record of previous outputs.
A Plan for Building from Scratch
This section of the book is short. On page 23 it introduces a plan for building a large language model, an LLM, from scratch. The phrase from scratch is the key to reading it. The book does not stop at describing a finished model, and it does not only show how to call a model through an existing service. It sets out to take the learner through the construction itself, starting from basic pieces and working toward a model the learner has built.
Reading a plan well means asking what it commits the reader to. Here the commitment is to building rather than only observing. A learner who reads the plan as a promise of construction will know what to look for in the chapters that follow: concrete parts of a model assembled in order, with each part understood as it is added.
What do you think happens?
Does this section of the book show you a finished, working LLM?
Reveal answer
No, this section only states the plan for building one
The source for this section documents only the existence of the plan. The individual steps belong to later material, and the built model is the outcome the rest of the book is set up to produce.
Tracing the Learner's Three States
A useful way to read this section is to follow the state of the learner's understanding as the chapter proceeds. The learner moves through three states. Each state is distinct, and keeping them apart prevents a common confusion between a plan and the thing the plan produces.
- 1State one: the learner has an idea of what a large language model is.
- 2State two: the learner has the plan. The book intends to build such a model step by step, from scratch, rather than only describe one. This is the only state the source actually documents.
- 3State three: the learner has a working model built from the basic pieces. Moving from state two to state three is the work the rest of the book is set up to do.
Where the Transformer Sits
A transformer architecture is the neural network design used in large language models. Attention mechanisms are a key component inside that design.
The word architecture here refers to how the parts of the network are organized. It does not refer to a single formula. For a beginner, the two facts that matter are these: transformer architectures are the design used in large language models, and attention mechanisms are a key component inside them. Attention is not a separate system bolted onto a language model. It is one of the central parts of the transformer design.
Attention and Long-Range Dependencies
Language arrives as a sequence. A sentence is a run of words, and the meaning of a later word often depends on something said much earlier. The source material flags the modeling of long sequences as a real problem that has to be handled deliberately rather than ignored. Attention is the family of mechanisms that addresses this.
The key word is focus. A model that reads a sequence does not need to treat every earlier position as equally important for every decision it makes. Attention lets the model give more weight to some parts of the input than to others. The source material states the purpose directly: attention mechanisms handle long-range dependencies in input sequences, meaning relationships between parts of the input that are far apart from each other.
Read the flow from left to right. The input sequence enters the attention mechanism, which scores the parts of the sequence against one another. Those scores produce a weighted focus, where some parts count for more than others, and that focus shapes what the model produces. This describes the flow of information. The source material treats the detailed computation of these weights as a later topic.
Self-Attention Versus Causal Attention
Self-attention is the form of attention in which the sequence is compared against itself. Each position in the input can look at other positions in that same input and decide how much they matter. This is the mechanism connected to the long-sequence problem: because any position can draw on any other position, dependencies spanning a long stretch of text need not be lost along the way.
Self-attention alone lets a position look at any other position. Causal attention adds a restriction. The source material says causal attention is used to prevent the model from attending to future tokens. A token may draw on what came before it, but not on what has not yet been produced. This restriction matters most when the model generates text, because at generation time the future has not been written yet.
Which tokens can each position see under causal attention?
Consider the four-token sequence The, cat, sat, down. Under causal attention, which tokens can each position draw on?
- 1Position 1
The token The has no earlier tokens. It can draw only on itself.
- 2Position 2
The token cat can draw on The, which came before it, and on itself. It cannot draw on sat or down, which have not been produced yet.
- 3Position 3
The token sat can draw on The, cat, and itself. The later token down is blocked.
- 4Position 4
The token down can draw on every earlier token and itself. Nothing comes after it in this sequence, so no future token is blocked for it.
Each position sees only itself and the tokens before it. Under plain self-attention, every position could instead see all four tokens.
What do you think happens?
While generating the word after sat, can the token down influence what the model produces next?
Reveal answer
No, because causal attention blocks future tokens
At generation time down has not been produced yet. Causal attention prevents the model from attending to it, so only earlier tokens can shape the next output.
Autoregressive Generation as a Loop
The source material states that autoregressive models are used in large language models. Their defining feature is a feedback loop. The model produces an output, that output becomes part of what the model conditions on, and the model then produces the next output. Each new output is therefore shaped by the outputs that came before it.
Follow the loop around. The model reads the previous outputs, produces a next output, and that output is appended to the record of previous outputs. The cycle then repeats. The return arrow is the essential part. Without it, the model would produce one output from the input and stop. Autoregressive generation is what turns a single prediction into an extended sequence of text.
Generating a short phrase one token at a time
Starting from the prompt The cat, show how an autoregressive model would extend the text.
- 1Step 1
The model reads The cat and produces the next token, sat.
- 2Step 2
sat is appended, so the record is now The cat sat. The model conditions on all three tokens and produces the next token, down.
- 3Step 3
down is appended, giving The cat sat down. The cycle continues as long as the model keeps producing outputs.
The text grows one token at a time, and every new token depends on the tokens generated before it.
Datasets, Pre-Training, and Fine-Tuning
Large language models are trained using large datasets and various training methods. The source material states as an important fact that large language models require large datasets for training. Before training can happen, the data itself has to be made usable, and the source material identifies this step as crucial.
The scale is substantial. The source's reference list includes a resource titled Dolma: An Open Corpus of Three Trillion Tokens for LLM Pretraining Research, which gives a sense of how large the text collections used for pretraining can be. The word pretraining points to the broader pattern: a large model is first trained on a large general dataset, and it can then be adapted further.
A pre-trained model has already learned from a large dataset. Fine-tuning starts from that model and adapts it to a narrower purpose. The source material's index contains a clear case: fine-tuning for classification, which includes using an LLM as a spam classifier. The general model is the starting point, and the fine-tuned model is the specialized result.
Mistakes Readers Make with This Introduction
Common mistake Treating the plan as the finished model
What it looks likeExpecting this section to contain a trained model that can already answer questions.
Why it failsThe source documents only the existence of the plan. The built model is the outcome of the later work.
Do this insteadKeep the three states distinct: idea, plan, and built model.
Common mistake Assuming attention is a separate system added to the model
What it looks likeThinking of attention as an optional module attached to an unrelated network.
Why it failsThe source says attention is a key component inside the transformer architecture.
Do this insteadPlace attention inside the transformer design when reading later sections.
Common mistake Using the same meaning for self-attention and causal attention
What it looks likeAssuming that during generation a token can see the tokens that come after it.
Why it failsSelf-attention lets positions relate to each other freely, while causal attention blocks future tokens.
Do this insteadRemember that causal attention adds a restriction on top of self-attention.
Common mistake Believing generation produces a whole sequence at once
What it looks likeThinking the model writes The cat sat down in a single unbroken step.
Why it failsAutoregressive models produce one output and feed it back to produce the next.
Do this insteadDescribe generation as a loop in which each output is appended and conditioned on.
Checking Your Reading of the Plan
Using only the ideas in this article, explain in your own words why the plan for building an LLM from scratch is not the same thing as a finished LLM. Then name one property of causal attention that distinguishes it from plain self-attention.
Hints
- Recall the three states: idea, plan, and built model.
- Think about which positions a token may draw on during generation.
Key Takeaways
- The book's introductory section presents a plan for building an LLM from scratch, meaning the learner is taken through constructing the model rather than only describing or calling one. The specific stages belong to later material.
- A transformer architecture is the neural network design used in large language models, and attention mechanisms are a key component inside it. Attention helps a model focus on parts of the input and handle long-range dependencies.
- Self-attention relates positions within a sequence, while causal attention restricts each token to previous tokens and blocks future ones, which matters during generation.
- Autoregressive models generate output based on previous outputs, forming a feedback loop in which each new token is appended and used to produce the next one.
- Large language models require large datasets, which must be prepared before training. A model pre-trained on a large general dataset can then be fine-tuned for a narrower purpose such as spam classification.