Large Language Models

Established

Modern text generation is dominated by the Decoder-Only Transformer, trained primarily on next-token prediction.

The Lifecycle: Pretraining, Post-training, and Inference

A modern LLM undergoes distinct lifecycle stages that dictate what interventions are possible:

Architecture: The Transformer Backbone

Interpretive intuition

Avoid anthropomorphizing "attention." Self-attention is a learned routing mechanism. It allows a token representation at layer N to mix in information from previous tokens before passing to layer N+1. It does not "understand" text; it performs a mathematically optimized information retrieval over the context window.

During inference, models utilize a KV Cache (Key-Value cache). Instead of recalculating attention for the whole prompt on every single generated word, the model caches the intermediate states of previous tokens, drastically reducing compute at the cost of high memory usage.

Sampling: Temperature & Top-P

The neural network outputs a vector of raw scores (logits) for every possible next token. We convert these to probabilities using a softmax function, modified by Temperature and Top-P (Nucleus Sampling).

Output string:
Interactive: Observe how high temperature flattens probabilities. Click 'Sample Token' to draw a word using the displayed probability weights.

References