Categorical and Multinomial Distributions
Model one labeled outcome with a categorical variable and repeated category counts with a multinomial vector. Use one-hot representations, distinguish sequence from count probability, compute count and proportion moments, and state what order and dependence the model discards.
Categorical and multinomial distributions describe trials with a finite set of possible categories, commonly more than two. A categorical variable records one category. A multinomial variable records how many times each category appears across a fixed number of independent trials with unchanged category probabilities.
One Outcome from Several Categories
Let a variable take one of labels with probability vector:
Then has a categorical distribution. For three weather labels, one possible model is:
| Category | sunny | cloudy | rainy |
|---|---|---|---|
| Probability |
The labels identify alternatives; they need not carry numerical distance or order. Renaming sunny, cloudy, and rainy as , , and does not make “rainy minus cloudy” a meaningful quantity.
A Bernoulli distribution is the two-category case when the labels are encoded as zero and one.
Exercise: Complete a categorical distribution
A three-class distribution assigns probabilities , , and . What is ?
Compute it first, then check your number.
HintNormalize the category probabilities
Subtract the two known probabilities from one.
SolutionAssign all remaining probability mass
A categorical probability vector sums to one:
The result is nonnegative, so the completed vector is valid.
One-Hot Vectors Represent Categories Numerically
A -category outcome is often represented by a one-hot vector . Exactly one component equals one and the others equal zero. For the three weather categories:
The expected one-hot vector is the probability vector itself:
This representation appears in classification. A model produces a probability vector over classes, while the observed class can be encoded as one-hot. A language model's next-token distribution is categorical over its vocabulary.
Exercise: Interpret the expected one-hot vector
For category probabilities , what is the second component of ?
Compute it first, then check your number.
HintAverage each indicator component
The second component equals one exactly when category two occurs.
SolutionAn indicator's expectation is its event probability
The second one-hot component is an indicator for category two. Its expected value is therefore .
Repeated Categories Produce a Count Vector
Repeat the categorical trial times independently with the same probability vector . Let count occurrences of category . The count vector satisfies:
It has a multinomial distribution:
“The probability of the count vector equals the multinomial coefficient times the product, over categories , of raised to count .” The coefficient counts the different orders represented by the same counts.
This formula applies to nonnegative counts whose sum is . The product gives the probability of one particular sequence with those counts. The multinomial coefficient counts how many distinct sequences have the same count vector. As usual, , so a category with zero observations does not alter the coefficient or product.
For , probabilities , and counts :
The three matching sequences are first-first-second, first-second-first, and second-first-first.
Exercise: Compute a multinomial count probability
Two independent trials have category probabilities . What is the probability that category one occurs once, category two occurs once, and category three does not occur?
Compute it first, then check your number.
HintCount the two possible orders
The matching sequences have probabilities and .
SolutionAdd both arrangements of the counts
The multinomial coefficient is , so:
Counting only one order would miss half of the required event.
A Sequence and Its Count Vector Are Different Events
For probabilities , the exact ordered sequence first-first-second has probability:
The count event includes three ordered sequences, so its probability is . The multinomial coefficient appears only because the count vector groups several sequences together.
This distinction matters in language. A token sequence model assigns probability to an order. A multinomial bag-of-words model assigns probability to counts and deliberately discards order.
Exercise: Separate sequence probability from count probability
Three independent categorical trials use probabilities . What is the probability of the exact ordered sequence first-second-first?
Compute it first, then check your number.
HintDo not add other orders
Multiply the probabilities in the specified order: .
SolutionMultiply one specified sequence
The exact sequence has probability:
No combinatorial coefficient is used because the prompt names one order, rather than every sequence containing two first-category outcomes.
Means, Variances, and Dependence among Counts
Each individual count has mean and variance:
Increasing moves more expected count toward category because . The probabilities must still sum to one, so increasing one category's probability requires decreasing one or more of the others. Increasing scales every expected count in proportion to the number of trials, while the observed proportions become more stable around the probability vector as the sample grows.
Viewed alone, has a binomial distribution. However, the counts are not independent because their sum is fixed. For :
An extra occurrence in one category leaves one fewer trial available for the others, producing negative covariance.
Exercise: Compute an expected category count
For trials and category probabilities , what is ?
Compute it first, then check your number.
HintMultiply total trials by the category probability
Use .
SolutionAdd the expected indicators for category two
The expected count is:
Other count values remain possible; is the distribution's mean for that component.
Count Proportions Estimate Category Probabilities
Define the empirical category proportion:
Scaling the count moments gives:
The proportions always satisfy . Their negative covariances also shrink with sample size:
As grows, empirical proportions tend to concentrate around the probability vector, while individual samples still fluctuate.
Exercise: Compute the variance of a category proportion
For independent categorical trials with , what is ?
Compute it first, then check your number.
HintScale the indicator variance by sample size
Use .
SolutionMeasure the spread of an empirical proportion
The variance is:
Increasing the number of trials reduces this variance because the empirical proportion averages more categorical indicators.
Choose the Distribution by the Recorded Object
The same trial can lead to different random variables:
| Recorded object | Distribution |
|---|---|
| one binary outcome | Bernoulli |
| number of successes in repeated binary trials | Binomial |
| one outcome among categories | Categorical |
| vector of category counts across repeated trials | Multinomial |
If order is retained, a full sequence of categorical variables is being modeled; the multinomial count vector discards that order. Two documents with the same token counts but different token sequences have the same count vector, so a multinomial bag-of-words model cannot distinguish them.
Exercise: Choose the matching distribution
A document contains independently sampled tokens from a three-token vocabulary. Only the count of each token is recorded. Which distribution models the three counts under these assumptions?
Select one choice, then check.
HintIdentify what was repeated and retained
There are many multi-category trials, and the recorded object is a count vector.
SolutionMatch the multinomial count vector
One token draw is categorical. Repeating the draw times and retaining one count per category gives a multinomial distribution, provided the draws are independent and share one fixed probability vector.
Check the Repeated-Trial Assumptions
The multinomial model requires a fixed number of independent trials and one unchanged categorical probability vector. Natural language tokens generally do not satisfy this assumption: the next-token distribution changes with context, and nearby tokens are dependent. A multinomial token-count model can still be a deliberate approximation, but its limitations should be explicit.
Simulate Categorical Draws and Count Them
Compare multinomial counts with expected counts
Change the category probabilities, trial count, or seed. Compare one simulated count vector with its expectation.
Ready to run.
One sample need not equal its expected count vector. Repeating the complete experiment and averaging its counts would approach the expectation.
Before Choosing a Multi-Category Distribution
Use categorical for one labeled outcome and multinomial for a vector of counts from repeated independent categorical trials with fixed probabilities. Decide whether order has been discarded, verify normalization, and state whether the independence and constant-probability assumptions are exact or approximate.
The next lessons turn to continuous distributions, where probability belongs to intervals and regions rather than individual points.