Jump to content

Large language model (LLM): Difference between revisions

From Wikibase
Rewrite Inference: denser math, softmax and temperature formulas referenced out to Softmax instead of restated, KV caching and self-attention referenced (via update-page on MediaWiki MCP Server)
Make the article architecture-neutral: move decoding policies to Decoding, attention cost to Self-attention and KV caching, architecture specifics to Autoregressive decoder-only Transformers (via update-page on MediaWiki MCP Server)
Line 2: Line 2:
[[Category:Natural language processing]]
[[Category:Natural language processing]]


A '''large language model''' ('''LLM''') is an [[artificial intelligence]] system built as a [[neural network]] with a very large parameter count, typically based on the [[Transformer]] architecture, trained by [[machine learning]] on broad text corpora to generate text in response to prompts.<ref>{{#cite:Q3130}}</ref>
A '''large language model''' ('''LLM''') is a [[neural network]] with a very large parameter count, trained by [[machine learning]] on broad text corpora to model the distribution of token sequences, so that it can generate text in response to a prompt. The definition rests on scale, and on the modelling of text, rather than on any 1 architecture.


== Architecture ==
== Architecture ==


At the time of writing (2026-08), the most widely adopted LLMs are [[Transformer]] models, specifically [[autoregressive decoder-only Transformer]]s.<ref>{{#cite:Q3130}}</ref>
LLMs are built from several architectures, which differ in how they model text and in how they generate it. The dominant family at the time of writing (2026-08) is the [[autoregressive decoder-only Transformers]], and how it differs from the alternatives is set out there.<ref>{{#cite:Q3130}}</ref> What every family shares, and what the rest of this article relies on, is a distribution over token sequences.


== Scaling laws ==
== Scaling laws ==
Line 20: Line 20:
== Inference ==
== Inference ==


Generation is autoregressive: the model runs once per token, each run emitting one token from the distribution over the vocabulary $\mathcal{V}$ and appending it to the context,
Inference produces an output sequence $y_1,\cdots,y_N$ from an input $x$ by drawing on the distribution the model defines over token sequences,


$$
$$
x_{t+1}\sim P_\theta(\cdot\mid x_{1:t}),
y\sim P_\theta(\cdot\mid x).
$$
$$


until an end-of-sequence token is drawn. That distribution is the [[Softmax|softmax]] of the output logits $\vec{z}\in\mathbb{R}^{|\mathcal{V}|}$ computed for the prefix,
2 properties hold whatever the architecture. The most probable output is in general unavailable, because it is a maximiser over a space of size $|\mathcal{V}|^{N}$,


$$
$$
P_\theta(x_{t+1}\mid x_{1:t})=\operatorname{softmax}(\vec{z})_{x_{t+1}}.
y^\star=\arg\max_{y\in\mathcal{V}^{N}}P_\theta(y\mid x),
$$
$$


=== Decoding ===
and that space cannot be enumerated. Models therefore impose a factorisation that lets the sequence be built a piece at a time, the dominant one being the autoregressive chain rule,
 
Greedy search takes the mode of the distribution, and beam search extends the $b$ prefixes of highest likelihood at each step,


$$
$$
x_{t+1}=\arg\max_{v\in\mathcal{V}}\operatorname{softmax}(\vec{z})_{v}=\arg\max_{v\in\mathcal{V}}z_v.
P_\theta(y\mid x)=\prod_{t=1}^{N}P_\theta(y_t\mid x,y_{1:t-1}),
$$
$$


Both select rather than sample, which favours degenerate, repetitive continuations.<ref>{{#cite:Q3198}}</ref> Temperature sampling instead draws from the temperature-scaled softmax $\operatorname{softmax}(\vec{z}/\tau)$ with $\tau>0$: its one-hot limit $\tau\to0^{+}$ recovers greedy search, and $\tau\to\infty$ approaches the uniform distribution.
which replaces 1 intractable search by $N$ tractable draws. Taking the mode at each of those draws is greedy decoding,
 
Top-$p$ (nucleus) sampling keeps the smallest set of tokens carrying probability mass $p$ and renormalises onto it,
 
$$
\mathcal{S}_p=\operatorname*{arg\,min}_{\substack{S\subseteq\mathcal{V}\\ \sum_{v\in S}P_\theta(v\mid x_{1:t})\ge p}}|S|,
\qquad
x_{t+1}\sim\frac{P_\theta(\cdot\mid x_{1:t})\,\mathbb{1}_{\mathcal{S}_p}}{\sum_{v\in\mathcal{S}_p}P_\theta(v\mid x_{1:t})}.
$$
 
=== Cost ===
 
The score matrix of [[self-attention]] is $\mathbf{S}=\mathbf{Q}\mathbf{K}^{\top}/\sqrt{d}\in\mathbb{R}^{T\times T}$ for queries and keys $\mathbf{Q},\mathbf{K}\in\mathbb{R}^{T\times d}$, so attention over a context of length $T$ costs $\mathcal{O}(T^2d)$ time and $\mathcal{O}(T^2)$ memory. Generating $T$ tokens therefore totals


$$
$$
\begin{cases}
\hat{y}_t=\arg\max_{v\in\mathcal{V}}P_\theta(v\mid x,\hat{y}_{1:t-1}),
\sum_{t=1}^{T}\mathcal{O}(t^2d)=\mathcal{O}(T^3d) \quad\text{recomputing the prefix at each step} \\
\sum_{t=1}^{T}\mathcal{O}(td)=\mathcal{O}(T^2d) \quad\text{reusing cached keys and values}
\end{cases}
$$
$$


[[KV caching]] stores the keys and values of earlier positions, which is what removes the recomputation, at the cost of $2Td$ scalars per layer.<ref>{{#cite:Q3192}}</ref>
and it is generally not $y^\star$: the locally most probable token need not begin the globally most probable sequence. The policies for choosing $y$, from beam search to sampling, are treated at [[decoding]], and what a step costs is a property of the architecture rather than of inference, as developed at [[self-attention]] and [[KV caching]].

Revision as of 14:01, 11 November 2026

Languages: English · français · Esperanto


A large language model (LLM) is a neural network with a very large parameter count, trained by machine learning on broad text corpora to model the distribution of token sequences, so that it can generate text in response to a prompt. The definition rests on scale, and on the modelling of text, rather than on any 1 architecture.

Architecture

LLMs are built from several architectures, which differ in how they model text and in how they generate it. The dominant family at the time of writing (2026-08) is the autoregressive decoder-only Transformers, and how it differs from the alternatives is set out there.[1] What every family shares, and what the rest of this article relies on, is a distribution over token sequences.

Scaling laws

The performance of LLMs improves predictably with

  • model size
  • training-data volume
  • computational budget

Language model loss and Chinchilla prescription describe the correlation.[2][3]

Inference

Inference produces an output sequence $y_1,\cdots,y_N$ from an input $x$ by drawing on the distribution the model defines over token sequences,

$$ y\sim P_\theta(\cdot\mid x). $$

2 properties hold whatever the architecture. The most probable output is in general unavailable, because it is a maximiser over a space of size $|\mathcal{V}|^{N}$,

$$ y^\star=\arg\max_{y\in\mathcal{V}^{N}}P_\theta(y\mid x), $$

and that space cannot be enumerated. Models therefore impose a factorisation that lets the sequence be built a piece at a time, the dominant one being the autoregressive chain rule,

$$ P_\theta(y\mid x)=\prod_{t=1}^{N}P_\theta(y_t\mid x,y_{1:t-1}), $$

which replaces 1 intractable search by $N$ tractable draws. Taking the mode at each of those draws is greedy decoding,

$$ \hat{y}_t=\arg\max_{v\in\mathcal{V}}P_\theta(v\mid x,\hat{y}_{1:t-1}), $$

and it is generally not $y^\star$: the locally most probable token need not begin the globally most probable sequence. The policies for choosing $y$, from beam search to sampling, are treated at decoding, and what a step costs is a property of the architecture rather than of inference, as developed at self-attention and KV caching.