Astronoo - Back to homepage
X (new window) Bluesky (new window) Pinterest (new window)
English Français Español Português 日本語 Deutsch 中文
Last updated: October 15, 2026

The journey from prompt to response: behind the scenes of an LLM

A stream of text chopped into tokens passing through an artificial neural network before forming an answer

Artistic visualization of a text cut into tokens passing through the layers of an artificial neural network, illustrating the probability calculation by which a large language model (LLM) produces its answer word after word.
Image source: astronoo.com (new window): AI-generated image, public domain.

Scientific abstract

This article describes step by step the journey of a question asked to a conversational artificial intelligence, from the user's keyboard to the displayed answer. A large language model (LLM) does not consult a database of facts: it computes, token after token, the probability of the next word using hundreds of billions of coefficients adjusted during training. Two annotated diagrams separate the training phase, where the coefficients are born, from the inference phase, where they are used. The second diagram locates each component: browser, AI service, cloud and graphics processing units (GPUs). The article distinguishes the logic (the code) from the coefficients (the model), clarifies what the model no longer contains (the training data) and recalls the simplifications of the diagrams.

What happens between your question and an AI's answer?

A probability calculation, not a knowledge base

When you ask a question to an assistant such as Claude, ChatGPT or Gemini, your text travels through three different places: your device, the publisher's servers, and then a data center equipped with GPUs. It is in the latter that the LLM runs, a program that uses a huge table of numbers, the model, to predict the next token.

A token is a piece of text: a word, part of a word, a punctuation mark or a number. The whole answer is built this way, one token at a time, each new token being chosen among candidates whose probability the model has computed. The two diagrams below show first how these numbers are made, then how they are used.

Also worth exploring

Continue your exploration of the Universe with these topics:

Phase 1: training, where the coefficients are born

╔══════════════════════════════════════════════════════════════╗ ║ TRAINING PHASE ║ ╚══════════════════════════════════════════════════════════════╝ Books Wikipedia Articles Websites Code │ │ │ │ │ └─────────────┴─────────────┴─────────────┴────────────┘ │ ▼ ≈ 10¹³ to 10¹⁴ TOKENS (order of magnitude) (words, word pieces, punctuation, numbers) │ ▼ ╔══════════════════╗ ║ TRAINING ║ ║ Adjusting the ║ ║ coefficients ║ ╚══════════════════╝ │ ▼ Billions of corrections │ ▼ ╔══════════════════════════════════════════════════════════════╗ ║ LLM MODEL ║ ║--------------------------------------------------------------║ ║ Coefficient 1 = 0.28471 ║ ║ Coefficient 2 = -1.94822 ║ ║ Coefficient 3 = 3.70015 ║ ║ Coefficient 4 = -0.01054 ║ ║ ... ║ ║ Coefficient N = 1.58291 ║ ║ ║ ║ 100 to 1000 billion coefficients ║ ║ (= model parameters) ║ ║ ║ ║ - MODEL MEMORY - ║ ╚══════════════════════════════════════════════════════════════╝

N.B.:
Training phase: a corpus of text, cut into tokens, is used to adjust the model's coefficients. The orders of magnitude are indicative.

The sources: an immense corpus of text

Books, Wikipedia, articles, websites, computer code: the training corpus is first cut into tokens. For models whose figures are published, the order of magnitude runs into tens of thousands of billions of tokens: about 15,000 billion for Llama 3, from Meta (2024). The publishers of the most recent commercial models generally do not disclose these values.

Training: adjusting coefficients

The principle is simple. The model is shown the beginning of a text, it predicts the next token, its prediction is compared with the actual continuation, and then the coefficients are corrected very slightly so that the right answer becomes a little more probable. This correction, computed by gradient backpropagation, is repeated billions of times on thousands of GPUs, for weeks or months.

A second, shorter training then steers the model's behavior: answering questions, following instructions, refusing certain requests, adopting a tone. It relies in part on human evaluations.

What remains after training

Only the coefficients remain, also called the model's parameters: from 100 to 1000 billion numbers for today's large models. The texts are not stored in the model like books in a library: they have only shaped these values. A model can reproduce certain very widespread passages (partial memorization), but it cannot "re-read" a book.

Phase 2: inference, from prompt to response

┌── [1] YOUR DEVICE: web browser or mobile application ────────────┐ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ You type your question (the "prompt"): │ │ │ │ "At the center of the Solar System is the" │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ Role: enter the text and display the answer. │ │ No AI computation here (except a small model installed locally).│ │ │ └──────────────────────────────────────────────────────────────────┘ │ │ Internet (HTTPS): │ sending the text ▼ ┌── [2] PUBLISHER'S AI SERVICE: application servers (API) ─────────┐ │ │ │ Your question Conversation System │ │ (prompt) history instructions │ │ │ │ │ │ │ └───────────────────┴───────────────────┘ │ │ │ │ │ ▼ │ │ ╔════════════════════════════════════════════════════╗ │ │ ║ GATEWAY AND ORCHESTRATION ║ │ │ ║ Authentication, quotas, security filters ║ │ │ ║ Assembling the complete prompt ║ │ │ ╚════════════════════════════════════════════════════╝ │ │ │ │ Role: this service is what is called "the AI" │ │ (the assistant); the LLM is only one component. │ │ │ └──────────────────────────────────────────────────────────────────┘ │ │ Cloud internal network │ (toward a GPU server) ▼ ┌─ [3] CLOUD: data center, GPU / TPU servers ──────────────────────┐ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ The LLM = an inference program + the model │ │ │ │ (coefficient file) loaded into GPU memory │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════╗ │ │ ║ TOKENIZATION ║ │ │ ║ Cutting the text into tokens, ║ │ │ ║ one number per token (dictionary) ║ │ │ ╚══════════════════════════════════════════════╝ │ │ │ │ At │ the │ center │ of │ the │ Solar │ System │ is │ the │ │ 412 │ 3871│ 95 │ 15204│ 8830│ 77 │ 2956 │ 31 │ ... │ │ (numbers given as examples) │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════╗ │ │ ║ EMBEDDING ║ │ │ ║ Each token becomes a vector ║ │ │ ║ of thousands of numbers + its position ║ │ │ ╚══════════════════════════════════════════════╝ │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════════════════════╗ │ │ ║ TRANSFORMER BLOCKS, repeated ≈ 80 to 120 times ║ │ │ ║ same logic at each layer, different coefficients ║ │ │ ╟──────────────────────────────────────────────────────────────╢ │ │ ║ ┌────────────────────────────────────────────────────────┐ ║ │ │ ║ │ ATTENTION │ ║ │ │ ║ │ LOGIC (the code, written by humans): │ ║ │ │ ║ │ compare the tokens with one another, weight, mix │ ║ │ │ ║ │ COEFFICIENTS (learned): │ ║ │ │ ║ │ matrices Q, K, V, O: they decide what to pay │ ║ │ │ ║ │ attention to │ ║ │ │ ║ └────────────────────────────────────────────────────────┘ ║ │ │ ║ │ ║ │ │ ║ ▼ ║ │ │ ║ ┌────────────────────────────────────────────────────────┐ ║ │ │ ║ │ FEED-FORWARD NETWORK │ ║ │ │ ║ │ LOGIC (the code, written by humans): │ ║ │ │ ║ │ multiply by matrices, apply an activation │ ║ │ │ ║ │ function │ ║ │ │ ║ │ COEFFICIENTS (learned): │ ║ │ │ ║ │ matrices W1 and W2: this is largely where the │ ║ │ │ ║ │ model's "knowledge" is stored │ ║ │ │ ║ └────────────────────────────────────────────────────────┘ ║ │ │ ╟──────────────────────────────────────────────────────────────╢ │ │ ║ THE COEFFICIENTS = THE MODEL (100 to 1000 billion) ║ │ │ ║ From 200 GB to several TB, loaded into GPU memory, ║ │ │ ║ never modified during the answer. ║ │ │ ║ The training data (10¹³ to 10¹⁴ tokens) are no longer ║ │ │ ║ there: only these coefficients keep a trace of them. ║ │ │ ╚══════════════════════════════════════════════════════════════╝ │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════╗ │ │ ║ SCORES (LOGITS) ║ │ │ ║ One score for each token in the vocabulary ║ │ │ ║ (on the order of 100,000 possible tokens) ║ │ │ ╚══════════════════════════════════════════════╝ │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════╗ │ │ ║ SOFTMAX ║ │ │ ║ Converting scores into probabilities ║ │ │ ╚══════════════════════════════════════════════╝ │ │ │ │ Sun = 92% │ │ Moon = 4% │ │ Jupiter = 3% │ │ Others = 1% │ │ │ │ │ │ │ ▼ │ │ ╔══════════════════════════════════════════════╗ │ │ ║ SAMPLING ║ │ │ ║ Choosing the token according to the ║ │ │ ║ probabilities (settings: temperature, top-p) ║ │ │ ╚══════════════════════════════════════════════╝ │ │ │ │ │ │ │ ▼ │ │ Token chosen: "Sun" │ │ │ │ │ │ │ ▼ │ │ ┌────────────────────────────────────────────────────────┐ │ │ │ GENERATION LOOP │ │ │ │ The token is added to the text and the cycle starts │ │ │ │ again for the next token, until the "END" token │ │ │ └────────────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────────────────┘ │ │ Streaming: each token is sent │ back as soon as it is computed │ (AI service, then Internet) ▼ ┌─ [4] YOUR DEVICE: displaying the answer ─────────────────────────┐ │ │ │ ╔══════════════════════════════════════════════════════════╗ │ │ ║ ANSWER DISPLAYED WORD BY WORD ║ │ │ ║ "At the center of the Solar System is the Sun." ║ │ │ ╚══════════════════════════════════════════════════════════╝ │ │ │ └──────────────────────────────────────────────────────────────────┘ ╔══════════════════════════════════════════════════════════════╗ ║ LEGEND ║ ╟──────────────────────────────────────────────────────────────╢ ║ Model = coefficient file (the "memory") ║ ║ LLM = model + the program that runs it ║ ║ AI = complete service: application, API, filters, ║ ║ conversation history ║ ║ Cloud = data center that hosts the GPUs ║ ╚══════════════════════════════════════════════════════════════╝

N.B.:
Inference phase: four zones, from your device to the cloud, then back. The token numbers and probabilities are given as examples.

The diagram is divided into four colored zones that indicate where each component is. Zones 1 and 4 (blue) are on your device, zone 2 (orange) is the publisher's AI service, zone 3 (green) is the cloud, that is, a data center.

Zone 1: your device

The browser or mobile application merely collects your text and displays the answer. For large models, no AI computation takes place here, because the coefficients occupy hundreds of gigabytes. Only small compact models can run locally on a recent computer or phone.

Zone 2: the publisher's AI service

Your text travels over the Internet (HTTPS protocol) to the publisher's application servers. A gateway verifies your identity and your quotas, applies security filters, then assembles the complete prompt: the system instructions, the conversation history and your latest question.

This detail is essential: the model keeps no memory of the conversation. It is the service that sends it the whole history with each question, up to the context window, that is, the maximum number of tokens the model can read at once. This service, with its application, its filters and its history, is what is commonly called "the AI." The LLM is only one component of it.

Zone 3: the cloud and its GPUs

The complete prompt is transmitted over the data center's internal network to servers equipped with GPUs or TPUs, chips designed to perform huge matrix multiplications in parallel. The model, which occupies from 200 GB to several terabytes, is distributed across the memory of several chips. This is where the LLM in the strict sense is found: an inference program associated with the model.

In the cloud: seven computation steps

1. Tokenization

The text is cut into tokens using a dictionary fixed before training (the so-called byte-pair encoding method). Each token is given a number. Frequent words form a single token; rare words are split into pieces. The vocabulary has on the order of 100,000 to 200,000 tokens.

2. Embedding

Each token number is replaced by a vector, a list of thousands of numbers (16,384 for the largest Llama 3 model). Position information is added, because word order changes meaning. These vectors are themselves coefficients learned during training.

3. Transformer blocks: attention

The heart of the model is a stack of Transformer blocks, an architecture proposed in 2017. Large models have on the order of 80 to 130 of them. In each block, the attention mechanism compares each token with the preceding tokens and computes their relative importance: in "At the center of the Solar System is the," the words "center" and "Solar" weigh heavily for predicting the continuation. The matrices that decide what to pay attention to (denoted Q, K, V and O) are coefficients.

4. Transformer blocks: the feed-forward network

Each block also contains a feed-forward network, which transforms each vector by two large matrix multiplications separated by an activation function. Interpretability work suggests that these layers serve largely as memory for learned associations, but this interpretation remains a research hypothesis.

In these two steps, the logic is identical at each block, because it is the same code. Only the coefficients differ from one block to another.

5. Scores and probabilities

At the output of the last block, the model assigns a score (logit) to each token in the vocabulary. The softmax function converts these scores into probabilities whose sum equals 100%. In the diagram's example, "Sun" gets 92%, "Moon" 4%, "Jupiter" 3% and all the other tokens together 1%.

6. Sampling

The token is not always the most probable one. A setting called temperature flattens or sharpens the probabilities, and the top-p method limits the draw to the most probable candidates. At very low temperature, the answer is almost deterministic; higher, it varies from one run to the next. This is why the same question does not always produce the same answer.

7. The generation loop

The chosen token, here "Sun," is added to the text, and the whole cycle starts again to compute the next token, until the model produces a special end token. An answer of 300 words therefore requires several hundred successive passes through the model.

Zone 4: the return to your screen

The tokens are not all awaited together: each is sent back as soon as it is computed (streaming), passing again through the AI service and then the Internet. Your device displays them as they arrive, which gives the impression of an answer "written live."

Logic and coefficients: what does a model really contain?

Three things are often confused: the code that performs the computations, the coefficients that determine the result, and the data that were used to set those coefficients. The table below separates them.

Logic, coefficients and data in an LLM
ElementNatureOriginPresent during the answer?
LogicCode and architecture (attention, feed-forward, softmax)Written by humansYes, executed for each token
Coefficients100 to 1000 billion numbersAdjusted by trainingYes, read from GPU memory, never modified
Training dataBooks, web pages, codeCollected before trainingNo, only traces in the coefficients remain
Prompt and historyText of the conversationYou and the AI serviceYes, reread in full at each question

Where is each component located?

Location and role of the diagram's components
ComponentLocationRole
Browser or applicationYour deviceEntering the prompt, displaying the answer
Gateway and orchestrationAI service serversAuthentication, quotas, filters, prompt assembly
Inference programCloud GPU serversRuns the seven computation steps
ModelGPU memoryProvides the coefficients that determine the probabilities
Training dataOutside the answer circuitUsed only for training

The limits of the diagram

A deliberately simplified diagram

The diagrams leave out several elements: mixtures of experts, where only part of the coefficients is activated for each token; the cache memory of attention computations, which avoids recomputing everything at each token; the normalizations and residual connections inside the blocks; the external tools (web search, code execution) that the AI service can call; and the processing of images or sounds. Depending on the publisher, tokenization may also be performed in the AI service rather than on the GPU server.

Why an AI can be confidently wrong

Because the model chooses plausible tokens, not verified facts, it can produce a fluent but false sentence, which is called a hallucination. Nothing in the computation distinguishes a learned fact from a plausible sequence of words: only probability counts. Connections to external sources and human verification therefore remain indispensable.

What to remember

An LLM is first of all a program that multiplies matrices, associated with a model that is an immense table of coefficients. These coefficients were fixed by training on enormous text corpora, then frozen. With each question, the text travels from your device to a data center, goes through seven computation steps, produces a token, and then starts again.

This mechanism explains both the power of these systems and their limits: they excel at continuing a text plausibly, and they have no memory of their own of the conversation nor any guarantee of truth. Understanding where each component is located is also understanding where the issues of computation, energy and confidentiality lie.

References

FAQ: How an LLM works

What is a token?

A token is the unit of text handled by the model: a frequent word, a piece of a word, a punctuation mark or a number. A French text generally has slightly more tokens than words.

Does an LLM understand what it says?

Mechanically, it computes the probability of the next token. Its internal representations nevertheless capture many relationships between concepts, and the question of whether this constitutes a form of understanding remains debated in AI and in cognitive science.

Does the model learn from my conversation?

During the conversation, the coefficients are not modified: the model is frozen. The service may however keep the history to return it to you, and some publishers may use conversations to prepare future versions, depending on their policy and your settings.

Why are GPUs indispensable?

Computing one token comes down to enormous matrix multiplications. GPUs perform thousands of them in parallel and have fast memory to store the coefficients, which classic processors cannot do at this scale.

Can you run an LLM on your own computer?

Yes, for reduced-size models, often quantized (coefficients stored with less precision). The largest models, however, require several GPUs and exceed the capabilities of a personal computer.

Why does the answer change from one time to the next?

Because the sampling step draws the token at random according to the probabilities. At a very low temperature, the answer becomes almost identical from one run to the next.

What is a hallucination?

It is a plausible but false answer. It occurs because the model chooses likely tokens, without verifying the facts they state.

🏠

To explore in this category

The journey from prompt to response: behind the scenes of an LLM
The token: the fundamental unit of large language models
The Different Types of AI Learning
Agentic AI: When Machines Become Autonomous
What AI Cannot Do
Artificial Intelligence and Astronomy: Understanding the Role of AI Assistants
AI Tools: How to Choose?

Artificial Intelligence: Noise Creators and the Cognitive Bubble Ready to Burst
Generative AI vs AGI: Where does imitation end and consciousness begin?
Artificial networks vs biological networks: Two systems, one common architecture
Human Brain and Artificial Intelligences: Similarities and Differences
AlphaGo vs AlphaGo Zero: A Revolution in Artificial Intelligence
The Next Step for Intelligent Machines
The First Step Towards the Emergence of Life
From Biological Neuron to Formal Neuron: Simplifying the Brain
Artificial intelligence: the explosion of gigantism
When AI models train on their own data, they go mad!
How machines become intelligent
Artificial intelligence: real threat or opportunity for humanity?
How do machines understand, interpret and generate language in a similar way to humans?
How does an artificial neural network work?