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)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[[Category:Large language models]]
[[Category:Large language model]]
[[Category:Natural language processing]]
[[Category:Natural language processing]]
 
A '''large language model''' ('''LLM''') is an [[artificial neural network (ANN)]] 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.
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>


== 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>
The dominant architecture at the time of writing (2026-11) is the [[autoregressive decoder-only Transformer]].<ref>{{#cite:Q3130}}</ref>  


== Scaling laws ==
== Scaling laws ==
Line 20: Line 19:
== 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,
With [[tokenisation (machine learning)#Definition|token vocabulary]] $\mathcal{V}$, given input $x$, '''inference''' produces output [[token (machine learning)|token]] sequence $y=(y_1,\cdots,y_T) \in \mathcal{V}^T$ chosen probabilistically:


$$
$$
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,
{{Hidden example}}
With prompt $x=$ `"The capital of France is"`, 3 independent inferences with a typical, well-trained LLM may give:


$$
$$
P_\theta(x_{t+1}\mid x_{1:t})=\operatorname{softmax}(\vec{z})_{x_{t+1}}.
y^{(1)}=\texttt{"Paris."},\qquad
y^{(2)}=\texttt{"Paris, a city on the Seine."},\qquad
y^{(3)}=\texttt{"Lyon, argued some."}
$$
$$
{{End hidden}}


=== Decoding ===
=== Computational limitation ===
 
Greedy search takes the mode of the distribution, and beam search extends the $b$ prefixes of highest likelihood at each step,


The globally most probable output sequence
$$
$$
x_{t+1}=\arg\max_{v\in\mathcal{V}}\operatorname{softmax}(\vec{z})_{v}=\arg\max_{v\in\mathcal{V}}z_v.
y^\star=\arg\max_{y\in\mathcal{V}^T}P_\theta(y\mid x)
$$
$$


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.
is calculated by a maximiser [[function]] over a space of size $|\mathcal{V}|^T \to \infty$, which cannot be enumerated for long sequences (large $T$). The output sequence must be generated sequentially in smaller steps (e.g., 1 to a few tokens).


Top-$p$ (nucleus) sampling keeps the smallest set of tokens carrying probability mass $p$ and renormalises onto it,
=== Typical implementation: sequential next token prediction ===


[[File:Sequential next-token prediction.png|thumbnail|'''Sequential next token prediction''' starting with prompt <code>the</code> with ChatGPT3.]]
$$
$$
\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|,
\vec{z}_t=f_\theta\left(x,y_{1:t-1}\right)\in\mathbb{R}^{|\mathcal{V}|},\\
\qquad
y_t\sim\operatorname{Categorical}\left(\mathrm{softmax}\left(\vec{z}_t\right)\right).
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 ===
where $f_\theta$ is the model [[forward pass]] with [[model parameters]] $\theta$, and $\operatorname{Categorical(\cdot)}$ denotes the [[categorical distribution]] given probability vector $\cdot$.
 
 
<blockquote>
In '''sequential next token prediction''', the LLM first determines $y_1$ based on $x$, then determines $y_2$ based on $x,y_1$, $y_3$ based on $x,y_1,y_2$, so on so forth.
</blockquote>


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
== Application ==


$$
=== Thinking partner ===
\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.<ref>{{#cite:Q3192}}</ref>
For example, [[Person:Yoochul Kim]] employed various LLMs as his thinking partner for his philosophical thought experiments [[OntoMotoOS]].<ref>{{#cite:Q3426}}</ref>

Latest revision as of 14:38, 17 November 2026

Languages: English · français · Esperanto

A large language model (LLM) is an artificial neural network (ANN) 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.

Architecture

The dominant architecture at the time of writing (2026-11) is the autoregressive decoder-only Transformer.[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

With token vocabulary $\mathcal{V}$, given input $x$, inference produces output token sequence $y=(y_1,\cdots,y_T) \in \mathcal{V}^T$ chosen probabilistically:

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

Computational limitation

The globally most probable output sequence $$ y^\star=\arg\max_{y\in\mathcal{V}^T}P_\theta(y\mid x) $$

is calculated by a maximiser function over a space of size $|\mathcal{V}|^T \to \infty$, which cannot be enumerated for long sequences (large $T$). The output sequence must be generated sequentially in smaller steps (e.g., 1 to a few tokens).

Typical implementation: sequential next token prediction

Sequential next token prediction starting with prompt the with ChatGPT3. · Open in a new tab

$$\begin{gathered} \vec{z}_t=f_\theta\left(x,y_{1:t-1}\right)\in\mathbb{R}^{|\mathcal{V}|},\\ y_t\sim\operatorname{Categorical}\left(\mathrm{softmax}\left(\vec{z}_t\right)\right). \end{gathered}$$

where $f_\theta$ is the model forward pass with model parameters $\theta$, and $\operatorname{Categorical(\cdot)}$ denotes the categorical distribution given probability vector $\cdot$.


In sequential next token prediction, the LLM first determines $y_1$ based on $x$, then determines $y_2$ based on $x,y_1$, $y_3$ based on $x,y_1,y_2$, so on so forth.

Application

Thinking partner

For example, Yoochul Kim employed various LLMs as his thinking partner for his philosophical thought experiments OntoMotoOS.[4]