
Language Models · v1.0.3
2026-11-03 01:40:25

Builds on
Supplies

Neural networks operate on continuous values; text is categorical. An embedding maps discrete tokens into a continuous vector space.
\[E : V \to \mathbb{R}^{d}, \qquad \mathbf{W} \in \mathbb{R}^{|V| \times d}\]
Since \(V\) is finite, \(E\) is fully described by a matrix with one row per token. GPT-2 uses \(d = 768\); the largest GPT-3 model uses \(d = 12{,}288\).
Higher dimensionality captures more nuance, at the cost of computation.



\[V = \operatorname{sorted}(\operatorname{set}(T(\text{corpus})))\]
encode and decodedecode must re-attach punctuation, so the round trip holds only up to whitespace
<|unk|> and <|endoftext|> appended as the two highest IDs.Encoding a word absent from the corpus raises a lookup error — a property of a closed vocabulary, not a bug.
<|unk|> substitutes for an out-of-vocabulary word, so no lookup can miss<|endoftext|> separates unrelated documents in the stream[BOS], [EOS], [PAD] exist elsewhere; GPT uses none of them
BPE trained GPT-2, GPT-3 and the original ChatGPT model.
<|unk|> is ever required<|endoftext|> is ID 50256Every character is present from the start, so encoding always terminates — in the worst case, character by character.

\[\mathbf{x}^{(i)} = (t_i, \dots, t_{i+n-1})\] \[\mathbf{y}^{(i)} = (t_{i+1}, \dots, t_{i+n})\]


max_length fixes the context size \(n\); stride advances the window
\[E(t) = \mathbf{W}_{t,:} = \mathbf{e}_t^{\top}\mathbf{W}\]

Self-attention has no notion of order, so position is injected separately.
\[\mathbf{Z}_{b,i,:} = E_{\text{tok}}(t_{b,i}) + E_{\text{pos}}(i)\]
The addition broadcasts: one \(n \times d\) positional matrix serves every example in the batch.
The pipeline delivers a tensor of shape (batch \(\times\) context length \(\times\) embedding dimension) — the input to unit 3, Coding attention mechanisms.