Understand the technology behind ChatGPT — large language models, tokens, and how AI generates text.
You ask ChatGPT a question and get back a clear, confident, well-organized answer in seconds. Then you ask a follow-up and it tells you something that turns out to be flatly wrong, in exactly the same confident tone. So which is it: brilliant or unreliable?
Both, and the reason is the same. Once you understand what is actually happening when you press Enter, the good answers and the bad ones both make sense, and you can start getting more of the first kind on purpose. That is what this lesson is for. No math, no jargon you do not need, just an accurate picture of the machine you are talking to.
ChatGPT is a chat app built by OpenAI. Underneath it sits a large language model, or LLM: a very large neural network trained on an enormous amount of text, including books, websites, articles, and code.
During training, the model was shown text and asked, over and over, to guess what comes next. Each time it guessed wrong, its internal settings were nudged slightly so the next guess would be a little better. Repeat that across a huge amount of text and the model ends up holding a detailed map of how language tends to go: grammar, common facts, styles of argument, how emails open and close, how code is structured.
The important part is what it does not hold. It does not store a searchable copy of the internet. It does not look up answers in a database. It learned patterns, and it produces text from those patterns.
When you type a message, this is roughly what happens:
So the primary job of the model is simple to state: given a sequence of tokens, predict the next one. Think of it as autocomplete on your phone, scaled up enormously. Your phone suggests the next word; the model keeps going for paragraphs, and because its patterns are so rich, the result can hold together as an explanation, a plan, or a working piece of code.
This explains the puzzle from the opening. The model is producing text that looks like a good answer to your question. Most of the time, a good-looking answer and a correct answer are the same thing. Sometimes they are not, and the model has no built-in alarm that tells it the difference.
Everything the model can "see" at once, your messages plus its replies, has to fit inside its context window, a limit measured in tokens. Limits vary by model and keep growing. As one example, GPT-4o, a widely used model, was released with a context window of about 128,000 tokens. Newer models may differ, so check the current documentation rather than memorizing a number.
What this means for you: in a very long conversation, the earliest material can fall out of view, and the model may start forgetting instructions you gave at the start. If that happens, restate the important details or start a fresh chat.
A hallucination is when the AI generates confident but incorrect information: a made-up statistic, a book that does not exist, a quote nobody said. It happens because the model is predicting plausible text, not checking facts. A fake citation looks exactly like a real one, pattern-wise. You will learn how to guard against this in the third lesson.
The model's knowledge comes from its training data, which stops at a knowledge cutoff date. The model itself has no real-time connection to the internet. Some versions of ChatGPT add a web search tool on top, and when that tool runs you will usually see it searching or citing sources. Without that, anything that happened after training is simply unknown to the model, and it may guess.
The model does not learn from your chats. Its training is finished before you ever talk to it. Within one conversation it can refer back to what you said, because that text is sitting in its context window. Close the chat and start a new one, and by default it starts fresh.
Some apps offer a "memory" feature. That works by saving short notes about you and quietly adding them to future conversations. The model itself has not changed or learned anything; it is just being handed a reminder.
Because the model predicts from everything in the conversation, your prompt is the single biggest lever you control. A vague prompt gives it little to go on, so it falls back on the most generic, average answer. A specific prompt steers it toward a narrower, more useful set of patterns.
Here is the difference in practice.
Before:
Explain how a car engine works.
This usually gets you a textbook-style paragraph about pistons, combustion, and crankshafts, pitched at nobody in particular.
After:
Explain how a car engine works to [WHO IT'S FOR, e.g. my 10-year-old].
Use simple words and one everyday analogy they would recognize.
Keep it under [NUMBER] sentences and end with one question
I can ask them to check they understood.
Same topic, same model. The second prompt tells it who the audience is, how long to go, and what shape the answer should take. Every one of those details changes which patterns the model draws on. You are not unlocking a hidden mode; you are giving the prediction machine better material to predict from.
Set aside 10 to 15 minutes.
Step 1. Open ChatGPT and send this exact prompt:
Explain how a car engine works.
Step 2. Start a new chat and send the "after" version above, filling in the brackets with a real person you know and a sentence limit.
Step 3. Compare the two. Note three concrete differences: length, vocabulary, and structure.
Step 4. In the same chat, ask a follow-up about something recent, for example:
What happened in the news in [YOUR CITY] this week?
Watch what it does. Does it search the web and show sources, or does it tell you it cannot access current events, or does it guess? Any of those is useful to see, because it shows you where the model's own knowledge ends.
Step 5 (optional). If you have access to the Study AI Mastery Playground, run the "after" prompt in compare mode on two or three different models side by side. You will see that the same prompt produces different answers, which is a good reminder that you are dealing with prediction, not a single correct lookup.
from openai import OpenAI
client = OpenAI(api_key="your-key-here")
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful tutor."},
{"role": "user", "content": "What is machine learning?"}
]
)
print(response.choices[0].message.content)Learn the fundamentals of writing prompts that get useful, accurate responses from ChatGPT.
Getting Started with ChatGPT
No resources available for this lesson yet.
Ask me anything about this lesson!
I'm here to help you understand the concepts better.
Test your understanding of this lesson
AI will generate 5 questions tailored to this lesson
Test your understanding of What is ChatGPT and How Does It Work?
Test your understanding of What is ChatGPT and How Does It Work?