ChatGPT works by predicting text one small piece at a time. A neural network called a Transformer, trained on a very large amount of text and then tuned with human feedback, reads your conversation and chooses the next token again and again until the reply is complete.
This article follows that path in order: the architecture, the two training stages, and what happens between pressing send and seeing the answer. One limit up front: OpenAI's own help pages blocked automated access when this article was checked, so it relies on the published research papers, OpenAI's API documentation and Google's machine learning course. Where the exact recipe behind the current ChatGPT is not public, the text says so. For the same topic from another vendor, see how Claude works.
Step 1: The Transformer architecture
ChatGPT is built on the Transformer, introduced in the 2017 paper "Attention Is All You Need". The abstract describes it as a new network architecture "based solely on attention mechanisms", dropping the recurrent and convolutional designs that came before. The authors reported results of 28.4 BLEU on WMT 2014 English-to-German and 41.8 BLEU on English-to-French translation, and noted that the model was more parallelizable and faster to train.
The key idea is self-attention. Google's course explains it as asking, for each token, "How much does each other token of input affect the interpretation of this token?" In its example sentence, the pronoun "it" gets a higher relevance score for "animal" than for "street". Models stack many such layers, and later layers can build more abstract representations of the text.
ChatGPT's name has a second half that comes from this design. GPT stands for Generative Pre-trained Transformer: generative because it writes text, pre-trained because it learns from raw text before any tuning.
Step 2: Pre-training on text
The first training stage teaches the model to predict missing text. Google's course says training hides some tokens in a piece of text and adjusts the model's parameters so it fills the gaps more accurately. Repeated over a huge amount of text, this gives the model a working picture of grammar, facts, writing styles and code, stored as numbers in its parameters. For the general mechanics of loss and parameter updates, see how AI learns.
The result of this stage is a model that continues text. Give it the start of a news story and it writes a plausible rest. Give it a question and it may continue with more questions, because that is a plausible continuation too. It is not yet an assistant.
Step 3: Tuning it to follow instructions
The second stage shapes the text continuer into something that answers requests. The published method is described in the InstructGPT paper from OpenAI researchers, and it has three parts:
- Demonstrations. Human labelers write examples of the desired behavior, using prompts they wrote and prompts submitted through the OpenAI API. GPT-3 is fine-tuned on these examples with supervised learning.
- Rankings and a reward model. The model produces several outputs for a prompt, labelers rank them, and a reward model is trained to predict which output people prefer.
- Reinforcement learning. The supervised model is further adjusted using reinforcement learning from human feedback (RLHF), with the reward model supplying the score.
The paper's headline result is that in human evaluations, outputs from the 1.3B-parameter InstructGPT model were preferred to outputs from the 175B-parameter GPT-3, a model with about 100 times more parameters. Tuning for instructions mattered more than raw size in that test.
This paper describes InstructGPT, not ChatGPT itself. The sources opened for this article do not give the full current training pipeline for ChatGPT models, so treat the three steps above as the published method this family of products grew out of, not a current specification.
Step 4: Your message becomes tokens
When you send a message, the text is first cut into tokens. OpenAI's documentation says text models process text in chunks called tokens, and gives a rule of thumb for English: "1 token is approximately 4 characters or 0.75 words". A common word such as "the" is one token, while a longer word can split into pieces. Its example is "tokenization", which breaks into two tokens.
You can check the arithmetic yourself. A 300-word email is about 300 / 0.75 = 400 tokens. The same email in another language, or full of code, can come out differently, because the rule is only an estimate for English. The article how many tokens is a word covers counting in more detail, and the tokenizer tool linked from OpenAI's docs shows how a specific string splits.
Step 5: The model scores every possible next token
The tokens go through the stacked attention layers. At the end, the model produces a probability for each token in its vocabulary being the next one. Google's course puts it this way: LLMs are "essentially autocomplete mechanisms", and a user's question can be treated as given text whose continuation the model scores.
A token is then chosen from those probabilities. How strictly the model picks the single most likely token, or samples from the top few, is a setting that varies by product and by API option. That is one reason the same prompt can give different answers on different tries.
Step 6: The reply is built one token at a time
The chosen token is added to the text, and the whole process runs again to pick the next one. Google's course notes that output is built one token at a time from the text already generated. This repeats until the model emits a stop signal or reaches a length limit. It is also why replies appear to stream word by word: the text really is produced in small pieces.
Because each token depends on all the earlier ones, an early wrong turn can carry through the rest of the answer. The model has no separate fact-checking step inside this loop.
What the context window limits
The model can only work with a fixed amount of text per request. OpenAI's documentation states that for text generation models, "the prompt and the generated output combined must be no more than the model's maximum context length". The limit differs by model, and OpenAI lists each in its model index. A long chat, a pasted document and the reply all draw on the same budget. If you hit the limit in the app, see what to do when the ChatGPT context window is full.
The model's parameters do not change during a chat. What it "remembers" within one conversation is the text it is given again with each turn. Any longer-term memory in the app is a separate product feature, and its settings are in your account.
What this means when you use it
- Fluent does not mean true. The process picks plausible text. Check names, numbers, quotes and citations against a primary source.
- Specific prompts help because the prompt is the whole starting text. The model only sees what is in the context, so details you leave out cannot be used. For practical habits, see how to use ChatGPT effectively.
- It reads and writes tokens, not letters. Tasks that depend on exact letter counts or spelling are awkward for a system that sees chunks of characters.
- Looking things up is a separate tool. Without a search or file tool turned on, answers come from training and the conversation text.
Frequently asked questions
- Does ChatGPT understand what it says?
- Google's machine learning course describes large language models as essentially autocomplete mechanisms that predict the next tokens. They score possible continuations of the text they are given. Whether that amounts to understanding is a debate this article does not settle, but it does explain why fluent answers can still be wrong.
- Does ChatGPT learn from my messages while we talk?
- Not in the training sense. Training adjusts the model's parameters before release, and a conversation does not change them. The model can use earlier messages in the same chat because they are part of the text it reads. Whether a provider later uses conversations to train new versions is set by its privacy settings and terms, so check your account.
- Why does ChatGPT sometimes make things up?
- The model produces the most plausible continuation of the text, one token at a time, and plausible is not the same as true. Nothing in that process checks a claim against a source unless a separate tool such as web search is used. Verify anything important against a primary source.
- What is a token?
- A token is a chunk of text, often a few characters. OpenAI's documentation gives a rough rule of thumb for English of 1 token per 4 characters, or about 0.75 words, so 100 tokens is roughly 75 words. Other languages and code can split differently.