Ten modules, mechanism first
Each module builds on the one before it: tokens and attention explain how a model processes text at all; scale, pretraining, and alignment explain how it gets trained into something useful; in-context learning, retrieval, and tools explain how it's actually used; evaluation and deployment explain how to trust and run one in practice.
From words to numbers
Tokenization and embeddings
A model computes over numbers, not words, so the first step in any LLM pipeline is splitting text into tokens — chunks that are sometimes whole words, sometimes word pieces, sometimes single characters, decided during training by what split lets the vocabulary cover the training text efficiently.
Each token then maps to a vector of numbers called an embedding, learned during training so that tokens used in similar contexts end up with similar vectors. Everything downstream — attention, prediction, generation — operates on these vectors, never on the original text directly.
The transformer and attention
Deciding which earlier words matter right now
The mechanism that made modern LLMs practical is self-attention: for each token, the model computes how much every other token in the input should influence it, and weighs them accordingly. A pronoun can "attend" strongly to the noun it refers to several sentences back, regardless of the distance between them in the text.
This replaced older architectures that processed text strictly in order and struggled to connect distant words. Attention computes those connections directly, and does it for every token in parallel rather than one at a time — which is also most of the reason transformers scale to run efficiently on modern hardware.
Why scale changes behavior
Bigger isn't just "more of the same"
Model size and training data volume have historically followed fairly predictable scaling relationships — more compute and data reliably improve next-token prediction accuracy in a smooth, measurable way.
What's more debated is whether some capabilities appear abruptly at scale rather than improving smoothly — so-called emergent abilities. Some researchers argue certain skills genuinely appear only past a size threshold; others argue the abruptness is partly an artifact of how a capability gets measured rather than a real discontinuity in the model. Worth knowing this is an open research question, not a settled one.
Pretraining at scale
One objective, an enormous amount of text
Pretraining trains a model on one deceptively simple task — predict the next token, over and over, across a training set that can run to trillions of tokens of text. Nothing in this stage is annotated or curated for a specific downstream use; the model just gets very good at anticipating what comes next.
That single objective, run at enormous scale, is what produces a model that can also translate, summarize, and answer questions — abilities nobody explicitly trained it for, that emerged as side effects of getting extremely good at prediction across an enormous, varied corpus.
From predictor to assistant
Instruction tuning and RLHF
A raw pretrained model predicts plausible continuations — which isn't the same as following an instruction or being a helpful conversational partner. Instruction tuning fine-tunes the model on examples that pair an instruction with the kind of response that's actually wanted.
Reinforcement learning from human feedback goes a step further: people rank different model responses, and that ranking data trains the model to prefer outputs people rate more highly. This is the stage that turns a raw next-token predictor into something that behaves like a cooperative assistant.
In-context learning
Learning a task from the prompt alone
A trained LLM's weights are frozen when you use it — nothing updates while you talk to it. And yet a few examples placed directly in the prompt can teach it a new task pattern it never saw during training, purely from context.
This is genuinely different from traditional machine learning, where teaching a model something new means retraining it. In-context learning happens entirely within a single conversation and vanishes the moment that conversation ends — it's a capability of how the model processes its current input, not a change to what it permanently knows.
Grounding with retrieval
Answering from documents, not just memorized weights
Everything a pretrained model "knows" is compressed into its weights, frozen at training time — it has no way to look anything up. Retrieval augmentation fixes that by searching a document store for relevant passages and inserting them into the prompt before the model answers.
This grounds the answer in a specific, checkable source instead of purely what the model happened to memorize, and it lets a system answer from private or newly updated content the model was never trained on — without retraining anything.
Tool use
Acting, not just answering
Trained to output text, an LLM can be given tools — functions it can call for a calculation, a search, a database lookup — and trained to recognize when calling one is the right response instead of generating an answer directly.
This is the mechanism underneath what gets called an AI agent: the model isn't doing anything fundamentally different from ordinary generation, it's just generating a structured tool call instead of prose, and the result of that call gets fed back in as new context for the next step.
Evaluating an LLM
Benchmarks, and their limits
Standard benchmarks test a model against a fixed set of questions with known answers, which works well for narrow, checkable skills and less well for open-ended quality, where there often isn't one right answer to score against.
A specific, growing problem is contamination: if benchmark questions leaked into a model's training data, a high score reflects memorization rather than the capability the benchmark was meant to measure. Combining benchmarks with human evaluation, and refreshing test sets over time, are the main defenses against that.
Running LLMs in production
The cost and latency tradeoffs behind every response
A large model is expensive to run: every response requires a full forward pass through billions of parameters, which costs real compute time and money per request — a very different economics than traditional software, where running the same code twice costs almost nothing extra.
Quantization (representing the model's numbers with less precision) and distillation (training a smaller model to mimic a larger one) are the two main levers for shrinking that cost, generally trading some capability for speed and lower expense. Where that tradeoff is worth making depends entirely on what the specific application actually needs.
Common questions
What is a token in a large language model?
A chunk of text — sometimes a whole word, sometimes a word piece, sometimes a single character — that the model actually computes over. Text gets split into tokens, each token maps to a vector of numbers called an embedding, and every step of the model from there operates on those vectors, not the original text.
What does attention actually do in a transformer?
For each token, it computes how much every other token in the input should influence it and weighs them accordingly — letting the model connect words that are far apart in the text directly, computed in parallel across every token at once rather than one at a time in sequence.
What's the difference between pretraining and instruction tuning?
Pretraining trains a model on one objective, next-token prediction, across an enormous volume of raw text. Instruction tuning and RLHF come after, fine-tuning that raw predictor on examples of instructions paired with the kind of response that's actually wanted, which is what turns it into something that behaves like a cooperative assistant.
Why does an LLM need retrieval augmentation if it already has a lot of knowledge?
Everything an LLM knows is frozen into its weights at training time — it can't look anything up on its own. Retrieval augmentation searches a document store for relevant passages and inserts them into the prompt, letting the model answer from specific, checkable, and up-to-date sources instead of only what it memorized.