Uni-Sine
AI
+25XP
AIHow AI works

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.

Try it

Language Model Simulator

See tokens, next word odds and temperature at work

Go to its page

How to use the language model simulator

  1. Under Model, choose a Training text: a short story, weather forecasts, Shakespeare's Sonnet 18, or your own text.
  2. Choose whether tokens are Words (with punctuation) or Characters.
  3. Set the Context, from 1 to 4 tokens: how many previous tokens the model looks at.
  4. Set the Temperature, from 0 to 2, and type a prompt.
  5. 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 tokenCountProbability
.50.3125
sat40.25
ran30.1875
others40.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:

p_i' = \frac{p_i^{1/T}}{\sum_j p_j^{1/T}}

Example: two options

A model gives two next tokens probabilities 0.7 and 0.3.

TemperatureFirst tokenSecond tokenEffect
010Always picks the most likely token
0.50.8450.155Sharper: the favourite wins more often
10.70.3The model's own odds
20.6040.396Flatter: 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?
A program that gives probabilities to the next token in a sequence, so it can write by picking one token at a time.
What does temperature do in an LLM?
It sharpens or flattens the probabilities before a token is picked. Low temperature picks the likeliest tokens; high temperature picks rarer ones more often.
What happens at temperature 0?
The model always picks the single most likely next token, so the same prompt gives the same text.
What is an n-gram model?
A model that predicts the next token from the previous n − 1 tokens, using counts from a training text.
Is this simulator a real AI model?
No. It is a tiny counting model for teaching. Real large language models use neural networks trained on far more text.
What is a token?
A unit of text the model works with: here a word, a punctuation mark or a character. Real models often split words into pieces.

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
Read next
AI · How AI worksWhat is a token in AI? Meaning, examples and costLearn what a token in AI is, see how text really splits into tokens, and estimate tokens and cost yourself, with worked examples and real prices.