Probability and statistics

y∼Cat⁡(π)y \sim \operatorname{Cat}(\boldsymbol{\pi}) Categorical distribution

Cat(π) picks one of K classes, class k with probability πₖ. It is how a model samples the next token.

In ML papers

Cat⁡(π)\operatorname{Cat}(\boldsymbol{\pi}) is a die with KK faces: it returns class kk with probability πk\pi_k, where the πk\pi_k are non-negative and sum to 1. A classifier's Softmax output is the parameter vector of a categorical distribution, and a language model samples each next token as xt∼Cat⁡(softmax⁡(zt))x_t \sim \operatorname{Cat}(\operatorname{softmax}(\mathbf{z}_t)).

Mult⁡(n,p)\operatorname{Mult}(n, \mathbf{p}), the multinomial, counts how often each class comes up in nn such draws. With n=1n = 1 it is the categorical written as a one-hot vector, which is why some papers say "multinomial" for a single draw.

How to type it

LaTeXShows
\operatorname{Cat}(\boldsymbol{\pi})Cat⁡(π)\operatorname{Cat}(\boldsymbol{\pi})
\operatorname{Categorical}(\mathbf{p})Categorical⁡(p)\operatorname{Categorical}(\mathbf{p})
\operatorname{Mult}(n, \mathbf{p}) multinomialMult⁡(n,p)\operatorname{Mult}(n, \mathbf{p})

A worked example

π=(0.7,0.2,0.1):P(y=2)=0.2\boldsymbol{\pi} = (0.7, 0.2, 0.1): \quad P(y = 2) = 0.2

Sampling 1000 times gives roughly 700 ones, 200 twos and 100 threes.

Common confusions

Related

softmax⁡(z)i=ezi∑jezj\operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_j e^{z_j}}Softmaxm∼Bernoulli⁡(p)m \sim \operatorname{Bernoulli}(p)Bernoulli distributionπ∼Dir⁡(α)\boldsymbol{\pi} \sim \operatorname{Dir}(\boldsymbol{\alpha})Dirichlet distributionx∼pdatax \sim p_{\text{data}}Distributed as (tilde)

Decode this example →