Reading preferences
Concept

Tokens, Context, and Language Models

Follow a prompt through tokenisation and prepared next-token inference.

generative ai, llm, tokens, inference

A sentence becomes tokens

An LLM is a language model trained on a large amount of text or other data. It uses tokens, which might be words, word pieces or punctuation. A tokenizer maps text to token IDs; an embedding maps IDs to numerical representations. Different tokenizers can split the same text differently.

Follow a tiny prepared example

  1. For illustration, suppose “drink tea” becomes two tokens: drink, tea.
  2. Their representations enter a trained model within its context window.
  3. The model assigns next-token probabilities. A decoding rule chooses a next token; the choice may be sampled rather than always the most likely.

See the reasoning

From text to a continuation

Separate tokenisation from model inference. This is a prepared demonstration, not live code execution.

Tokenise

Hypothetical tokenizer and model
  1. Textdrink teaCurrent focus
  2. Tokensdrink | tea
  3. Next tokenNot chosen

This example assumes two tokens; a real tokenizer may split differently.

Context is not permanent memory

The context window limits the tokens available to a request, including instructions, conversation, retrieved text and generated output according to the implementation. A longer context does not guarantee that all information is used correctly. Inference applies trained parameters; training changes them. A model can be fluent and still be wrong. Check important claims and do not put sensitive data into a service without understanding its privacy rules.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. Is a token always one whole word?
2. What is an input embedding?
3. What is a context window?
4. What is inference?

References and further reading