← AI Knowledge Home
05 · Tokens, Context & Inference

How a Language Model Turns Your Input into an Answer

This module explains how text becomes tokens, enters the model’s context, and is processed during inference to generate an answer one token at a time.

Follow one request from raw text to generated output.

The Big Picture · inference timeline

From user text to final response

USER TEXTRaw input from a person or application
↓
TOKENIZATIONText is split into token units
↓
TOKENSUnits the model processes
↓
CONTEXT WINDOWInformation available for this run
↓
INFERENCEThe trained model processes the context
↓
NEXT-TOKEN PREDICTIONCalculate probabilities for possible next tokens
↓
SAMPLINGA generation method selects the next token
↓
GENERATED TOKEN ↺ REPEATAdd it to the sequence until a final response is complete
Knowledge Map

Understand each idea by its role

A · INPUT

Tokenization

Converts raw text into tokens.

Token

A unit processed by the model.

B · CONTEXT

Context Window

The amount of information available during a run.

C · EXECUTION

Inference

Running the trained model on current input.

Next-token Prediction

Calculating probabilities for possible next tokens.

Key Distinctions

Connected concepts, different jobs

TokenModel input unit≠WordHuman language unit
TokenizationConversion process≠TokenResulting unit
Context WindowAvailable request information≠MemoryPersistent state across work
InferenceRunning a trained model≠TrainingChanging learned parameters
PredictionScores possibilities≠SamplingSelects one option
KV CacheEfficiency support≠Context WindowAvailable context
Recommended Learning Path

Learn the flow in order

This is a learning path, not a strict software pipeline.

01Tokenization

How text is converted.

02Token

What the model processes.

03Context Window

What is available.

04Inference

How the model runs.

05Prediction

How options are scored.

06Sampling

How one token is selected.

07KV Cache

How repeated work is reduced.

Remember the flow
Text is tokenized, placed into context, processed during inference, and generated one token at a time through prediction and sampling.