large language models · neural networks · AI basics

How Large Language Models Actually Work

A large language model (LLM) is a program trained to predict the next piece of text in a sequence, given everything that came before it. That single mechanic — predict what comes next — is the basis for chatbots, writing assistants, coding tools, and search summaries that now feel like they understand what you're asking. Understanding how that prediction works, and what it doesn't guarantee, is the first step to using these tools well.

Training on Patterns, Not Facts

LLMs are built by showing a neural network enormous amounts of text — books, articles, code, forum posts — and repeatedly asking it to guess the next word. Each time it guesses wrong, the model's internal parameters (numbers controlling how it weighs information) are nudged slightly so it does better next time. Repeated across billions of examples, this process produces a model that has absorbed statistical patterns in language: which words tend to follow which, how arguments are typically structured, how code usually compiles.

Crucially, the model isn't storing a database of facts the way a search engine indexes pages. It's storing patterns of association. That distinction explains a lot of what LLMs are good and bad at.

From Tokens to Predictions

Text is broken into tokens — chunks that might be a whole word, part of a word, or a punctuation mark. The model doesn't see "cat"; it sees a number representing that token. Every token is converted into a vector (a long list of numbers) that captures something about its meaning and how it relates to other tokens, learned entirely from training data.

When you send a prompt, the model processes your tokens through many layers of a transformer — the architecture nearly all modern LLMs use — which lets every token "attend to" every other token in the input, weighing which earlier words matter most for predicting the next one. It then outputs a probability distribution over possible next tokens and picks one, adds it to the sequence, and repeats the process to generate the next, and the next, until the response is complete.

Why They Sound So Confident

Fluency comes from the training objective itself: the model has been optimised, above all else, to produce text that reads naturally. It has not been optimised to say "I don't know" when it's uncertain, unless it was specifically trained to behave that way. This is why LLMs can state incorrect information with the same confident tone as correct information — the sentence structure is equally fluent either way.

This tendency to generate plausible-sounding but incorrect content is often called hallucination. It isn't a bug in the traditional sense; it's a predictable consequence of a system built to continue text convincingly rather than to verify claims against a source of truth.

What They Get Wrong

  • Fabricated specifics — invented citations, statistics, or quotes that sound plausible but don't exist.
  • Outdated knowledge — most of what a model "knows" comes from a training cut-off date; it won't know about events afterwards unless given that information directly.
  • Arithmetic and logic slips — multi-step reasoning or precise calculation can go wrong, especially without being asked to show its work.
  • Inconsistency — the same question asked two different ways can produce two different answers, because the model is sampling from probabilities, not looking up a fixed fact.

Context Windows and Memory

A model's context window is the amount of text it can consider at once — your prompt, any earlier conversation, and its own response so far. Everything outside that window is invisible to the model; it doesn't "remember" previous sessions unless a product has been built to store and re-insert that information. Longer context windows let models work with bigger documents or longer conversations, but they don't change what the model fundamentally knows — only how much it can look at in a single pass.

Where the Technology Is Heading

Current research is focused on making models more reliable rather than simply larger: techniques like retrieval (letting a model look things up instead of relying purely on memorised patterns), tool use (letting a model call a calculator, run code, or query a database), and better training methods aimed at reducing hallucination and improving reasoning on multi-step problems.

None of this changes the underlying mechanic — next-token prediction is still the engine. But wrapping that engine with retrieval, tools, and verification steps is how today's AI products try to turn a fluent guesser into a genuinely useful assistant.

Sources

  1. Large language model — Wikipedia