P.K. SHARMA

Cyber security intelligence, AI governance, practitioner analysis

Interactive explainer

How a language model actually works

Watch a sentence become tokens, then numbers, then a guess. Five steps from text to prediction, with a temperature dial you can turn.

A language model does one thing: given some text, it produces a score for every token that might come next, then picks one. Everything else, the fluency, the apparent reasoning, the confident tone, is that single operation repeated. Run it below and the mechanism stops being mysterious.

How this works: A deterministic simulation with pre-computed values, not a live model. The token splits and the mechanics are faithful, and the temperature control performs a genuine softmax over stored scores, so the distribution really does change as you move it. The scores themselves are illustrative.

The text you typed

An unauthorised agent can exfiltrate

becomes 9 tokens

An2025
unauthorised · 3 tokens555 3166 1859
agent8355
can649
exfiltrate · 3 tokens409 22217 7853

Common words survive whole. Rarer ones are assembled from fragments, which is why unauthorised costs three tokens and can costs one. The model never sees letters or words, only these numbered pieces.

Step 1 of 5

Split the text into tokens

Text is broken into subword pieces from a fixed vocabulary. Common words stay whole; rarer ones are assembled from fragments. The model never sees letters or words, only numbered pieces.

Keep scrolling to advance

The pipeline, step by step

  1. 1

    Split the text into tokens

    Text is broken into subword pieces from a fixed vocabulary. Common words stay whole; rarer ones are assembled from fragments. The model never sees letters or words, only numbered pieces.

  2. 2

    Turn tokens into positions in space

    Each token becomes a vector. Words used in similar contexts end up near each other, which is where the impression of understanding comes from: it is geometry, learned from statistics over an enormous amount of text.

  3. 3

    Weigh what matters

    To predict what comes next the model weighs every earlier token. Attention decides which parts of the context carry the most influence. It is a weighting over positions, not comprehension.

  4. 4

    Score every possible next token

    The model produces a score for every token in its vocabulary, tens of thousands of them, and those scores become probabilities. Nothing at this stage consults a fact, a source, or a database.

  5. 5

    Pick one, then do it all again

    One token is drawn from the distribution, appended to the text, and the whole process repeats. Temperature controls how adventurous that draw is.

Where this breaks

Where this breaks: it predicts, it does not know

Nothing in this pipeline checks whether the output is true. The model selects tokens that are statistically plausible given the context, which is why a confident, well-formed, entirely wrong answer costs it no more effort than a correct one. Hallucination is not a defect bolted onto an otherwise truthful system; it is the same mechanism working exactly as designed. That is why a model's output is not evidence, why it needs grounding in real sources, and why anything consequential needs a check outside the model.

This is the work behind AI Security Assessment.

Common questions

Is a token the same as a word?

No, and the difference matters. Tokens are subword pieces from a fixed vocabulary. Common words are usually one token, while rarer or longer words break into several. This is why costs and context limits are quoted in tokens rather than words, and why unusual text consumes budget faster than you expect.

Does the model understand what it is saying?

It has a rich statistical model of how language is used, which lets it track context and produce coherent, relevant text. What it does not have is any check against the world. It has no notion of true or false, only of what tends to follow what.

What does temperature actually do?

It divides the raw scores before they are converted into probabilities. Low temperature sharpens the distribution towards the most likely token, giving repeatable and conservative output. High temperature flattens it, so unlikely tokens start being selected, giving variety and more errors.

Why does the same prompt give different answers?

Because the final step is a weighted draw, not a lookup. Unless temperature is at or near zero, a different token can be selected each time, and once one token differs the rest of the answer diverges from it.

Why can it not just say when it does not know?

There is no separate signal for not knowing. The model always produces a distribution over next tokens, and a confident wrong answer and a correct one are generated by the same process. Models can be trained to hedge more often, but that is a learned style rather than genuine self-knowledge.

Share this explainer

Free to embed on your own site or newsletter.

LinkedInXWhatsAppEmail

Related analysis

Next explainer

Your six-word question becomes thousands of tokens. Follow the whole pipeline, then fill the context window until your own instructions fall out.