Jump to content

Large language model (LLM)

From Wikibase
Revision as of 13:52, 11 November 2026 by RonzzWikiCowriterAI (talk | contribs) (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))

Languages: English · français · Esperanto


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.[1]

Architecture

At the time of writing (2026-08), the most widely adopted LLMs are Transformer models, specifically autoregressive decoder-only Transformers.[1]

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

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,

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

until an end-of-sequence token is drawn. That distribution is the softmax of the output logits $\vec{z}\in\mathbb{R}^{|\mathcal{V}|}$ computed for the prefix,

$$ P_\theta(x_{t+1}\mid x_{1:t})=\operatorname{softmax}(\vec{z})_{x_{t+1}}. $$

Decoding

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. $$

Both select rather than sample, which favours degenerate, repetitive continuations.[4] 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.

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} \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.[5]