Tokens, Context, and Language Models
Follow a prompt through tokenisation and prepared next-token inference.
generative ai, llm, tokens, inferenceA 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
- For illustration, suppose “drink tea” becomes two tokens:
drink,tea. - Their representations enter a trained model within its context window.
- 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
- Textdrink teaCurrent focus
- Tokensdrink | tea
- 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.
