NextTechBlog

Technology, explained properly.

Rows of servers in a data centre, the hardware that trains large language models

How Large Language Models Actually Work, Step by Step

In 2017, eight researchers at Google published a 15-page paper describing a neural network they trained on eight NVIDIA P100 GPUs. The larger version took three and a half days to train. It was built to translate English into German, and it beat the previous best system by more than two BLEU points, a standard translation score. The paper was called Attention Is All You Need, and the architecture it introduced, the transformer, is still the foundation of every major AI chatbot you have used.

Nine years later, the same basic design runs models that hold a million tokens of context, write working code, and pause to “think” before answering. The scale has changed enormously. The core mechanism has not changed nearly as much as you might assume.

This article walks through that mechanism end to end: how text becomes numbers, what attention actually computes, what happens during training versus when you type a message, why these systems make things up, and what the reasoning models released since late 2024 genuinely changed. No math background required, but no hand-waving either.

Step one: your sentence becomes a list of numbers

A neural network cannot read letters. It processes numbers. So the first thing that happens to your message is tokenization: chopping the text into chunks called tokens and looking up an ID number for each one.

Tokens are not words. They are frequent character sequences discovered by an algorithm called byte pair encoding, which starts with individual bytes and repeatedly merges the most common adjacent pairs until it has a vocabulary of the desired size. OpenAI’s tiktoken library implements this, and its documentation notes that a word like “encoding” typically splits into “encod” and “ing” rather than into single letters.

OpenAI’s own guidance is that one token averages about four characters, or roughly three quarters of a word in English. Capitalization and spacing matter: “red”, “Red”, and ” red” with a leading space can all be different tokens with different IDs.

This detail explains a whole class of odd behavior. When a model miscounts the letters in a word, it is not being stupid about spelling. It never saw the letters. It saw two or three opaque chunk IDs, and letter-level information has to be reconstructed indirectly from training data.

From IDs to embeddings

Token IDs are arbitrary. Token 4,391 is not meaningfully larger than token 4,390. So the model immediately converts each ID into an embedding: a long list of decimal numbers, typically several hundred to a few thousand values, that positions the token in a high-dimensional space.

Google’s machine learning course describes an embedding as a vector representation in embedding space, where distance between two items can be computed mathematically and read as a measure of similarity. Word embeddings commonly use somewhere between 256 and 1,024 dimensions.

These coordinates are learned, not assigned. Nobody decided that the vector for “Paris” should sit near the vector for “France”. That geometry emerged because the two tokens appeared in similar contexts across the training data, and the training process nudged their vectors together.

Attention: the actual idea

Here is the problem the transformer solved. In a sentence like “the trophy did not fit in the suitcase because it was too large”, the word “it” refers to the trophy. Earlier architectures processed text left to right and had to squeeze all prior context into a single fixed summary, which made long-range links like this fragile.

Attention takes a different approach. Every token gets to look at every other token directly and decide how much each one matters.

Mechanically, each token’s embedding is projected into three vectors: a query (what am I looking for), a key (what do I offer), and a value (what I actually contribute). The model compares every query against every key with a dot product, scales the result, runs it through a softmax so the weights sum to one, and uses those weights to blend the value vectors. The original paper writes this as Attention(Q, K, V) = softmax(QKᵀ / √d_k)V, and calls it scaled dot-product attention.

The result is that “it” ends up carrying a representation heavily mixed with “trophy”. Context is not summarized and passed along. It is gathered fresh at every layer.

The 2017 base model ran eight attention heads in parallel, each with 64 dimensions, on top of a model width of 512. Multiple heads let the network track several kinds of relationship at once: one head might follow grammatical subjects while another tracks which entity a pronoun refers to.

Stacking blocks

One attention layer is not enough. A transformer block pairs attention with a small feed-forward network that processes each position independently, plus normalization and residual connections that let information skip past layers.

The original base model stacked six such blocks in the encoder and six in the decoder, with a feed-forward inner dimension of 2,048. Modern frontier models are the same recipe scaled up by orders of magnitude in depth, width, and vocabulary, with efficiency modifications layered on. The 2017 paper reported training costs of roughly 3.3 x 10^18 floating-point operations for the base model. Frontier training runs today are many millions of times larger.

Early layers tend to handle surface patterns. Deeper layers assemble something more abstract. Anthropic’s interpretability team demonstrated this concretely in Scaling Monosemanticity (May 2024), where they used sparse autoencoders to pull millions of interpretable features out of a production Claude model. One feature fired on references to the Golden Gate Bridge; when the researchers artificially amplified it, the model began describing itself as the bridge. Those internal features are not decorative. They causally drive behavior.

Training versus inference: two very different activities

People conflate these constantly, and the confusion causes most misconceptions about what AI can do.

Pretraining is the expensive phase. The model is shown enormous quantities of text with a single objective: predict the next token. Its guess is compared against the actual next token, the error is propagated backward through every layer, and billions of parameters are adjusted by a tiny amount. Repeat trillions of times. This runs for months on large GPU or TPU clusters and produces a model that has absorbed statistical structure about language, code, and the world.

Post-training makes that raw model usable. The landmark technique here is reinforcement learning from human feedback, introduced for instruction-following in OpenAI’s InstructGPT paper (March 2022). Humans write demonstrations, then rank model outputs; those rankings train a reward model, which in turn guides the language model. The headline finding was striking: outputs from a 1.3-billion-parameter tuned model were preferred by human raters over a 175-billion-parameter untuned one. Alignment did more for usefulness than a hundredfold increase in size.

Inference is what happens when you press enter. No weights change. The model reads your entire conversation, produces a probability distribution over its whole vocabulary for the next token, samples one, appends it, and repeats. Every word you see is a separate forward pass through the network.

This is why a chatbot does not learn from your conversation. Unless a product explicitly saves notes to a memory store and feeds them back in as text, the model is identical before and after you talk to it.

Why they hallucinate

In September 2025, OpenAI published Why Language Models Hallucinate, arguing that fabrication is not a mysterious bug but a predictable consequence of how models are trained and graded. Their claim: standard procedures reward guessing over admitting uncertainty.

The logic is a test-taking analogy. If a benchmark scores only exact correctness, then guessing a stranger’s birthday gives you a 1-in-365 chance of a point, while saying “I don’t know” guarantees zero. Over millions of training and evaluation signals, that arithmetic pushes models toward confident answers.

The paper backs this with numbers from the SimpleQA benchmark. One newer model abstained on 52% of questions, scored 22% accuracy and 26% errors. An older model abstained on just 1%, got 24% accuracy, and produced errors 75% of the time. Two extra points of accuracy came with roughly triple the hallucination rate.

There is a second, structural cause. Next-token prediction teaches consistent patterns well, but a rare arbitrary fact, appearing once in the corpus, has no pattern to generalize from. The model produces something plausibly shaped instead. That is why hallucinations cluster around specific citations, dates, case numbers, and obscure names rather than general explanations.

Context windows and their limits

The context window is everything the model can see at once: system instructions, tool definitions, conversation history, attached documents, and its own output. Anthropic’s developer documentation describes it as the model’s working memory, and notes that as of 2026 its Opus 5 and Sonnet 5 generation defaults to one million tokens, while older Sonnet 4.5 and Haiku models run 200,000.

A million tokens is a lot of text. It is not the same as a million tokens of reliable recall. The classic result here is Lost in the Middle (Liu et al., 2023), which found that models retrieve information best when it sits near the beginning or end of the input and measurably worse when it sits in the middle. Anthropic’s own docs use the phrase “context rot” for the general effect that accuracy degrades as the window fills.

The practical consequence: pasting a 400-page document and asking a narrow question is less reliable than retrieving the ten relevant paragraphs and asking about those.

What reasoning models changed

Until roughly late 2024, a model’s answer quality was mostly fixed at the moment you sent the request. Reasoning models added a dial.

These models generate a long internal chain of intermediate tokens before writing the visible answer. They plan, check, backtrack, and try alternatives in that hidden scratchpad. OpenAI’s API documentation confirms these reasoning tokens occupy context-window space and are billed as output tokens even though callers never see them, and exposes a reasoning.effort setting that as of 2026 ranges from none through medium up to xhigh and max.

The training breakthrough is documented publicly in the DeepSeek-R1 paper. Its R1-Zero variant was trained with reinforcement learning using only rule-based rewards for final-answer correctness, with no supervised fine-tuning stage at all. Behaviors including self-verification and strategy switching emerged on their own. The reported result was 77.9% pass@1 on the AIME 2024 competition math set, rising to 86.7% with self-consistency sampling.

What did not change: the architecture. Reasoning models are transformers doing next-token prediction. They were simply trained to spend more of those predictions on working the problem out.

What this means for you

A few things follow directly from the mechanism.

  • Put critical instructions at the start or end of a long prompt. Middle-of-context material is measurably less well retrieved.
  • Give the model the source text rather than trusting recall. Facts inside the prompt are read; facts inside the weights are reconstructed and can be wrong.
  • Expect fabrication where the answer is a specific, rare identifier. Citations, statute numbers, API method names, and dates deserve verification every time.
  • Ask for uncertainty explicitly. Models are trained on metrics that penalize abstention, so you often have to request it.
  • Match effort to task. Reasoning modes cost more tokens and more time. Use them for multi-step problems, not for rewriting an email.
  • Do not assume the model learns from you. Inference does not update weights.

Frequently asked questions

Does a language model understand what it is saying?

This is genuinely contested among researchers, and anyone who tells you it is settled is overselling. What is documented is that models build internal features corresponding to abstract concepts, and that manipulating those features changes behavior. Whether that constitutes understanding is a philosophical question the evidence does not resolve.

Why do answers differ when I ask the same question twice?

Because the next token is sampled from a probability distribution rather than always taking the most likely option. Lowering the temperature setting makes output more deterministic but also more repetitive.

Is a bigger context window always better?

No. It costs more, runs slower, and retrieval accuracy drops as the window fills. Selecting the right content usually beats supplying more of it.

Can hallucinations be eliminated?

Not with current methods. OpenAI’s own analysis frames them as a consequence of training and evaluation incentives, which suggests they can be substantially reduced by changing how models are graded, but no published work claims to remove them.

Are reasoning models a different architecture?

No. Same transformer, different training objective and more inference-time computation.

The short version worth remembering

A large language model turns your text into chunks, turns chunks into coordinates, and pushes those coordinates through dozens of layers where every position repeatedly asks every other position what it has to offer. Training set the coordinates and the layer weights. Inference just runs the machine forward, one token at a time.

Everything impressive about these systems and everything frustrating about them comes from that same fact. There is no database being queried and no fact-checker in the loop. There is a very large function, shaped by a very large amount of text, producing the next token. Understanding that will not make you a machine learning engineer, but it will make you a considerably better judge of when to trust the output.

Sources

Image credit: Photo: Raysonho @ Open Grid Scheduler / Grid Engine — Public domain (via Wikimedia Commons)

Leave a Reply

Your email address will not be published. Required fields are marked *