Language model simulator
A language model simulator shows the idea at the heart of tools like ChatGPT and Claude: predict the next token from the ones before it, then pick one and repeat. Our Language Model Simulator is a tiny teaching model, not a large language model. It counts which token follows which in a short text, shows the odds of every possible next token, and writes by sampling from those odds at the temperature you choose.
It opens on a short story about a cat and a dog, a context of 2 tokens, a temperature of 0.8 and the prompt "the cat". It runs entirely in your browser and makes no network calls.
Language Model Simulator
See tokens, next word odds and temperature at work
How to use the language model simulator
- Under Model, choose a Training text: a short story, weather forecasts, Shakespeare's Sonnet 18, or your own text.
- Choose whether tokens are Words (with punctuation) or Characters.
- Set the Context, from 1 to 4 tokens: how many previous tokens the model looks at.
- Set the Temperature, from 0 to 2, and type a prompt.
- Step through the run under Run. Each step shows the context used, every next token with its odds before and after temperature, and the one it picked.
The readouts give the number of tokens in the text, the number of different tokens, how many options there are, and the uncertainty in bits. When the model has never seen the current context, it falls back to a shorter one and says so. Practice and help sets questions on next-token probabilities and temperature, with worked solutions.
How next-token prediction works
The simulator is an n-gram model: it predicts from the last few tokens only. With a context of 2, it looks at every place "the cat" appears in the training text and counts what came next:
| Next token | Count | Probability |
|---|---|---|
| . | 5 | 0.3125 |
| sat | 4 | 0.25 |
| ran | 3 | 0.1875 |
| others | 4 | 0.25 between them |
Each probability is the count divided by the 16 times "the cat" appears: 5 ÷ 16 = 0.3125. Large language models work on the same principle of predicting the next token, but with a neural network trained on vast amounts of text, so they can use a context thousands of tokens long and handle sequences they have never seen. Our guide to what a token is in AI covers how real models split text.
Try estimating tokens in the course, then press Mark:
Use a rule of thumb to estimate a token count or a cost, typed as maths.
Press Mark to have your answer marked in the AI Prompt Engineering course.
LLM temperature: what it does
Temperature reshapes the odds before a token is picked. Each probability is raised to the power 1/T, then they are scaled to add up to 1 again:
Example: two options
A model gives two next tokens probabilities 0.7 and 0.3.
| Temperature | First token | Second token | Effect |
|---|---|---|---|
| 0 | 1 | 0 | Always picks the most likely token |
| 0.5 | 0.845 | 0.155 | Sharper: the favourite wins more often |
| 1 | 0.7 | 0.3 | The model's own odds |
| 2 | 0.604 | 0.396 | Flatter: rarer tokens get more chances |
At 0.5, 0.7² = 0.49 and 0.3² = 0.09, so the first becomes 0.49 ÷ 0.58 = 0.845. In the simulator at 0.8, the "." after "the cat" rises from 0.3125 to 0.355. Low temperatures give safe, repetitive text; high temperatures give varied but less sensible text. Try the Sonnet at 0 and then at 2 to see both.
What the simulator does not do
- It is not an AI chatbot. It only knows the short text it was trained on, and it cannot answer questions or follow instructions.
- No neural network. It counts; it does not learn meanings. Real language models use transformers and embeddings, which this does not show.
- A short context. At most 4 tokens, so it soon loses track of a sentence.
Common mistakes
- Thinking temperature makes a model smarter. It only changes how often less likely tokens are picked.
- Thinking the model looks up answers. It generates each token from probabilities; it does not copy a stored reply, though a tiny model often repeats its training text.
- Assuming a token is a word. In real models, tokens are often pieces of words; here you can choose words or characters.
Learn more
The AI Prompt Engineering course starts with how AI reads text as tokens, one token at a time, and our guide to how neural networks learn covers the training behind real models.
Common questions
What is a language model?
What does temperature do in an LLM?
What happens at temperature 0?
What is an n-gram model?
Is this simulator a real AI model?
What is a token?
Revision cards
Say the answer first, then flip the card to check it.
Where to go next
- Solve it
Language Model Simulator
See tokens, next word odds and temperature at work
Open the tool - Learn it
AI Prompt Engineering
Prompts, agents and multi-agent workflows for large language models
Start the course