Language modeling
Algorithms
- Deleted interpolation
Mix the n-gram estimates of every order with weights fitted by EM on held-out data, often in buckets by the count of the history.
1 languagescore - Good-Turing estimation
Estimate the total chance of the unseen types as N_1/N and replace each count r by r* = (r+1) N_(r+1) / N_r, where N_r is the number of types seen r times.
1 languagescore - Katz backoff
An n-gram model that uses discounted counts for the n-grams it has seen and backs off to the shorter history, scaled by a weight alpha(h), for the ones it has not.
1 languagescore - Kneser-Ney smoothing
Absolute discounting whose lower order model uses continuation counts, the number of distinct contexts a word follows, rather than raw counts.
1 languagescore - Multi-head attention
Run h attention heads in parallel on learned low-dimension projections of queries, keys and values, then concatenate and project the outputs.
1 languagescore - Scaled dot-product attention
Output softmax(Q K^T / sqrt(d_k)) V: each query gets a mix of the value vectors, weighted by how well each key matches it. Costs O(n^2 d) for n tokens.
1 languagescore - Witten-Bell smoothing
Interpolate each n-gram estimate with the lower order, giving the lower order the weight T(h)/(c(h) + T(h)), where T(h) is the number of distinct words seen after the history h.
1 languagescore - Entropy-based n-gram pruning
Remove the n-grams whose removal least raises the relative entropy between the original and pruned backoff models, below a threshold.
1 languagesadvanced - Modified Kneser-Ney smoothing
Kneser-Ney with three discounts, for counts one, two and three or more, set from counts of counts. The best n-gram smoothing in the measurements of Chen and Goodman.
1 languagesadvanced - Simple Good-Turing
Good-Turing with smoothed counts of counts: fit log N_r against log r by a line, and use it in place of the raw N_r once the two estimates no longer differ significantly.
1 languagesadvanced - Stupid backoff
Unnormalized scores for very large n-gram models: the relative frequency if seen, else 0.4 times the score of the shorter n-gram.
1 languagesadvanced - Direct preference optimization
Fit a language model to preference pairs with a logistic loss on the difference of its log-ratios to a frozen reference model. It optimizes the RLHF objective with no reward model and no sampling.
1 languagesresearch - FlashAttention
Exact attention computed in tiles that fit in fast on-chip memory with an online softmax, so the n by n score matrix is never written out.
1 languagesresearch - Low-rank adaptation
Fine-tune a large model by freezing a weight matrix W0 and training a rank-r update B A, scaled by alpha / r and zero at the start. The update merges into W0, so inference costs nothing extra.
1 languagesresearch
Techniques
- Laplace smoothing
Add one, or a constant k, to every count before normalizing, so no event gets zero probability. Simple, but with a large vocabulary it takes too much mass from seen events.
intro - Absolute discounting
Subtract a fixed discount D from every nonzero n-gram count and give the freed mass to the lower-order model, with D often set to N_1 / (N_1 + 2 N_2).
core - Causal language modeling
Train a network to predict each token from the tokens before it, with a triangular attention mask so no position sees the future.
core - Masked language modeling
Train a bidirectional encoder to recover tokens that were masked or replaced at random positions from the rest of the sentence.
core - Sinusoidal positional encoding
Add to each token vector sines and cosines of its position at geometrically spaced frequencies, so attention can use word order.
1 languagescore - Noise-contrastive estimation
Fit an unnormalized model by logistic regression that tells data samples from noise samples. It avoids the full softmax over a large vocabulary.
advanced - Rotary position embedding
Rotate pairs of query and key coordinates by angles proportional to position, so that their dot product depends only on the relative offset.
1 languagesadvanced - Attention with linear biases
Add to each attention score a penalty linear in the distance between query and key, with a fixed slope per head, instead of position vectors.
1 languagesresearch - Chain-of-thought prompting
Put worked reasoning steps into the prompt so that a language model writes steps before its answer. Measured gains on multi-step problems appeared only in models of about 100B parameters.
research - Grouped-query attention
Let groups of query heads share one key head and one value head, which shrinks the key-value cache with little loss in quality.
1 languagesresearch - Instruction tuning
Fine-tune a pretrained language model on tasks written as instructions with answers. Measured gains on unseen tasks appear in large models; FLAN models of 8B and below got worse.
research - Reinforcement learning from human feedback
Fit a reward model to human comparisons of outputs, then tune the language model by policy gradient to raise reward under a KL penalty.
research - Replaced token detection
Pretrain an encoder to tell, at every position, whether a small generator network replaced the token, which learns from all positions.
research
Concepts
- In-context learning
A pretrained language model does a new task from an instruction and a few solved examples in its prompt, with no change to its weights. How well it works is measured, not proved.
research - Neural scaling law
Fitted, measured power laws for how the test loss of language models falls with parameters, data and compute. Kaplan et al. (2020) and Hoffmann et al. (2022) fitted different laws.
research
Definitions
- Language model
A probability distribution over finite sequences of tokens, written by the chain rule as a product of the probabilities of each token given those before it, with an end marker.
intro - Perplexity
The exponential of a model's per-token cross-entropy on held-out text, exp(H) in nats or 2^H in bits, which is the inverse geometric mean of the token probabilities. Lower is better.
intro
Models
- N-gram language model
A language model that conditions each token only on the n - 1 tokens before it, with probabilities estimated from counts in a corpus and smoothed to fill the zeros.
intro - Neural probabilistic language model
Bengio's model that concatenates learned vectors of the previous n - 1 words and feeds them through a hidden layer to a softmax over the vocabulary.
core - Recurrent neural network language model
A language model whose recurrent hidden state summarizes the whole history and gives a softmax over the next word at each step.
core - Transformer
A network of stacked blocks of self-attention and feedforward layers with residual connections and normalization, with no recurrence.
core - BERT
A transformer encoder pretrained by masked language modeling and next sentence prediction, then fine-tuned with a small head per task.
advanced - Cache language model
Interpolate a static language model with a unigram or bigram model of the recent words in the document, since words just used tend to recur.
advanced - Generative pretrained transformer
A transformer decoder pretrained by causal language modeling on a large corpus, then fine-tuned or prompted for downstream tasks.
advanced - Maximum entropy language model
A log-linear model of the next word given features of the history, such as n-grams and triggers, fit to match feature expectations.
advanced - Preference reward model
A network that scores a response so that the chance one response is preferred to another is the sigmoid of the score difference.
research - Selective state space model
A linear recurrent layer whose state matrices depend on the input, computed by a parallel scan in time linear in sequence length.
research