NeoChat

AI basics

How does ChatGPT work? From your prompt to its answer

NeoChat Editorial2 min read

ChatGPT works by sending your message, plus the earlier conversation and some hidden instructions, to one of OpenAI’s GPT large language models. The model splits the text into tokens and predicts the answer one token at a time, based on patterns learned from huge amounts of text and from training on human feedback. Tools such as web search, file reading and image generation are added around the model by the ChatGPT app.

Step 1: your message becomes tokens

ChatGPT does not read words the way people do. It breaks text into tokens, chunks that are often a whole short word or part of a longer one. “ChatGPT works” might become three or four tokens. Every token is mapped to a list of numbers the model can process.

Step 2: the context is assembled

Before the model sees your message, the app adds context: a system message with OpenAI’s instructions, your custom instructions, relevant saved memories, earlier messages in the chat, and the text of any files you uploaded. All of this has to fit in the model’s context window. When a conversation gets very long, older parts may be summarized or dropped.

Step 3: the model predicts the answer

The GPT model is a transformer, a neural network that uses attention to weigh how each token relates to the others. It calculates the probability of every possible next token, picks one, appends it and repeats until the answer is complete. This is why answers appear word by word on screen.

Step 4: reasoning before answering

For harder questions, newer GPT models first generate internal reasoning, working through the problem in steps before writing the final answer. This takes longer but improves results on math, coding and planning. In ChatGPT you can often see a short summary of that thinking.

Step 5: tools extend what the model can do

When the model decides it needs help, ChatGPT can call tools: a web search for current facts, a code interpreter that runs Python for calculations and charts, an image generator, or connectors to apps like Google Drive. The tool’s result goes back into the context and the model writes the answer using it.

How ChatGPT was trained

The underlying model was first pretrained on a vast mix of public web text, books, code and licensed data to predict the next token. It was then fine-tuned on example conversations and trained with feedback from human reviewers who ranked answers, so it learned to be helpful, follow instructions and refuse harmful requests. Our guide to what a large language model is covers these stages in more detail.

Why ChatGPT makes mistakes

The model produces the most plausible continuation, which is usually right but not always. When it lacks information, it can fill the gap with confident invention, known as an AI hallucination. It may also miss recent events if it does not search, or misread a long file. Asking for sources and checking them is the best defense.

Safety layers

Separate systems check prompts and answers for harmful content, and the model itself is trained to decline certain requests. These rules are why ChatGPT sometimes refuses or adds caveats.

To get better results from this process, read how to write prompts. To see how ChatGPT compares with other assistants, see the LLM comparison.

Frequently asked questions

Does ChatGPT search the internet?

It can. ChatGPT searches the web when a question needs current information or when you ask it to, and it shows the sources it used. Otherwise it answers from what the model learned in training.

Does ChatGPT learn from my conversations?

The model does not change in real time while you chat. OpenAI may use consumer conversations to train future models unless you turn that off in settings; business plans exclude data from training by default.

Why does ChatGPT give different answers to the same question?

Each answer is generated by sampling from probabilities, so wording and sometimes content vary between runs. Memory, custom instructions and the chosen model also change the result.

Related articles