24 November 2026 · 8 min read
How does ChatGPT work? The maths for Class 10
Chatbots look like magic, but every step inside them is maths you already know or will meet by Class 12: multiplying, adding, a little probability and a lot of practice.
When you type a question into a chatbot, it seems to think. Underneath, it is doing something much plainer: it reads your words as numbers, does a very long sum, and picks the next word. Then it does it again for the word after that. Everything in that sum is school maths.
Step 1: words become lists of numbers
A computer cannot multiply the word “cat”. So each piece of a word, called a token, is turned into a list of numbers, called a vector. A real model uses lists that are thousands of numbers long, but the idea works with two.
Imagine “cat” is [0.9, 0.2] and “dog” is [0.8, 0.3]. They are close together, because cats and dogs appear in similar sentences. “Car” might be [0.1, 0.9], far away. The model learns these numbers by itself while it trains, so words used alike end up near each other.
Step 2: the dot product measures how related two words are
To compare two vectors, multiply matching numbers and add: [0.9, 0.2] · [0.8, 0.3] = 0.9 × 0.8 + 0.2 × 0.3 = 0.78. A bigger dot product means the two words point the same way. This one operation, which you can do with a pencil, is the heart of the part of a chatbot called attention.
Step 3: attention lets each word look at the others
In “The bank of the river was muddy”, the word “bank” needs to notice “river” to know it is not a money bank. Attention does this with dot products: “bank” scores every earlier word, and words with high scores get more say in what “bank” means here.
Step 4: scores become probabilities
Scores can be any numbers, so they are turned into probabilities that add up to 1 by a function called softmax. It makes the biggest score bigger and the small ones smaller, a bit like turning marks into percentages, but with exponents.
- Raise e to the power of each score.
- Add them all up.
- Divide each one by the total.
Step 5: pick the next word
At the end, the model has a probability for every possible next token: maybe 41% for “brown”, 12% for “old”, and tiny amounts for thousands of others. It picks one, adds it to the text, and runs the whole sum again for the next word. A long answer is hundreds of these steps.
How does it learn the numbers?
At first every number is random and the predictions are nonsense. Training shows the model a sentence, asks it to predict the next word, and measures how wrong it was with a loss. Then it nudges every number a tiny bit in the direction that lowers the loss. That nudging is gradient descent, and it uses derivatives, which you meet in Class 11 and 12. Repeat it billions of times and the numbers settle into something useful.
Nothing in this article needs more than multiplication, addition, powers and the idea of a slope. That is why Gradient’s course on the maths behind AI starts from multiplying two numbers.
What this means for you
- Vectors and dot products: Class 11 and 12 maths, but you can start now.
- Probability: Class 10 onwards.
- Derivatives (the slope of a curve): Class 11 and 12.
- Matrices: Class 12, and they are just many dot products at once.
A worked example with three tiny words
Imagine a model that knows only three words, each stored as a list of two numbers: cat = [2, 1], dog = [2, 2] and car = [−1, 3]. To see which word is most related to cat, take the dot product of cat with each word: multiply matching numbers and add.
- cat · dog = 2×2 + 1×2 = 6
- cat · car = 2×(−1) + 1×3 = 1
- cat · cat = 2×2 + 1×1 = 5
- Biggest score: dog, so the model treats “dog” as most related to “cat”
Real models use lists with thousands of numbers instead of two, and millions of words and word pieces, but the arithmetic is exactly what you just did. A Class 10 student who can multiply and add can follow every step.
From scores to percentages
Scores like 6, 1 and 5 are turned into probabilities with a rule called softmax: raise e (about 2.718) to the power of each score and divide each by the total. Bigger scores get a much bigger share. For 6, 1 and 5 that gives roughly 73%, 0.5% and 27%. Those percentages are what the model uses to pick the next word, often with a little randomness so that it does not say the same thing every time.
This is also why answers vary when you ask the same question twice. The model is choosing from a list of likely words, not looking up one fixed answer.
How the numbers are learned
At the start, every number in the model is random. The model reads a sentence with the last word hidden, guesses it, and measures how wrong it was. Calculus then tells it which way to nudge each number to be a little less wrong next time. This nudge is called gradient descent, and it is repeated billions of times over enormous amounts of text.
Nobody types in the meaning of “cat”. The numbers end up meaning something only because nudging them made the guesses better.
Which school topics you need
- Coordinate geometry and vectors (Class 10 to 12): words as points and arrows.
- Exponents and logarithms (Class 9 and 11): softmax and measuring error.
- Probability (Class 10 and 12): choosing the next word.
- Derivatives (Class 11 and 12): learning by gradient descent.
What happens when you press Enter
- Your message is cut into tokens: whole words or pieces of words
- Each token becomes an embedding, a list of a few thousand numbers
- Dozens of transformer layers mix these lists using attention, built on dot products
- The last layer gives a score to every token in the vocabulary
- Softmax turns scores into probabilities and one token is picked
- That token is added to the text and the whole process repeats
A reply of 200 words therefore needs roughly 250 rounds of this loop. Each round involves billions of multiplications, which is why the replies appear word by word and why special chips called GPUs are used. A GPU does thousands of multiplications at the same moment.
Tokens, not letters
The model does not see letters. “Unbelievable” might become “un”, “believ” and “able”. This is why chat models sometimes struggle to count letters in a word or to reverse a word: they never saw the letters one by one. It is a good example of how knowing the maths explains the strange mistakes.
How big is big?
A model described as having 70 billion parameters stores 70 billion learned numbers. Written at one number per line in an exercise book of 200 lines, that would fill 350 million books. Training such a model can take months on thousands of chips and uses more text than a person could read in many thousands of lifetimes.
Questions to think about
- If the model picks likely words, how could it ever say something new?
- Why might two different prompts with the same meaning give different answers?
- What kinds of mistakes would you expect from a model that never sees letters?
- Why does a model need to be checked by people before it is released?
Glossary
- Token: a word or piece of a word that the model handles as one unit.
- Embedding: the list of numbers that stands for a token.
- Parameter or weight: one learned number inside the model.
- Softmax: the rule that turns scores into probabilities.
- Training: adjusting parameters to make better guesses on example text.
You can try every idea here on paper with tiny numbers. That is the best way to see that there is no magic inside, just a very large amount of simple arithmetic done very fast.
Try these yourself
- Q1. Words: sun = [3, 1], moon = [2, 2]. Find sun · moon. Answer: 3×2 + 1×2 = 8.
- Q2. Which is closer to sun = [3, 1]: star = [3, 0] or sea = [0, 3]? sun·star = 9, sun·sea = 3, so star.
- Q3. Scores 2 and 0. Using softmax, what share does the first get? e² ÷ (e² + 1) ≈ 7.39 ÷ 8.39 ≈ 88%.
- Q4. A model guessed “dog” with 20% when the answer was dog. Is the error large or small? Large: a good model would give the right word a much higher share.
A short history
Word vectors became popular around 2013. The transformer, the design behind ChatGPT, was published in 2017. Large chat models trained on huge text collections reached the public in late 2022. Each step used the same school-level maths at much larger scale.
In short
ChatGPT turns words into lists of numbers, compares them with dot products, turns scores into percentages with softmax and picks the next word. It learned its numbers by guessing hidden words and nudging itself after each mistake. Every piece connects to a topic in your school syllabus.
Keep going
Questions people ask
Is ChatGPT just predicting the next word?
Yes, one piece of a word at a time. But to predict well across so much text it has to learn grammar, facts and patterns of reasoning, which is why the result can look like understanding.
Do I need to know calculus to understand it?
Not for the main idea. Dot products and percentages explain how it chooses words. Calculus explains how it learned its numbers, and you meet that in Class 11 and 12.
Why does ChatGPT sometimes make mistakes?
It picks likely words, not checked facts. If wrong text is likely, it can produce it confidently. That is why you should check important answers.