The first thing you need to understand when it comes to LLMs is tokens. Consider the phrase "dogs like cats". It consists of three words and 14 characters, including the blank spaces in between. A tokenizer might represent this phrase as three tokens, but tokens don't necessarily correspond to words. They can represent entire words, parts of words, punctuation, or even whitespace. One token generally corresponds to approximately four characters, although this is only a rough rule of thumb.
You can experiment with a tokenizer to understand how a piece of text might be tokenized.
These tokens form a one-dimensional sequence called a token stream. When a user asks a question in an app like ChatGPT, what happens under the hood is that the question is broken down into tokens and added to the token stream. The response generated by the LLM is also written back into the stream—an alternating back-and-forth contribution by both the user and the model. In practice, the conversation can also contain system instructions, previous messages, and tool interactions.
The hard limit on how many tokens a model can process at once is called the context window.
Now, let's shift our focus to what a language model is, or perhaps what a language model does.
A language model estimates the probability of a token occurring within a longer sequence of tokens. When the user query is written into the token stream, the model probabilistically predicts the next token based on the statistical relationships it learned during training. It does this one token at a time.
It's worth noting that this happens sequentially. To generate the 100th token, the model must first generate tokens 1 through 99, feeding each newly generated token back into the context for the next prediction. This process is called inference.
This guide doesn't go much into inference, but it's good to know about at this point. Inference is the doing part. It's the moment a trained model starts working, using what it learned during training to predict and generate one token at a time.
But if inference is just the model running live in your chat box, where does its ability to make those next-token guesses actually come from?
That brings us to training.
Before a model can infer a single token, it has to learn the statistical patterns in its training data. There are two main stages of building an LLM: pre-training and post-training.
During pre-training, vast swaths of internet text and other data are processed and compressed into a neural network's weights, creating something like a probabilistic, lossy zip file of internet knowledge.
Because storing the raw internet directly inside a model is not how this works, the model instead learns statistical relationships, patterns, and representations from its training data, which allow it to predict the next token.
To digest all this data efficiently, the training set is split into smaller chunks called batches. A single training iteration consists of a forward and backward pass over a batch, after which the model updates its internal weights to reduce prediction errors.
Repeating this loop across millions of iterations and multiple full passes over the entire dataset, gradually refines these weights. The result is a pretrained model that has learned an enormous range of statistical patterns, but isn't necessarily a helpful assistant yet.
Pre-training is computationally expensive, can take months, and requires significant resources. The model's training data also determines its knowledge cutoff: the point beyond which it generally doesn't have reliable built-in knowledge of events. This doesn't mean it cannot access newer information; it means it needs additional context or external tools, such as web search, to do so.
Post-training (or fine-tuning) is what turns that raw text engine into a helpful tool.
Through human feedback, curated conversations, and other optimization techniques, developers further refine the model's behaviour—teaching it to answer your questions conversationally rather than simply completing raw text.
Techniques such as supervised fine-tuning and reinforcement learning help the model learn to follow instructions, respond helpfully, use tools, and behave according to desired constraints. The underlying model weights are further updated during this process.
How to work with LLMs
Understanding how LLMs work also helps us understand how to work with them effectively.
A few things become clear:
- Context matters. The quality of the response depends heavily on the information available to the model. Give it relevant context rather than expecting it to figure everything out.
- Inference isn't learning. A model doesn't automatically update its underlying weights every time you have a conversation with it.
- Be specific. Clear instructions and well-defined expectations make it easier for the model to produce useful results.
- Verify important outputs. LLMs can generate convincing answers that are factually incorrect. Treat their output as something to evaluate, not blindly trust.
The goal isn't to have an LLM do all the thinking. It's to use it as a tool to explore ideas, understand unfamiliar concepts, and work through problems.