Autoregressive language models (gemini)
Autoregressive language models generate text one token at a time by predicting the probability of the next token based on all the tokens that came before it. Each newly predicted token is appended to the sequence and fed back in as context for the next step, repeating until the model produces an end-of-sequence marker or hits a length limit.
Tokenization & Embeddings
They are two separate steps in sequence. Tokenization chops text into smaller pieces (tokens), while embeddings turn those pieces into lists of numbers (vectors) that capture meaning.
How They Differ
Tokenization splits raw text into words, subwords, or characters and assigns each one a token ID. Embeddings map those token IDs to dense vectors (often hundreds or thousands of numbers) in a multi-dimensional space.
Meaning vs. structure: Token IDs are just labels or index numbers they don't carry meaning on their own. Embeddings encode semantic relationships and context, so similar concepts sit closer together mathematically.
Order of operations: Tokenization always comes first. You slice the text into tokens, look up their IDs, and then convert those IDs into embeddings for a model to process.
How It Works
Causal Self-Attention & Blocks: Data passes through stacked decoder blocks containing masked multi-head self-attention, feed-forward layers, residual connections, and normalization.
Autoregressive Next-Token Prediction: The model scores all vocabulary tokens for the next position, picks one, appends it to the sequence, and repeats this loop until finished.
Transformer architecture
Transformer is a neural network architecture introduced in the 2017 paper "Attention Is All You Need" that processes sequence data in parallel using self-attention instead of reading step-by-step like older recurrent models. It is the core building block behind modern large language models (LLMs) and multimodal AI systems
Embeddings & Positional Encoding: Inputs (like words, subwords, or image patches) are converted into numerical vectors and tagged with position info so the model knows order even while reading everything at once.
Self-Attention & Multi-Head Attention: Each token creates query, key, and value vectors to weigh how strongly tokens relate to one another even across long distances using multiple parallel "heads" to capture different patterns.
Why It Replaced Older Sequence Models
Parallelization: Unlike RNNs or LSTMs that process tokens one by one, transformers compute relationships across whole sequences at once, making better use of GPUs and speeding up training.
Long-Range Context: Direct attention links between distant tokens avoid losing context across long passages.
Next-token prediction
Next-token prediction works as a compression engine rather than a simple word-association table.
To predict the next token accurately across trillions of sentences spanning code, science, dialogue, and arguments a model cannot just memorize surface phrases; it is forced to build internal representations of structure, relationships, and context.
Your second intuition is close to what happens inside the network, with an important distinction: the algorithm is not handed a pre-existing "hidden language" by humans, nor does it understand language the way people do. Instead, it discovers its own internal latent representations (numerical vectors called activations) because tracking underlying patterns is the most efficient way to lower prediction error.
Why Next-Token Prediction Produces Capable Behavior
Compression forces abstraction: Suppose a model must predict the next token in "The detective looked at the bloodstain and realized the butler was..." A shallow lookup table fails on novel phrasing. Learning to predict accurately across diverse stories requires modeling roles, cause-and-effect, tone, and narrative logic.
Context shapes the probability landscape: At every step, the model computes a probability distribution over its vocabulary conditioned on all preceding tokens. A prompt asking for Python code shifts probability mass toward syntax and algorithms; a prompt asking for a poem shifts it toward meter and imagery.
Sequential generation builds on prior choices: Because each selected token becomes part of the input for the next step, multi-step reasoning or structured explanations emerge step by step rather than in a single jump.
Post-training refines behavior: Raw next-token prediction learns from the whole training corpus including unhelpful or messy text. Fine-tuning and preference alignment shape how the model answers questions, follows instructions, and formats responses.
Plausibility and hallucination are direct byproducts of the exact same mechanism that makes next-token prediction work: the model optimizes for what sounds statistically likely to come next, not what is verifiably true in the external world.
Why Plausibility Comes First
Style and structure are easier to learn than specific facts: Across billions of documents, rules of grammar, tone, formatting, and conversational flow repeat constantly. Rare facts like an obscure legal citation or a specific person's birth date appear far less often, so the model learns how an authoritative answer sounds much more reliably than every individual detail inside it.
No built-in truth-checking loop: During standard generation, the model has no separate database lookup or ground-truth sensor verifying each claim before emitting a token. It simply selects from the highest-probability continuations given the context so far.
Pattern completion favors fluency: If a prompt implies an answer exists (for example, asking for a quote from a book that does not exist), the strongest statistical continuation is a smoothly formatted, convincing-sounding quote rather than an admission of ignorance.
If a model only looked at the last word or two (like an early Markov chain), the output would rapidly drift into grammatical nonsense.
Modern LLMs avoid turning the input into garbage because of three specific mechanisms that enforce global structure over local randomness:
1. Full-Context Attention (Not Just "What Follows the Last Word")
A next-token predictor does not predict based on the previous word alone. Through self-attention, every new token attends directly back to all earlier tokens in the prompt and its own generated output simultaneously.
2. Massive Penalty for Garbage During Training
During training, the model is shown billions of real human texts and penalized heavily every time it assigns a high probability to an incoherent or off-topic token.
In real human writing, sentences stay on topic, arguments follow premises, and parentheses close where they opened.
Any internal parameter configuration that lets text drift into gibberish gets a high error score (cross-entropy loss) and is overwritten by gradient descent. Over trillions of updates, only representations that preserve coherence survive.
3. Controlled Sampling (Pruning the "Garbage Tail")
At each step, the model outputs probabilities for tens of thousands of tokens most of which are garbage (near-zero probability). Decoding algorithms cut off that tail before picking a token:
Low temperature sharpens the distribution so the model consistently picks the strongest logical continuation rather than a random outlier.
When those safeguards break for example, if you crank temperature up to 2.0 so the model starts picking low-probability tail tokens the output immediately collapses into the exact kind of word-salad garbage you are describing.
Temperature controls how random or predictable a large language model's (LLM) text output is. Lower values make the model stick to its most likely next word, while higher values give less likely words a better shot.
No single person "invented" the insight in one flash it emerged across several milestones where researchers realized that scaling up simple next-symbol prediction forces neural networks to learn complex reasoning and world knowledge.