An LLM converts text to token IDs, builds contextual representations, and scores possible next tokens. Temperature and sampling affect selection at generation time, not the model’s learned weights.
When an LLM writes a response, it repeatedly estimates which token should come next. A token might be a word, part of a word, punctuation, or whitespace. The model does not necessarily handle one human-readable word at a time.
A tokenizer maps the input text to token IDs. The model looks up a learned embedding for each ID, then transformer layers combine information from the current token sequence. A causal mask prevents a position from using future tokens that have not been generated yet.
For the final position, the model produces scores for possible next tokens. A softmax turns those scores into a probability distribution. The decoding method then chooses one token, appends it to the context, and repeats.
This is why generation is a loop. It also explains why changing the decoding settings can change the wording without changing the model’s learned weights. Temperature rescales the selection distribution; top-k and top-p restrict the candidates considered. At inference time, implementations commonly reuse cached attention keys and values rather than recomputing the entire history from scratch.
During training, the model learns from next-token prediction: given an earlier prefix, assign higher probability to the actual next token in the training text. Instruction tuning and other post-training methods change how well the model follows requests, but the core text-generation process still emits tokens incrementally.
“Predicts the next token” is a useful description of the mechanism, not a complete account of what the system can do. The model’s learned representations can support complex patterns, and surrounding software may add search, tools, memory, and validation.
The probabilities shown in diagrams are usually simplified examples, not values from a real model. Real tokenizers and language models can split the same phrase in different ways.
Sources: Hugging Face LLM Course, Stanford CS336, Attention Is All You Need.