生日悖论显示小型 LLM 仅从 40 个词中取约 6 个

用生日悖论衡量 LLM 输出多样性
我学过数学,所以解释过很多次生日悖论。反应总是一样的。房间里放 23 个人,其中两个人生日相同的概率大约是 50%。23 个人,365 天?不可能。我第一次也不信。
数学很简单。只是你的直觉错了。这种不匹配正是我喜欢它的原因,而且它碰巧也是戳一戳 AI 模型的便捷方式。
试试这个。让聊天机器人随机给出一个名字,然后问一次,再问一次,总共问 300 次。一个真正从成千上万个名字中挑选的模型,几乎不会重复。如果总是出现同样的几个名字,那它真正的可选列表就比看起来短得多。生日悖论会告诉你短了多少。
你要做的就是数重复次数。不需要概率,也不用窥探模型内部,所以它能用于任何你能输入文字的聊天机器人。
我在六个小型开放模型上跑了这个测试。有一个结果一直让我耿耿于怀。我给一个聊天模型一个包含 40 个单词的列表,让它随机选一个,问了 300 次。它的表现就像它只有大约 6 个单词。
先说明一下,因为我还会再说一次“大约 6”:那指的是三个经过聊天微调的模型,它们的值落在 5.5 到 7.0 之间。基座模型更混乱。稍后再细说它们。
生日悖论:一次一对
这感觉不对,因为我们数的是人,而 23 听起来很小。不过,生日相同需要两个人,所以要改数配对。23 个人能组成 23 × 22 ÷ 2 = 253 对。每一对匹配的概率是 1/365,因此预期匹配对数约为 253 ÷ 365,也就是约 0.69 对。这已经接近至少出现一对匹配的五成概率了。
人是一个一个增加的。配对数量大致按平方增长。
从 N 个等概率选项中抽取 n 次时,预期匹配对数为:
预期匹配对数 = n(n−1) / (2N)
至少有两人生日相同的概率,随群体规模变化。在 23 人时超过 50%。作者制图
这个公式在你已知 N 时用来预测匹配数。我不知道 N,但我可以数出匹配数。所以我反过来解 N:
N ≈ n(n−1) / (2 × 匹配数)
假设我要求给出 30 个随机名字,结果有 9 对答案完全相同。N 约为 30 × 29 ÷ (2 × 9) ≈ 48。该模型的表现就像是它从大约 48 个名字中均匀抽取。
真实的选择并不均匀
模型显然不会均匀地选择。它有自己的偏好。那么当某些名字出现的频率远高于其他名字时,“大约48”意味着什么?
两次抽取匹配的概率等于每个选项概率平方之和。匹配对计数测量的是这个和,而我可以把这个和转换回选项数量。我称之为 N_eff,即有效选项数:
N_{\text{eff}} = \frac{1}{\sum_i p_i^2}
当所有 N 个选项等概率时,它给出恰好 N。当它们不等概率时,它给出一个更小的值,且热门选项占主导。假设一个模型有一半时间回答“Emma”,另一半时间均匀分布在其他 50 个名字上,每个 1%。平方和为 0.5 × 0.5 + 50 × 0.01 × 0.01 = 0.255,因此 N_eff 约为 3.9。共有 51 个名字可用。模型表现得像只有四个。
生态学家几十年来一直使用这个确切的数字来统计生态系统中的有效物种数。在那里,它被称为逆辛普森指数 [1][2]。
一个注意事项。由于偏好选项占主导,N_eff 告诉你模型的答案有多集中,而不是它可能说出多少种东西。我问的是这个东西有多重复,所以这正是我想要的。
我使用了六个开放模型,它们小到可以在免费的 Kaggle GPU 上运行:Qwen2.5 的 1.5B 和 3B 参数版本 [3],以及 SmolLM2 的 1.7B 版本 [4]。每个都有基础版本和指令微调(聊天)版本。
八个问题:随机一个名字、动物、颜色、水果、国家、英文单词、1 到 100 之间的一个数字,以及“从这份列表中随机选一项”,列表是我编的 40 个单词。每个问题在三个温度(0.7、1.0 和 1.3)下各得到 300 个回答。我把所有内容转为小写并去掉标点,所以“Emma!”和“emma”是同一个回答。温度 1.0 是模型的原始概率,没有锐化或平滑,因此除非另有说明,我报告的都是这一温度下的结果。
计数用几行 Python 代码:
from collections import Counterdef n_eff(answers): n = len(answers) matches = sum(c * (c - 1) // 2 for c in Counter(answers).values()) return n * (n - 1) / 2 / matches if matches else float('inf')
一种方法不能仅因为数学上看起来漂亮就值得信赖,所以我做了两项检查。列表问题有一个已知的正确答案:一个从 40 个词中均匀选取的模型应该恰好得到 40 分。对于“随机选一个字母表字母”,答案是一个 Token。这让我能读取模型对 26 个大写字母的真实概率,计算精确的 N_eff,并将其与来自 300 个抽样回答的估计值进行比较。
统计重复项真的有效吗?
是的,只要你有足够多的回答。
通过统计重复项估计的有效选项数(纵轴)与来自模型概率的精确值(横轴)的对比,针对字母问题。虚线 = 完全一致。空心标记表示可用回答少于 150 个。图片由作者提供。
对于这三个聊天模型,300 个答案中至少有 202 个是可用的字母,并且在全部九次运行中,估计值与真实值的误差都在约 12% 以内。在全部 18 次运行中,估计值与真实值之比的中位数为 0.99。基础模型噪声更大。它们常常没有给出干净的大写字母,所以我每次运行只有 26 到 124 个可用答案,最差情况下估计值偏差高达 39%。空心标记显示的就是这一点。
字母测试还首次让我们得以一窥这些聊天模型。在 26 个字母中,它们在 temperature 1.0 下表现得像是分别拥有 3.2(Qwen2.5 3B)、6.7(Qwen2.5 1.5B)和 12.6(SmolLM2)个选项。
这些聊天模型会使用多少个不同的答案?
三个聊天模型在 temperature 1.0 下每个问题的有效选项数量(对数尺度)。每个点代表一个模型。图片由作者提供。
大多数点位于约 5 到 25 之间。一个读过互联网大部分内容的模型能说出的答案远不止这些。水果类别最糟糕。Qwen2.5-3B-Instruct 和 SmolLM2-Instruct 在 300 次尝试中都有 227 次说“apple”,有效水果数约为 1.7。
对于每个问题,重复其最喜欢答案最多的聊天模型,以及重复频率。图片由作者提供。
名字类别很好地体现了这一点。Qwen2.5-3B-Instruct 在 300 次中有 130 次说“Ethan”(43%),得分为 4.7。另外两个聊天模型则倾向“Liam”(各约 16%),得分分别为 15.6 和 21.7。在数字类别,Qwen2.5-3B-Instruct 在其 30% 的答案中说 82,而 Qwen2.5-1.5B-Instruct 在 19% 的答案中说 73。
不过,聊天模型并不总是重复。这在很大程度上取决于模型和问题。在“英语单词”类别,Qwen2.5-3B-Instruct 有 40% 的时候说“abnegation”(N_eff 6.0),而 SmolLM2-Instruct 几乎从不重复自己(N_eff 超过 3,000)。同一个 SmolLM2 在水果类别上的得分为 1.7。
被要求从 40 个中均匀挑选时
聊天模型被要求从列出的 40 个词中随机选择一个时,按采样温度统计的有效选项数。虚线为理想值 40。图片由作者提供。
在温度 1.0 时,三个聊天模型的得分分别为 7.0、5.5 和 6.1,即我给出的 40 个选项中的 14% 到 17%。它们最偏爱的是 "apple"(36%,SmolLM2——没错,它就是我列表里的第一个词)、"river"(28%,Qwen2.5 3B)和 "orchard"(28%,Qwen2.5 1.5B)。
提高温度有帮助,但效果并不均衡。随着温度从 0.7 升到 1.0 再到 1.3,SmolLM2-Instruct 从 1.9 升到 6.1 再到 27.8;Qwen2.5-3B-Instruct 则只从 4.1 升到 7.7。我无法判断在 1.3 时增加的这部分有多少是真正的多样性。更高的采样温度也会让模型更可能跑到列表之外,而我的统计把这种“跑偏”也算作额外的多样性。
那基础模型呢?
我把它们排除在图表之外,原因如下。看看它们最常见的回答,其中很多根本算不上回答。对于 animal、color 和 number,Qwen2.5-1.5B 出现最多的“答案”是一段闲聊式开场白(“当然,这是一个随机动物”)。Qwen2.5-3B 在 first names 和 words 上也是如此。在列表问题上,SmolLM2 最常见的回复是照抄我的指令。而在 40 项列表上,基础模型产出了 134 到 284 个不同的字符串,而有效答案只有 40 个。
那是杂乱文本,不是选项。杂乱文本几乎不会重复,所以 N_eff 看起来极大(SmolLM2 在 "word" 上超过 22,000)。我本可以把它过滤掉,但那样就得由我猜测什么算有效。所以我不把这些数字当作多样性来引用。
基础模型与对话模型之间唯一公平的对比是字母测试,因为在那里我读取的是精确概率。在 temperature 1.0 下,基础模型的得分为 9.6(Qwen2.5 1.5B)、7.8(Qwen2.5 3B)和 5.3(SmolLM2)。它们的对话版本得分分别为 6.7、3.2 和 12.6。也就是说,对话微调降低了两款 Qwen 模型的数值,却提高了 SmolLM2 的数值。三组对比太少,不足以将此称为规律。
这说明了什么,又没有说明什么
原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。
查看英文原文(The Birthday Paradox Shows Small LLMs Pick From About 6 of 40 Words)
Measure LLM Output Diversity With the Birthday Paradox
I studied math, so I've explained the birthday paradox a lot. The reaction is always the same. Put 23 people in a room and there's about a 50% chance two of them share a birthday. 23 people, 365 days? No way. I didn't believe it either the first time.
The math is simple. Your gut is just wrong. That mismatch is why I love this one, and it happens to be a handy way to poke at AI models too.
Try this. Ask a chatbot for a random first name, then ask again, and again, 300 times. A model really choosing from thousands of names would almost never repeat itself. If the same few names keep showing up, its real list is a lot shorter than it looks. The birthday paradox tells you how much shorter.
All you do is count repeats. No probabilities, no peeking inside the model, so it works on any chatbot you can type into.
I ran it on six small open models. One result keeps nagging at me. I gave a chat model a list of 40 words, told it to pick one at random, and asked 300 times. It acted like it had about 6 words.
A quick flag, because I'll say "about 6" again: that's the three chat-tuned models, which landed between 5.5 and 7.0. The base models are messier. More on them later.
The birthday paradox, one pair at a time
It feels wrong because we count people, and 23 sounds small. A shared birthday needs two people though, so count pairs instead. 23 people make 23 × 22 ÷ 2 = 253 pairs. Each pair matches with a 1 in 365 chance, so you'd expect 253 ÷ 365, about 0.69 matching pairs. That's already close to a coin flip on getting at least one.
People pile up one at a time. Pairs grow roughly with the square.
With n draws from N equally likely options, the expected number of matching pairs is:
expected matching pairs=n(n−1)2N\text{expected matching pairs} = \frac{n(n-1)}{2N}expected matching pairs=2Nn(n−1)

Chance that at least two people share a birthday, by group size. It passes 50% at 23 people. Image by author
That formula predicts matches when you know N. I don't know N, but I can count the matches. So I solve for N instead:
N≈n(n−1)2×matchesN \approx \frac{n(n-1)}{2 \times \text{matches}}N≈2×matchesn(n−1)
Say I ask for 30 random names and 9 pairs of answers are identical. N is about 30 × 29 ÷ (2 × 9) ≈ 48. The model behaves as if it picked evenly from roughly 48 names.
Real choices aren't even
A model doesn't pick evenly, obviously. It has favorites. So what does "about 48" mean when some names show up much more than others?
Two draws match with a probability equal to the sum of each option's probability squared. The matching-pairs count measures that sum, and I can turn the sum back into a number of options. I call it NeffN_effNeff, the effective number of options:
Neff=1∑ipi2N_{\text{eff}} = \frac{1}{\sum_i p_i^2}Neff=∑ipi21
When all N options are equally likely, it gives exactly N. When they aren't, it gives something smaller, and the popular options dominate. Say a model answers "Emma" half the time and spreads the other half evenly over 50 other names, 1% each. The sum of squares is 0.5 × 0.5 + 50 × 0.01 × 0.01 = 0.255, so NeffN_effNeff is about 3.9. Fifty-one names in play. The model acts like it has four.
Ecologists have used this exact number for decades to count the effective number of species in an ecosystem. There it's called the inverse Simpson index [1][2].
One caveat. Since favorites dominate, NeffN_effNeff tells you how concentrated a model's answers are, not how many things it could ever say. I'm asking how repetitive the thing is, so that's what I want.
I used six open models small enough for a free Kaggle GPU: Qwen2.5 at 1.5B and 3B parameters [3], and SmolLM2 at 1.7B [4]. Each has a base version and an instruction-tuned (chat) version.
Eight questions: a random first name, animal, color, fruit, country, English word, a number between 1 and 100, and "pick one item at random from this list," using a list of 40 words I made up. Each question got 300 answers at three temperatures (0.7, 1.0 and 1.3). I lowercased everything and stripped punctuation, so "Emma!" and "emma" are the same answer. Temperature 1.0 is the model's plain probabilities with nothing sharpened or flattened, so I report that unless I say otherwise.
The counting is a few lines of Python:
from collections import Counterdef n_eff(answers): n = len(answers) matches = sum(c * (c - 1) // 2 for c in Counter(answers).values()) return n * (n - 1) / 2 / matches if matches else float('inf')
A method isn't trustworthy just because the math looks nice, so I ran two checks. The list question has a known right answer: a model picking evenly from 40 words should score exactly 40. For "pick a random letter of the alphabet," the answer is a single token. That lets me read the model's real probabilities for the 26 capital letters, compute the exact NeffN_effNeff, and compare it with the estimate from 300 sampled answers.
Does counting repeats actually work?
Yes, if you have enough answers.
Effective options estimated by counting repeats (vertical) against the exact value from the model's probabilities (horizontal), for the letter question. Dashed line = perfect agreement. Hollow markers have fewer than 150 usable answers. Image by author.
For the three chat models, at least 202 of 300 answers were usable letters, and the estimate landed within about 12% of the true value in all nine runs. Across all 18 runs the median ratio of estimate to truth was 0.99. The base models were noisier. They often didn't give a clean capital letter, so I had only 26 to 124 usable answers per run, and the estimate was off by as much as 39% in the worst case. That's what the hollow markers show.
The letter test also gave a first look at the chat models. Out of 26 letters, they acted like they had 3.2 (Qwen2.5 3B), 6.7 (Qwen2.5 1.5B) and 12.6 (SmolLM2) at temperature 1.0.
How many different answers do the chat models use?
Effective number of options per question for the three chat models at temperature 1.0 (log scale). Each dot is one model. Image by author.
Most dots sit between about 5 and 25. A model that has read most of the internet could name far more than that. Fruit is the worst. Qwen2.5-3B-Instruct and SmolLM2-Instruct both said "apple" in 227 of 300 tries, about 1.7 effective fruits.
For each question, the chat model that repeated its favorite answer the most, and how often. Image by author.
Names show it well. Qwen2.5-3B-Instruct said "Ethan" 130 times out of 300 (43%) and scored 4.7. The other two chat models went for "Liam" (about 16% each) and scored 15.6 and 21.7. For numbers, Qwen2.5-3B-Instruct said 82 in 30% of its answers, and Qwen2.5-1.5B-Instruct said 73 in 19%.
Chat models aren't always repetitive, though. It depends a lot on the model and the question. On "English word," Qwen2.5-3B-Instruct said "abnegation" 40% of the time ( NeffN_effNeff 6.0), while SmolLM2-Instruct almost never repeated itself ( NeffN_effNeff above 3,000). Same SmolLM2 that scored 1.7 on fruit.
Told to pick evenly from 40
Effective options when the chat models are told to choose one of 40 listed words at random, by sampling temperature. The dashed line is the ideal, 40. Image by author.
At temperature 1.0 the three chat models scored 7.0, 5.5 and 6.1. That's 14 to 17% of the 40 options I gave them. Their favorites were "apple" (36%, SmolLM2, and yes, it's the first word in my list), "river" (28%, Qwen2.5 3B) and "orchard" (28%, Qwen2.5 1.5B).
A higher temperature helped, but not evenly. SmolLM2-Instruct went from 1.9 to 6.1 to 27.8 as the temperature went from 0.7 to 1.0 to 1.3. Qwen2.5-3B-Instruct only got from 4.1 to 7.7. I can't say how much of the gain at 1.3 is real variety. Hotter sampling also makes a model more likely to wander off the list, and my count treats wandering as extra variety.
What about the base models?
I left them out of the charts, and here's why. Look at their most common answers and a lot of them aren't answers. For animal, color and number, the top "answer" from Qwen2.5-1.5B was a chatty preamble ("sure, here's a random animal"). Qwen2.5-3B did the same for first names and for words. On the list question, SmolLM2's most common reply was a copy of my instruction. And on the 40-item list, the base models produced between 134 and 284 different strings, when only 40 were valid answers.
That's messy text, not choices. Messy text almost never repeats, so NeffN_effNeff looks huge (over 22,000 for SmolLM2 on "word"). I could have filtered it, but then I'm guessing what counts as valid. So I'm not quoting those numbers as diversity.
The one fair comparison between base and chat is the letter test, because there I read exact probabilities. At temperature 1.0 the base models scored 9.6 (Qwen2.5 1.5B), 7.8 (Qwen2.5 3B) and 5.3 (SmolLM2). Their chat versions scored 6.7, 3.2 and 12.6. So chat tuning lowered the number for both Qwen models and raised it for SmolLM2. Three pairs is too few to call that a rule.
What this does and doesn't show
These are small models, 1.5B to 3B parameters, from two families. I'm not saying anything about the big chat models people use every day. The method only needs repeated answers though, so anyone can point it at a bigger one, even one behind an API.
I used one wording per question, and a different prompt would give different numbers. Answers match only if they're identical after lowercasing and removing punctuation, so it works best for short answers, and two spellings of one name count as two answers. If NeffN_effNeffcomes out above a hundred or so, there were very few repeats to count. Read that as "a lot," not as a precise figure. And since favorites dominate, NeffN_effNeffunderstates how many different things a model could say. It measures repetitiveness. That's all.
Ask a small chat model for something random and you get far less random than it feels like. Told to choose one of 40 words evenly, all three chat models acted like they had 5 to 7.
Checking is cheap. Ask the same question a few hundred times, count the repeats, run the formula. If you try it on a bigger model, tell me what number you get. I really want to know.
[1] E. H. Simpson, Measurement of Diversity (1949), Nature, 163, 688
[2] M. O. Hill, Diversity and Evenness: A Unifying Notation and Its Consequences (1973), Ecology, 54(2), 427–432
[3] Qwen Team, Qwen2.5 Technical Report (2024), arXiv:2412.15115
[4] L. B. Allal et al., SmolLM2: When Smol Goes Big, Data-Centric Training of a Small Language Model (2025), arXiv:2502.02737
Learnings as an AI & Robotics Associate Editor with 100 Peer Reviews
September 4, 202410 min read
Inspired by Encarta, built in Python, accessible at worldatlas.org
February 19, 202234 min read
An intuitive introduction to signal aliasing with Python
July 12, 202312 min read
Investigating the Capability of Synthetic Data to Enhance Model Performance on Imbalanced Datasets
原文为英文,正文由自动抓取并保留原文。
原文发布于 Towards Data Science(The Birthday Paradox Shows Small LLMs Pick From About 6 of 40 Words),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。