How Do Large Language Models Generate Responses? The Simple Science of Next-Word Prediction

Behind the conversational magic of ChatGPT and Claude lies a surprisingly elegant mathematical process: predicting what word comes next, one token at a time.

D

Design The Thought

AI & Tech Desk

November 2026•9 min read

The World's Most Advanced Autocomplete Engine

When you type a message on your smartphone and your keyboard suggests the next word, you are using a tiny language model. If you type 'See you...', your phone predicts 'later', 'soon', or 'tomorrow'.

A Large Language Model (LLM) like OpenAI's GPT-4o, Anthropic's Claude 3.5, or Google's Gemini operates on that exact same principle—but scaled up by a factor of trillions.

An LLM does not possess feelings, consciousness, or a hidden brain storing pre-packaged answers to every question. Instead, it is a massive mathematical engine trained on billions of books, articles, code repositories, and web conversations to answer one fundamental question:

'Given all the words written so far in this conversation, what is the single most likely token to follow next?'

By answering that question 50 to 100 times per second, the AI generates fluid paragraphs, solves coding bugs, and writes poetry that feels remarkably human.

“An LLM doesn't look up answers in an encyclopedia. It generates answers on the fly by predicting the next most plausible word, over and over.”

The Core Mental Model

Think of an LLM as a master improvisor. It never pauses to think through an entire essay before writing line one. It starts speaking and continually chooses the best next word based on the full conversation history.

Step 1: Chopping Language into Tokens

Computers cannot read letters or words directly; they only understand numbers. Before an AI can process your prompt, it converts your text into small building blocks called tokens using a technique called Byte-Pair Encoding.

A token is not always a full word. Common English words like 'cat', 'walk', or 'apple' are single tokens. But longer or complex words are split into pieces: 'unbelievable' might become 'un', 'believ', and 'able'.

On average, in English, 1,000 tokens equals roughly 750 words.

This tokenization explains several quirky AI behaviors that confuse beginners:

• Why AI struggles to count letters: If you ask an LLM 'How many letters are in strawberry?', it often gets it wrong because it never sees the letters 's-t-r-a-w-b-e-r-r-y'. It only sees the numeric tokens representing the chunks.

• Why spelling words backwards is hard: The model has to deconstruct the token into individual characters, reverse their mathematical coordinates, and re-emit them without seeing the intermediate steps.

Step 2: Calculating Probabilities for the Next Token

Once your prompt is turned into tokens, it passes through dozens of neural network layers. At the very final layer, the model does not pick a single word outright. Instead, it assigns a probability score to every single token in its vocabulary (which typically contains 100,000 to 200,000 possible tokens).

For example, consider the sentence: *'The tired student drank a hot cup of...'*

The model's neural network might calculate the following probability distribution:

If the model always picked the #1 highest-probability token (a setting called 'Greedy Decoding'), its writing would quickly become robotic, repetitive, and dull. To make text feel natural and creative, developers introduce controlled randomness through a setting called Temperature.

  • —• 'coffee': 62% probability
  • —• 'tea': 24% probability
  • —• 'cocoa': 8% probability
  • —• 'water': 3% probability
  • —• 'gasoline': 0.00001% probability

Step 3: What Does 'Temperature' Actually Do?

When software engineers call AI APIs, they adjust a parameter called Temperature, usually ranging from 0.0 to 1.0:

• Low Temperature (0.0 – 0.2): The model strictly picks the top 1 or 2 highest-probability words. The output is predictable, consistent, and factual. This is ideal for extracting data from receipts, writing SQL queries, or performing financial calculations.

• Medium Temperature (0.5 – 0.7): The standard setting used in consumer chatbots like ChatGPT and Claude. It selects words from the top 5% of plausible options, providing a natural balance of accuracy and conversational variety.

• High Temperature (0.8 – 1.2): The model ventures further down the probability distribution, occasionally picking surprising words. This produces inventive metaphors, fiction stories, and creative marketing angles—but increases the risk of hallucination and nonsense.

Step 4: The Transformer Secret: Self-Attention

Before 2017, computer models read text sequentially, word by word from left to right. When they reached the end of a long paragraph, they had already 'forgotten' the words at the beginning.

In 2017, researchers at Google published a landmark paper titled *'Attention Is All You Need'*, introducing the Transformer architecture.

Transformers introduced Self-Attention: the ability to process all words in a document simultaneously and calculate dynamic mathematical links between them.

Consider this sentence: *'The server crashed because it ran out of memory.'*

When the model evaluates the word 'it', the self-attention mechanism instantly connects 'it' to 'server' rather than 'memory'. This allows modern models to understand complex grammar, follow instructions across 100-page PDF documents, and keep track of characters across entire books.

How LLM Generation Concepts Connect
Generation StageWhat HappensReal-World Impact
TokenizationText is divided into sub-word chunks (~4 characters)Dictates how models count words, code, and non-English languages
Vector EmbeddingsTokens are mapped to points in multidimensional math spaceAllows the AI to know that 'king' and 'queen' share semantic meaning
Self-AttentionEvery token computes relationships with every other tokenEnables the model to understand context and track pronouns across long essays
Probability DistributionFinal layer calculates likelihood scores for 100,000+ wordsProvides candidate choices for what should be spoken next
Temperature SamplingRandomness filter selects the winning next tokenControls whether the AI sounds like a strict calculator or a creative writer

Inquiries & Clarifications

Do LLMs actually understand what they are saying?

From a computer science standpoint, no. LLMs do not possess subjective conscious understanding, intent, or personal beliefs. They are statistical pattern-recognition engines that have learned the structural, grammatical, and logical relationships between words through massive exposure to human writing.

Why does an AI give a different answer if I ask the exact same question twice?

Unless the developer sets the Temperature setting to absolute zero (Greedy Decoding), the model uses probabilistic sampling. If the top three candidate words have 60%, 25%, and 10% probabilities, the model will occasionally pick the second or third word, sending the subsequent sentence down a completely different conversational path.

What is a token and how do I count them?

A token is a fragment of text that the model processes as a single unit. In English, one token is approximately 4 characters or 0.75 words. A 500-word blog post is roughly 650 to 700 tokens. OpenAI and Anthropic provide free online tokenizer web tools where you can paste text and see exact token breakdowns.

Why do AI models struggle with simple math?

Because models predict words based on visual text patterns rather than running programmatic math equations. When an LLM calculates '437 + 892', it is guessing the most likely sequence of digits based on patterns in its training data. Modern models solve this by writing internal Python code behind the scenes to do the actual calculation.

What is the difference between training an LLM and running inference?

Training is the massive upfront phase where the AI reads billions of web pages over months using thousands of high-end GPUs, costing tens of millions of dollars. Inference is what happens in milliseconds when you type a prompt into ChatGPT and the trained model calculates tokens to reply to you.

Colophon / Disclosure: Some references in our reporting may include independent affiliate partner links. If you acquire software through these links, our publication may receive a commission without cost to you. Read our full Affiliate Disclosure.

Related Dispatches

Recommended Reading
The Weekly Dispatch

Thoughtful Perspectives, Delivered Weekly

Join founders, engineers, and digital operators who read our Tuesday briefing on frontier AI developments, lean business economics, and digital product craft.

No spam • Unsubscribe anytime with one click