# 困惑度

**困惑度**（Perplexity，PPL）是语言模型的标准内在评估指标：模型分配给一个留出序列的、指数化后的平均负对数似然。当困惑度等于 k 时，模型平均而言所承载的不确定性，等同于每一步从 k 个等可能选项中随机挑选一个时所承载的不确定性——因此困惑度也被描述为有效分支因子。<sup>[1](https://computationallinguistics.com/Perplexity)</sup> 这一度量由耶利内克（Jelinek）、默瑟（Mercer）、巴尔（Bahl）和贝克（Baker）于 1977 年在语音识别语境中提出，用来衡量任务难度；他们认为，词表大小以及静态和动态分支因子都不是充分的复杂度度量，而对数等于熵的困惑度，是衡量等效选择的更合适度量。<sup>[2](https://pubs.aip.org/asa/jasa/article/62/S1_S63/642598/Perplexity-a-measure-of-the-difficulty-of-speech)</sup>

| 关键事实 | 细节 |
|---|---|
| 定义 | PPL(X) = exp{−(1/t) Σ log p_θ(x_i \| x_<i)}，以 e 为底的指数化平均负对数似然<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup> |
| 交叉熵形式 | PP = 2^H，其中 H 是以比特为单位的交叉熵；交叉熵至少不小于真实熵，因此困惑度给出内在复杂度的上界<sup>[1](https://computationallinguistics.com/Perplexity)</sup> |
| 适用性 | 传统的从左到右序列困惑度直接适用于自回归（因果）语言模型；对于 BERT 这类掩码语言模型，它没有被直接定义<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup> |
| 可比性 | 只有在词表、分词器和测试集相同时才有意义；不同的分词方式会给出不同的有效分支因子<sup>[1](https://computationallinguistics.com/Perplexity)</sup> |
| 数值范围 | 在 20,000 词词表上的二元模型达到约 200；三元模型大致为 100–150；现代神经模型在宾州树库（Penn Treebank）上低于 20<sup>[1](https://computationallinguistics.com/Perplexity)</sup> |
| 协议敏感性 | 步幅为 512 的滑动窗口评估将 GPT-2 在 WikiText-2 上的困惑度从 19.44 降至 16.44；将窗口从 16 个词元扩大到 1024 个词元，会使 LLaMA-3.2 和 Qwen 模型上报告的困惑度降低 57–62%<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup><sup> • </sup><sup>[4](https://arxiv.org/html/2602.04099v1)</sup> |
| 下游关联 | 更低的困惑度并不保证更好的语音识别词错误率或机器翻译 BLEU 分数<sup>[1](https://computationallinguistics.com/Perplexity)</sup> |

## 定义与直觉

困惑度量化模型对训练中未见文本的惊讶程度。对于一个含 t 个词元的序列，模型的平均负对数似然衡量每个词元带来的惊讶程度；取指数会把该平均值转换回概率尺度，得到模型在每一步表现得仿佛面对的等可能选择数。<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup><sup> • </sup><sup>[1](https://computationallinguistics.com/Perplexity)</sup> 以奈特为单位时，关系为 PPL = exp(H)；以比特为单位时，关系为 PPL = 2^H。<sup>[5](https://llmdeepdive.com/lessons/1-text-to-tensors/1.7-entropy-perplexity/)</sup> Hugging Face Evaluate 库实现的正是这一量，指数底为 e，并把困惑度描述为评估语言模型最常用的指标之一。<sup>[6](https://github.com/huggingface/evaluate/blob/main/metrics/perplexity/perplexity.py)</sup>

传统的从左到右序列困惑度直接适用于自回归（即因果）语言模型，这类模型把序列概率从左到右分解。对于 BERT 这类掩码语言模型，它没有被直接定义，因为这类模型预测的是随机被遮蔽的词元，而不是下一个词元。<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup>

## 数学表述与相关度量

形式上，对于含 N 个词元的测试语料 W，PP(W) = P(w₁, …, w_N)^(−1/N) = 2^(H(W))，其中 H(W) 是模型预测与测试数据经验分布之间以比特为单位的交叉熵。由于交叉熵至少不小于数据的真实熵，测得的困惑度给出数据内在复杂度的上界。<sup>[1](https://computationallinguistics.com/Perplexity)</sup>

论文至少用四种单位报告下一词元预测：以奈特为单位的交叉熵、以比特为单位的交叉熵、困惑度，以及每字节比特数（BPB）。<sup>[7](https://www.theorempath.com/topics/bits-nats-perplexity-bpb)</sup> 相关指标包括每字符比特数（BPC），它把交叉熵适配到字符；以及每英文字符比特数（BPEC），它用英语的 BPC 归一化目标语言的 BPC；BPEC 与信息对等旨在跨语言比较 BPC。<sup>[8](https://aclanthology.org/2026.eacl-long.113.pdf)</sup> BPB 是按字节测量的交叉熵；由于它以字节为单位，因此与分词器无关，可以让词表不同的模型得到公平比较。<sup>[9](https://dipkumar.dev/posts/llm/bits-per-byte/)</sup> 每词元比特数与 BPB 之间的换算取决于分词器的压缩比：GPT-2 的字节对编码在英语文本上大约每字节产生 0.25 个词元，因此不知道分词器就无法换算。<sup>[7](https://www.theorempath.com/topics/bits-nats-perplexity-bpb)</sup>

## 用数字看困惑度

历史轨迹显示了这一度量的影响范围。在标准基准上，词表为 20,000 词的二元模型通常达到接近 200 的困惑度，三元模型将其降至约 100–150，而当代神经语言模型在[宾州树库](https://www.edgepedia.org/zh/penn-treebank)（Penn Treebank）上取得低于 20 的数值。<sup>[1](https://computationallinguistics.com/Perplexity)</sup> 在 [WikiText-103](https://www.edgepedia.org/zh/wikitext-103) 上，神经语言模型的最先进水平在不到两年内从 40.8 降到 16.4，而 n-gram 的性能在 N = 4 之后基本不再显著提升。<sup>[10](https://thegradient.pub/understanding-evaluation-metrics-for-language-models/)</sup> 根据一份参考文献的说法，GPT-2 在 WikiText-103 上取得了 18.3 的困惑度，<sup>[1](https://computationallinguistics.com/Perplexity)</sup> 不过另一份表格统计给出 GPT-2 Small（117M 参数）在 WikiText-103 上为 37.5，GPT-2 Large（762M）为 22.1，GPT-3（175B）在 WikiText-103 和宾州树库上都在 20 左右，LLaMA 2 70B 在 WikiText-103 上约为 7。<sup>[11](https://www.tensortonic.com/ml-math/information-theory/perplexity)</sup> 两份关于 GPT-2 在 WikiText-103 上的说法不同，说明模型规模和评估协议会改变这个数字。困惑度仍是一种常用的评估指标：一篇 2025 年经同行评审的压缩论文，在 WikiText-2、WikiText-103 和 PTB 上以困惑度比较各方法，并与 GPT-2、DistilGPT2 和 [SparseGPT](https://www.edgepedia.org/zh/sparsegpt) 基线对照。<sup>[12](https://www.nature.com/articles/s41598-025-92586-5/tables/5)</sup>

模型如何被评估，取决于所选语料、起始和结束词元的处理方式、上下文长度、重叠片段是否通过滑动窗口重新计算，以及哪些位置被排除在损失之外；在这些方面有任何不同的已发表数字都不能相互比较。<sup>[5](https://llmdeepdive.com/lessons/1-text-to-tensors/1.7-entropy-perplexity/)</sup> 分词过程对模型的困惑度有直接影响，在比较模型时必须加以考虑。<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup> 字符级模型的困惑度可能远小于词级模型，但这并不表示字符级模型更好。<sup>[10](https://thegradient.pub/understanding-evaluation-metrics-for-language-models/)</sup>

用于固定上下文模型的滑动窗口策略具体展示了协议效应。对于上下文为 1024 个词元的 GPT-2，以步幅 1024（无重叠）评估 WikiText-2 得到 PPL 19.44，接近 GPT-2 论文中报告的 19.93；以步幅 512 评估时，同一模型得分为 16.44。<sup>[3](https://huggingface.co/docs/transformers/en/perplexity)</sup> 从更广的视角看，将窗口从 16 个词元扩大到 1024 个词元，会使不同规模的 LLaMA-3.2 和 Qwen 模型困惑度降低 57–62%，而滑动窗口评估会持续低估长上下文建模能力，且无论模型规模如何，失真都相似。<sup>[4](https://arxiv.org/html/2602.04099v1)</sup>

## 与其他评估度量的比较

困惑度是一种内在指标：它衡量模型在固定协议下、在固定测试集上预测下一词元的能力。因此，现代大语言模型评估会在困惑度之外加入 MMLU 和 [HumanEval](https://www.edgepedia.org/zh/humaneval) 等任务特定基准。<sup>[11](https://www.tensortonic.com/ml-math/information-theory/perplexity)</sup>

这两类测量之间的联系是双向的。RoBERTa 的作者表明，更好的掩码语言建模困惑度会带来更好的情感分析和多文体自然语言推理最终任务准确率。<sup>[10](https://thegradient.pub/understanding-evaluation-metrics-for-language-models/)</sup> 另一方面，XLNet 的作者认为，语言模型性能的提升不一定能迁移到下游任务，<sup>[10](https://thegradient.pub/understanding-evaluation-metrics-for-language-models/)</sup> 而且语言模型中更低的困惑度并不保证语音识别中更好的词错误率或机器翻译中更高的 BLEU 分数，因为这些任务取决于模型如何与系统的其他组件交互。<sup>[1](https://computationallinguistics.com/Perplexity)</sup> 对这一差距最尖锐的表述是：困惑度衡量的是模型在给定协议下对词元有多惊讶；它并不直接衡量指令遵循、事实可靠性、拒答行为、工具使用或服务成本，而后训练可以提升助手质量，同时让困惑度朝令人困惑的方向变化。<sup>[5](https://llmdeepdive.com/lessons/1-text-to-tensors/1.7-entropy-perplexity/)</sup>

## 实际用途与失效模式

**数据过滤。** 困惑度也可兼作数据质量信号。用小参考模型计算出的困惑度来剪枝预训练数据，可以提升下游性能：10 亿参数模型在 Pile 和 Dolma 上分别获得 1.89 和 1.51 的平均下游分数提升，30 亿参数模型分别获得 2.04 和 0.59 的提升。<sup>[13](https://proceedings.iclr.cc/paper_files/paper/2025/file/fa30825df7ceaba452d5533538ea29c2-Paper-Conference.pdf)</sup> 同一项研究发现，在经困惑度剪枝的数据上训练，会显著恶化预训练数据留出测试划分上的困惑度，同时提升平均下游性能，因此得出结论：测试集困惑度未必始终是数据剪枝工作的可靠指标。<sup>[13](https://proceedings.iclr.cc/paper_files/paper/2025/file/fa30825df7ceaba452d5533538ea29c2-Paper-Conference.pdf)</sup> ScalingFilter 则使用一对 1.24 亿和 7.74 亿参数模型之间的困惑度差作为质量信号，相对于未过滤基线，取得 +3.09% 的下游准确率和 +2.23 的语义多样性，并缓解单模型困惑度倾向于选择简单、重复文本的问题。<sup>[14](https://aclanthology.org/2024.emnlp-main.187.pdf)</sup>

**测量伪影。** 短文本的困惑度很可能远大于长文本，不过当文本长度超过 100 个词元时，它会变得相对稳定。<sup>[15](https://ar5iv.labs.arxiv.org/html/2210.05892)</sup> 重复的文本片段会导致更低的 PPL 值，尽管重复并不会提升文本质量；仅仅删去句末标点，就可能显著提高其 PPL；作者据此认为，PPL 用于评估生成文本质量并不可靠。<sup>[15](https://ar5iv.labs.arxiv.org/html/2210.05892)</sup>

**一个理论极限。** 一项 2026 年的理论结果证明：如果一个紧凑的仅解码器 [Transformer](https://www.edgepedia.org/zh/transformer) 能准确且自信地预测某个序列——这是强泛化的必要前提——那么必然存在另一个困惑度极低、但同一模型会预测错误的序列。等困惑度分析进一步表明，困惑度并不总会选出更准确的模型：模型置信度的任何提升，都必须伴随准确率的相应提升，选择才是正确的。<sup>[16](https://arxiv.org/html/2601.22950v1)</sup>

## 语言建模之外的困惑度

这一度量起源于文本生成之外。耶利内克、默瑟、巴尔和贝克于 1977 年将其引入，作为衡量语音识别任务难度的指标，他们认为，对数等于熵的困惑度，比词表大小或分支因子更适合衡量等效选择；他们还表明，困惑度可以应用于没有明显统计描述的语言，因为对任何有限状态文法都可以找到熵最大化的概率分配。<sup>[2](https://pubs.aip.org/asa/jasa/article/62/S1_S63/642598/Perplexity-a-measure-of-the-difficulty-of-speech)</sup> 在现代实践中，它被用作预训练流程中的数据质量和过滤信号，正如上文的剪枝与过滤结果所示。<sup>[13](https://proceedings.iclr.cc/paper_files/paper/2025/file/fa30825df7ceaba452d5533538ea29c2-Paper-Conference.pdf)</sup><sup> • </sup><sup>[14](https://aclanthology.org/2024.emnlp-main.187.pdf)</sup>

有一个同名术语与此无关。降维方法 t-SNE 把“困惑度”用作超参数，用来定义有效邻域大小，即在嵌入点时考虑多少个邻居；它与语言模型困惑度是相关但不同的概念。<sup>[11](https://www.tensortonic.com/ml-math/information-theory/perplexity)</sup>

## References

1. [Perplexity — Computational Linguistics Reference](https://computationallinguistics.com/Perplexity)
2. [Jelinek, Mercer, Bahl & Baker (1977). Perplexity—a measure of the difficulty of speech recognition tasks. JASA 62(S1).](https://pubs.aip.org/asa/jasa/article/62/S1_S63/642598/Perplexity-a-measure-of-the-difficulty-of-speech)
3. [Perplexity of fixed-length models — Hugging Face Transformers documentation](https://huggingface.co/docs/transformers/en/perplexity)
4. [Rethinking Perplexity: Revealing the Impact of Input Length on Perplexity Evaluation in LLMs (arXiv preprint)](https://arxiv.org/html/2602.04099v1)
5. [Entropy, perplexity, and what 'good' means — llmdeepdive](https://llmdeepdive.com/lessons/1-text-to-tensors/1.7-entropy-perplexity/)
6. [Hugging Face Evaluate library — perplexity metric implementation](https://github.com/huggingface/evaluate/blob/main/metrics/perplexity/perplexity.py)
7. [Bits, Nats, Perplexity, BPB — TheoremPath](https://www.theorempath.com/topics/bits-nats-perplexity-bpb)
8. [AGOM (EACL 2026)](https://aclanthology.org/2026.eacl-long.113.pdf)
9. [Bits-per-Byte (BPB): a tokenizer-agnostic way to measure LLMs — dipkumar.dev](https://dipkumar.dev/posts/llm/bits-per-byte/)
10. [Evaluation Metrics for Language Modeling — The Gradient](https://thegradient.pub/understanding-evaluation-metrics-for-language-models/)
11. [Perplexity in LLMs: Formula, GPT Benchmarks & Interactive Guide — TensorTonic](https://www.tensortonic.com/ml-math/information-theory/perplexity)
12. [Table 5: Perplexity comparison across approaches on language modeling datasets (Scientific Reports, 2025)](https://www.nature.com/articles/s41598-025-92586-5/tables/5)
13. [Perplexity-Based Data Pruning (ICLR 2025)](https://proceedings.iclr.cc/paper_files/paper/2025/file/fa30825df7ceaba452d5533538ea29c2-Paper-Conference.pdf)
14. [ScalingFilter: Assessing Data Quality through Inverse Utilization of Scaling Laws (EMNLP 2024)](https://aclanthology.org/2024.emnlp-main.187.pdf)
15. [Perplexity by PLM Is Unreliable for Evaluating Text Quality (arXiv preprint)](https://ar5iv.labs.arxiv.org/html/2210.05892)
16. [Perplexity Cannot Always Tell Right from Wrong (arXiv preprint)](https://arxiv.org/html/2601.22950v1)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Language and vision AI › Natural language processing › NLP tasks and methods › Statistical NLP and language modeling

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/perplexity

English original: https://www.edgepedia.org/perplexity
