# TokensTokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →, training, and inference: what happens when you hit enter
Type "Paris is the capital of" into ChatGPT, Claude, or Gemini, and it will almost certainly finish with "France." We cover why the model does this in detail in 'What a Model Actually Does: Prediction, Not Understanding.'
Let's open the hood. Three ideas explain the whole pipelinepipelineAll active sales opportunities across the stages of the sales process, together with their combined potential value and probability of closing.Voir la définition complète →:
A large language modellarge language modelA Large Language Model is an AI system trained on vast text data to predict and generate language, enabling tasks like writing, summarizing, and answering questions.Voir la définition complète → (LLMLLMA Large Language Model is an AI system trained on vast text data to predict and generate language, enabling tasks like writing, summarizing, and answering questions.Voir la définition complète →) does not read words the way you do. It breaks text into tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →: small chunks that are often whole words, but sometimes pieces of words.
Here is the classic surprise. The word "strawberry" is not one unit to the model. It is usually read as something like "straw" + "berry." This is why models historically struggled to count the letters in "strawberry": they never saw the individual letters, just the chunks.
A rough rule of thumb in English: 1 token is about 4 characters, or roughly 3/4 of a word. So 100 tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → is about 75 words.
Some quick examples of how text splits:
You can see this for yourself with OpenAI's free Tokenizer tool. Paste in a sentence and watch it split into colored chunks.
TokensTokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → are the unit of pricing and limits. When a tool says it has a "200,000 tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → context windowcontext windowThe context window is the maximum amount of text (measured in tokens) a language model can process at once, including both the input prompt and the generated output.Voir la définition complète →," it means roughly 150,000 words can fit in a single conversation. When an APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.Voir la définition complète → charges "$3 per million input tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →," it is counting these chunks, not words.
Practical takeaway: shorter prompts cost less and fit more. And odd behavior with spelling, rhyming, or counting letters often traces back to tokenization.
Before you ever typed anything, the model went through training: a long, expensive process of learning from enormous amounts of text (books, websites, code, articles).
The core task is shockingly simple. The model is shown a sequence of text with the last tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → hidden, and it must predict the next token.
Show it "The sky is" and it learns to predict "blue." Show it "2 + 2 =" and it learns to predict "4." Do this across trillions of tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →, billions of times, and the model slowly adjusts its internal settings (called parameters, the numbers it tunes) to get better at guessing.
Nobody hand-coded the rule "Paris pairs with France." The model saw that pattern millions of times in its training text and learned the statistical link on its own.
Training has two main stages:
1. Pre-training: the model reads the giant pile of text and learns next-tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → prediction. This produces a "raw" model that is knowledgeable but not very helpful or polite.
2. Fine-tuning and alignment: humans and automated feedback teach the model to follow instructions, be helpful, and avoid harmful answers. This is what turns a text-predictor into ChatGPT.
This is also why models have a knowledge cutoff. Training happened at a fixed point, so a model may not know about events after that date unless it can search the web. In 2026, ChatGPT, Claude, and Gemini all offer live web search to patch this gap, but the base knowledge is still frozen at training time.
Inference is the moment of use: the model is done learning and is now making predictions for you in real time.
Here is the full sequence when you press Enter:
1. Your prompt is split into tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →.
2. The model reads those tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → and predicts the most likely next token.
3. It adds that tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → to the sequence, then predicts the next one.
4. It repeats, one tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → at a time, until it decides the answer is complete.
That word-by-word streaming you see in the interface? That is literally the model generating one tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →, then the next, then the next. You are watching inference happen live.
If the model always picked the single most likely tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →, it would be repetitive and robotic. So there is a setting called temperature that adds controlled randomness.
This is why asking "give me a tagline for my coffee shop" twice gives two different taglines. The randomness is a feature, not a bug.
If you want to watch the pipelinepipelineAll active sales opportunities across the stages of the sales process, together with their combined potential value and probability of closing.Voir la définition complète → concretely, here is a short, runnable example using the OpenAI APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.Voir la définition complète →. (You need an APIAPIApplication Programming Interface: a standardised interface that lets applications communicate and exchange data without knowing each other's internal workings.Voir la définition complète → key; the same idea works with Anthropic's Claude and Google's Gemini APIs.)
from openai import OpenAI
client = OpenAI() # uses your API key
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Paris is the capital of"}
],
temperature=0, # near-zero = most likely token, very predictable
max_tokens=5 # limit the answer to a few tokens
)
print(response.choices[0].message.content)
# Expected output: FranceTwo things to notice. temperature=0 tells the model to play it safe and pick the most likely continuation. max_tokens=5 caps the response length in tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →, not words, which ties straight back to Step 1.
Vérification des acquis
1. According to the lesson, why did LLMs historically struggle to count the letters in the word "strawberry"?
2. Using the lesson's rule of thumb, roughly how many words fit in a 200,000 token context window?
3. When an LLM completes "Paris is the capital of" with "France," what is it actually doing?
4. Select ALL correct answers about how tokens affect cost and limits in practice.
Sélectionnez toutes les réponses correctes.
5. Select ALL correct answers consistent with the lesson's examples of how text splits into tokens.
Sélectionnez toutes les réponses correctes.
Let's trace one real prompt end to end. You type:
> "Summarize this email in one sentence: [pastes a long email]"
1. TokensTokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →: your instruction plus the whole email gets chopped into tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →. A 500-word email is roughly 650 tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète →.
2. Training (already done): the model long ago learned what "summarize" means and how summaries are structured, from countless examples.
3. Inference: the model reads all those tokenstokensA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → and generates a one-sentence summary, one tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → at a time, until it hits a natural stopping point.
No lookup. Just very, very good next-tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → prediction, shaped by training and powered by inference.
Once you see the model as a next-tokentokenA token is the basic unit of text that language models process, often a word fragment, whole word, or punctuation mark rather than a single character.Voir la définition complète → predictor, a lot of practical advice clicks into place:
For a deeper but still readable explainer, the Wikipedia article on large language models is a solid, free reference that stays reasonably plain.