Before you can say how likely something is, you often need to know how many things could have happened. This lesson is about counting: why you can never brute-force an LLM's output space, how many ways there are to pick an eval set, and the distribution that turns "k correct out of n" into a probability.
Lessons 3 and 4 quietly assumed you already knew the list of possible outcomes. In practice that list is the hard part. A model with a 50,000-token vocabulary has far more than 50,000 possible outputs, because outputs are sequences. An eval harness has an enormous number of possible test sets you could have drawn. Combinatorics counts those possibilities, and it feeds probability: when outcomes are equally likely, a probability is a count of the outcomes you care about divided by a count of all outcomes.
The multiplication rule says: if a process has several steps, and step 1 can go a ways, step 2 can go b ways (whatever happened in step 1), and step 3 can go c ways, then the whole process can go a × b × c ways. Choices at each step multiply; they do not add.
Here is the smallest possible language model: a vocabulary of V = 3 tokens (A, B, C) and outputs of length n = 2. The first token has 3 choices. For each of those, the second token has 3 choices. The tree below draws every path.
Every path from the start to the bottom row is one distinct output sequence. Add one more level and each of the 9 boxes sprouts 3 more: 27 sequences.
With vocabulary size V and sequence length n, the count is V × V × … × V (n times) = Vn. Now put in real-sized numbers. Take V = 50,000 tokens, a plausible order of magnitude from Lesson 4:
A 20-token reply is a short sentence. The number of distinct token strings of that length is a 94-digit number, far too many to list, let alone score. Most of those strings are gibberish and the model gives them near-zero probability, but you cannot enumerate even the sensible ones.
Exhaustively testing a prompt template (10 slots with 20 fillers each is 2010 = 10,240,000,000,000 variants), searching all outputs for the single best one, and proving a model never says X all fail on this arithmetic. Decoders build answers one token at a time instead, and you estimate how often something happens by sampling (Lesson 5).
Two questions sound alike and have very different answers. Say a RAG system retrieved 20 candidate chunks and you will paste 5 of them into the prompt.
That division is the whole idea behind the formula for "n choose k", written C(n, k) or ⁿCₖ:
Read it as: n! arranges all n items, (n − k)! cancels the arrangements of the items you did not pick, and k! cancels the arrangements within the group you did pick. Check by hand: choose 3 of 10 prompts to review. Ordered: 10 × 9 × 8 = 720; each set appears 3! = 6 times, so C(10, 3) = 120.
The numbers C(n, k) have a pattern you can build with addition alone. To choose k items from n, look at one particular item. Either it is in your group (then choose the other k − 1 from the remaining n − 1) or it is not (then choose all k from the remaining n − 1). So:
Stack these into rows and you get Pascal's triangle, where each entry is the sum of the two above it:
This is the bridge to Lesson 4. A Bernoulli is one yes/no trial with success probability p. Now run n independent Bernoulli trials with the same p and ask: how many successes? The count k follows a binomial distribution.
Build the formula from what you already have. One specific pattern with exactly k successes, say the first k trials succeed and the rest fail, has probability pk(1 − p)n−k, because independent probabilities multiply (Lesson 3). But the k successes could land on any k of the n trials, and there are C(n, k) ways to choose which. Every such pattern has the same probability, so:
The mean and variance come from treating the count as a sum of n Bernoulli trials: the mean of a sum is the sum of the means (np), and for independent trials the variances add too (n × p(1 − p)). Lesson 12 derives both rules.
A team runs a model on n = 10 test prompts. Suppose the model's true per-prompt success rate is p = 0.8 (so each prompt is an independent Bernoulli trial with p = 0.8, an assumption we come back to in the pitfall below). What is the chance it gets exactly 8 right?
Binomial with n = 10, p = 0.8. Even when the model is truly 80% accurate, the score it earns on 10 prompts is a spread, not a single number.
Even at the most likely score (8 of 10), the model hits it only about 30% of the time. P(k ≥ 8) = 0.302 + 0.268 + 0.107 = 0.678, and P(k ≤ 6) = 0.121: an honestly 80%-accurate model scores 6/10 or worse about one run in eight.
Run it the other way, the way a real team does. You see 8 of 10 and wonder what the true p is. Under p = 0.6 the same data has probability C(10, 8) × 0.68 × 0.42 = 45 × 0.016796 × 0.16 = 0.121. Under p = 0.95 it is 45 × 0.958 × 0.052 = 0.075. Both are only about 2.5 to 4 times less likely than 0.302 (0.302 / 0.121 ≈ 2.5, 0.302 / 0.075 ≈ 4.0). A small eval makes a 60% or a 95% model less plausible than an 80% one, but it cannot rule either out. Lesson 5 turns this observation into confidence intervals and maximum likelihood.
More prompts shrink the relative noise. With n = 100 and p = 0.8: sd = √(100 × 0.8 × 0.2) = √16 = 4 correct answers, which is 4 percentage points on the accuracy. The sd of the proportion is √(p(1 − p)/n) = 0.04. With 10 prompts the same formula gives 0.126, three times bigger.
When you pick an eval set of 100 prompts out of a pool of 1,000, you do not pick the same prompt twice. That is sampling without replacement, and the count of possible subsets is C(1,000, 100), a 140-digit number (about 10140). The same logic gives you the size of other familiar choices:
| Choice | Count | Size |
|---|---|---|
| 100-prompt eval subset from a pool of 1,000 | C(1,000, 100) | about 10140 |
| 200 validation examples from 1,000 (an 80/20 split) | C(1,000, 200) | 216 digits |
Two people who each draw a "random" split will essentially never draw the same one, so a single lucky or unlucky split is possible. That is why serious reports show several splits or a confidence interval.
Cross-validation cuts the data into k folds of equal size. Count the ways on a small case: 20 examples into 5 labeled folds of 4. Choose 4 for fold 1 from 20, then 4 for fold 2 from the remaining 16, and so on:
The folds are interchangeable in practice (it does not matter which one you call "fold 1"), so divide by the 5! = 120 relabelings: 305,540,235,000 ÷ 120 = 2,546,168,625 genuinely different ways to partition 20 examples into 5 folds of 4. Any one run of k-fold uses just one of them.
This is the without-replacement version of the binomial, the hypergeometric count. A dataset of N = 1,000 prompts contains 100 mislabeled ones (10%). You hand-audit a random 50. On average you expect 50 × 100 / 1,000 = 5 mislabeled prompts. What is the chance your audit finds none? Count the audits that avoid all 100 bad prompts (choose 50 of the 900 good ones) over all possible audits:
A 50-prompt audit almost certainly spots a 10% problem. For a 1% problem (10 bad in 1,000) you expect only 50 × 10 / 1,000 = 0.5 hits, and C(990, 50) / C(1,000, 50) ≈ 0.60 says the audit finds nothing about 60% of the time. An audit sized for common problems says little about rare ones.
Counting also explains a surprise: duplicates appear far sooner than intuition suggests. Pick n items at random from N possible values and the number of pairs is n(n − 1)/2, which grows like n2. Each pair collides with probability about 1/N. So the expected number of colliding pairs is roughly:
This is the birthday effect, and it matters for deduplication. Say a team deduplicates a training corpus by giving each document a 32-bit hash (N = 232 = 4,294,967,296 possible values) and treating equal hashes as equal documents:
| Documents n | Pairs n(n−1)/2 | Expected colliding pairs | P(at least one) |
|---|---|---|---|
| 10,000 | 49,995,000 | 0.0116 | 1.2% |
| 100,000 | 4,999,950,000 | 1.16 | 68.8% |
With a hash space of over 4 billion values, 100,000 documents already collide about 69% of the time. Counting it exactly, the 50% mark is reached at 77,164 documents, about √N rather than N. Practical result: a corpus of millions of documents will have distinct documents treated as duplicates under a 32-bit hash. A 64-bit hash (N = 264 ≈ 1.8 × 1019) with 109 documents gives expected collisions of 109 × (109 − 1) / (2 × 264) ≈ 0.027, small enough to ignore.
Top-k sampling restricts each next-token draw to the k highest-probability tokens (Lesson 10 treats the mechanics). Combinatorics tells you two things about it.
Any pass/fail eval is a binomial count. Before comparing two models that scored 82/100 and 79/100, note that each has an sd of about 4 correct answers, so a 3-point gap is well within noise. Check this first when a "win" shows up on a small test set.
Report variability across several splits, size audits for the problem rate you care about, and size hashes from n2/(2N), not from n alone.
Here the focus was counting outcomes and the count of successes. The next step is to treat a number attached to a random outcome, such as the count of correct answers, the latency of a request, or the loss on a batch, as an object in its own right. That is a random variable, and its long-run average is its expectation. The binomial's np and np(1 − p) were your first two examples.
1. A model has a 1,000-token vocabulary and generates replies exactly 4 tokens long. How many distinct 4-token sequences exist?
2. You will choose which 3 of 10 candidate prompts to include in a review batch and the order inside the batch is irrelevant. How many different batches are there?
3. A model's true per-prompt success rate is 0.8 and you test 10 independent prompts. What are the mean and variance of the number of correct answers?
4. A team's eval prompts are 100 near-paraphrases of the same 10 base questions. Why is the binomial formula likely to understate the true spread of their accuracy score?
5. You deduplicate 100,000 documents with a 32-bit hash. Roughly how often will at least one pair of different documents share a hash value?