Find a course

Module 1: How AI Models Read Your PromptsLesson 2 of 1212 min

Tokens, Context Windows and Randomness

Understand tokens, context window limits and temperature so you can predict why long chats drift and why the same prompt gives different answers.

Step 1 of 13Learn

Why the model can't count the r's in "strawberry"

Ask some models how many times the letter r appears in "strawberry" and you may get the wrong answer. That seems absurd for a system that can write a sonnet. The reason is tokens.

Models don't read letters or whole words. Text is split into tokens: common words are often a single token, while rarer words are split into pieces. "Strawberry" might become something like str + aw + berry. The model sees those chunks as units, so questions about individual letters are surprisingly hard for it.

Rough rules of thumb for English:

  • One token is about 4 characters on average.
  • One token is about 0.75 words, so 100 tokens ≈ 75 words, and 1,000 words ≈ 1,300 tokens.
  • Other languages, code and unusual spellings often use more tokens per word.

Tokens matter for three practical reasons. They are how models measure length limits, how many paid services charge for use, and why tasks like exact letter counts, rhymes and character limits can go wrong. When a precise count really matters, ask the model to check its work, or count with a tool.

Step 2 of 13Practice · Work it out

Using the rule of thumb that 100 tokens ≈ 75 words, about how many tokens is a 3,000-word report?

Step 3 of 13Learn

The context window: the model's working memory

Every model has a context window: the maximum number of tokens it can consider at once. That budget covers everything: the system prompt, all earlier messages, pasted documents and the reply being written.

Modern models have large windows, often hundreds of thousands of tokens, enough for a long book. But two problems remain even when you're under the limit.

1. Old material can fall out. When a conversation exceeds the window, apps typically drop or compress the oldest parts. Instructions you gave at the start may simply no longer be there.

2. Attention isn't perfect. Even within the limit, models can overlook details buried in the middle of very long inputs. A rule stated once on page 40 of a pasted document gets less reliable treatment than the same rule placed clearly in your instructions.

Practical habits that follow:

  • Put key instructions in a clear, prominent place, and for very long documents, restate the task after the document.
  • Paste only the relevant parts of long material rather than everything you have.
  • When a long chat starts ignoring earlier rules, start a new conversation with a short summary of the decisions so far.

Step 4 of 13Try the calculator

Will it fit? Context budget estimator

Estimate how much of a context window your material uses. Token counts are approximate (1 word ≈ 1.33 tokens in English).

Input tokens (approx.)
16,000 tokens
Reply tokens (approx.)
1,067 tokens
Share of window used
13.3 %

Step 5 of 13Practice · Estimate

Use the estimator: a model has a 32,000-token window. Roughly what percentage of it would a 15,000-word contract plus a 1,000-word reply use?

25 %

Step 6 of 13Learn

Why the same prompt gives different answers

At each step, the model doesn't produce one "correct" next token. It produces a probability for every possible token. After "The weather today is", it might rate sunny at 30%, cold at 20%, nice at 15% and thousands of other options lower.

The app then samples from those probabilities. A setting called temperature controls how adventurous that sampling is:

  • Low temperature (near 0) makes the top choice dominate. Output becomes predictable and repetitive, which is good for extraction, classification and factual formatting.
  • Higher temperature flattens the probabilities, giving lower-ranked tokens a real chance. Output becomes more varied and surprising, which is good for brainstorming and creative writing, but also more likely to wander.

Most chat apps hide this setting and use a moderate default, which is why you can regenerate a reply and get something different. Developers using an API can set it directly.

Two lessons follow. First, one good result doesn't prove a prompt works; try it several times. Second, when you need consistency, don't rely on luck: give a fixed format, clear rules and examples so that the most likely answer is also the right one.

Step 7 of 13Practice · Chart

Next-token chances after "The weather today is"

At a temperature near 0, which word would the model almost always choose?

Tap the bar that answers the question, then press Check.

Next-token chances after "The weather today is"Bar chart with 5 categories: sunny: 30%; cold: 20%; nice: 15%; rainy: 10%; all other tokens: 25%.0%10%20%30%40%sunnycoldnicerainyall other tokens30%20%15%10%25%
Illustrative numbers matching the example above; real models spread probability over many thousands of tokens.
Next-token chances after "The weather today is"
ItemProbability
sunny30%
cold20%
nice15%
rainy10%
all other tokens25%

Step 8 of 13Note

Step 9 of 13Explore

Temperature explorer

Imagine the model is choosing between its two favorite next words. The gap is how strongly it prefers word A (in model "score" units). The curve shows the chance it picks word A as temperature (x-axis) rises.

0.40.60.81 123
Chance of word A at temperature 0.2
100 %
Chance of word A at temperature 1
88.1 %
Chance of word A at temperature 2
73.1 %

Step 10 of 13Practice · Choose one

Using the explorer with a preference gap of 2, what happens to the chance of picking word A as temperature rises from 0.2 to 2?

Step 11 of 13Compare

Choosing a temperature (when you can)

AspectLow (about 0–0.3)Medium (about 0.5–0.8)High (about 1 and above)
BehaviorPicks the most likely tokens almost every timeMostly likely tokens with some varietyFrequently picks less likely tokens
Good forData extraction, classification, code, factual Q&AEveryday writing, emails, explanationsBrainstorming, fiction, unusual ideas
RiskRepetitive, may get stuck in loopsOccasional driftRambling, more factual errors

Step 12 of 13Practice · Fill in the blanks

Fill in the blanks

Text is processed in chunks called . The maximum amount of text a model can consider at once is its , and the setting that controls how random its word choices are is called .

Step 13 of 13Practice · What would you do?

What would you do?

Jordan has been using one chat for three hours: first planning a product launch, then editing a contract, then writing social posts. The social posts suddenly start using formal contract language, and a rule from the start of the chat ("never mention pricing") is being ignored. What should Jordan do?