---
title: "Perplexity (metric) — 困惑度"
source: "https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6"
wiki: "systems-analysis.info/int"
article: "Perplexity_(metric)_—_困惑度"
language: "zh"
categories:
  - "Category:Chinese"
  - "Category:Large language models"
  - "Category:LLM evaluation"
  - "Category:Machine learning"
revision_id: 5543
wiki_created_at: 2026-09-06T23:50:46Z
wiki_modified_at: 2026-09-06T23:50:46Z
downloaded_at: 2026-09-07T23:09:02Z
---

# Perplexity (metric) — 困惑度

**困惑度**（英语：*Perplexity*，PPL）在信息论和机器学习中，是衡量语言模型在预测文本样本时的不确定性或“惊讶”程度的指标。低困惑度表明模型的概率分布与测试数据拟合得很好，而高困惑度则意味着模型对序列的预测效果不佳<sup>[\[1\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-ru_wiki-1)</sup>。

形式上，概率分布的困惑度定义为其熵的指数。对于离散概率分布 $p(x)$，困惑度等于 $2^{H(p)}$，其中 $H(p)$ 是熵<sup>[\[2\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-en_wiki-2)</sup>。直观上，困惑度可以理解为模型在每一步选择时面临的“有效”选项数量。如果困惑度为 100，这意味着模型的不确定性等同于从 100 个等可能结果中进行选择<sup>[\[3\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-comet_eval-3)</sup>。

该术语由 Frederick Jelinek 领导的 IBM 研究团队于 1977 年在统计语音识别领域首次引入，用于量化任务的“难度”<sup>[\[4\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-readme_jelinek-4)</sup>。

## 语言模型中的困惑度

在自然语言处理（NLP）领域，困惑度已成为评估语言模型质量的标准内部（*intrinsic*）指标。它衡量模型在测试数据集上预测单词或词元序列的能力。

### 形式化定义

对于一个测试语料库 $W = w_{1}w_{2}\ldots w_{N}$ 和一个语言模型 $q$，困惑度的计算方法是测试语料库概率的几何平均数的倒数，并按单词数量进行归一化： $\text{PP}(W,q) = \left( \prod\limits_{i = 1}^{N}\frac{1}{q(w_{i} \mid w_{1},\ldots,w_{i - 1})} \right)^{1/N}$

此公式等价于交叉熵的指数，或平均负对数似然（*negative log-likelihood*）： $\text{PP}(W,q) = \exp\left( - \frac{1}{N}\sum\limits_{i = 1}^{N}\log q(w_{i} \mid \text{上下文}) \right)$

**最小化困惑度**等同于**最大化模型**在测试数据上的**似然**。因此，困惑度较低的模型被认为在统计上更准确<sup>[\[5\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-stanford_slp-5)</sup>。

### 历史应用与现代 LLM

历史上，困惑度被广泛用于评估统计 n-gram 模型。例如，对于《华尔街日报》语料库，一元模型（unigram model，仅考虑词频）的困惑度约为 962，而三元模型（trigram model，考虑前两个词的上下文）的困惑度约为 109<sup>[\[6\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-jurafsky_slp3-6)</sup>。困惑度的急剧下降表明模型能更好地捕捉语言规律。

随着大型语言模型（LLM）的发展，困惑度仍然是其基础评估基准之一。研究人员通常在标准测试集（如 WikiText）上报告困惑度，作为模型“流畅性”的指标。例如，OpenAI 关于 GPT-2 的论文指出，一个拥有约 1.17 亿参数的模型在 WikiText-103 语料库上实现了约 37 的困惑度<sup>[\[7\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-gpt2_issue-7)</sup>。困惑度的降低通常与模型质量的提升相关，因此该指标是训练和优化过程中的一个便捷进展指示器。

## 指标的局限性与解读

虽然低困惑度表明模型认为数据出现的可能性很高，但该指标存在一些显著的局限性，并不总是与生成文本的实际质量相关。

- **低困惑度 ≠ 高质量**。困惑度衡量的是模型对其预测的“自信程度”，而非“正确性”。模型可能会自信地犯错，生成无意义但统计上很常见的文本（例如，重复高频词和短语）<sup>[\[3\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-comet_eval-3)</sup>。
- **对数据和分词方式敏感**。困惑度**不适合直接比较**架构、词汇表或分词方式不同的模型。例如，一个基于字符的模型其困惑度在数值上可能低于一个基于词的模型，但这并不意味着它在解决语言任务上表现更好<sup>[\[3\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-comet_eval-3)</sup>。
- **无法评估语义和长上下文**。困惑度是一个局部指标，评估的是对下一个词元的预测。它与模型捕捉长距离依赖和远距离语义上下文的能力关联性很弱。2023 年的一项研究（Hu et al.）表明，LLM 理解长文本（长达 10 万词元）的能力几乎不反映在困惑度指标中<sup>[\[8\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-hu_long_context-8)</sup>。
- **存在被操纵的可能**。该指标可以被“欺骗”。一个过拟合的模型会在它“记住”的数据上表现出人为的低困惑度。研究（Wang et al., 2022）还表明，重复文本片段甚至句末缺少句号，都可能不合理地降低或提高困惑度，而这并不影响文本的实际质量<sup>[\[9\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-wang_unreliable-9)</sup>。

## 结论：困惑度的当今作用

考虑到上述局限性，在当今的实践中，困惑度被视为评估语言模型质量的**辅助性、初步性指标**。它仍然是快速评估和调试模型的宝贵工具，因为它不依赖于特定的应用任务，且计算简单<sup>[\[3\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-comet_eval-3)</sup>。

然而，要全面评估 LLM，仅靠困惑度是不够的。如今，它必须与针对具体任务的外部（*extrinsic*）指标相结合，例如：

- 问答的准确率；
- 人工评估（*human evaluation*）；
- 用于机器翻译和文本摘要的 BLEU/ROUGE 分数。

通过与这些方法结合使用，困惑度继续扮演着重要角色——作为衡量模型“惊讶”程度的客观标准，但其结果的解读必须始终考虑上述局限性<sup>[\[3\]](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_note-comet_eval-3)</sup>。

## 外部链接

- <a href="https://habr.com/ru/companies/wunderfund/articles/580230/" class="external text" rel="nofollow">Habr 上的文章《语言模型中的困惑度》</a>
- <a href="https://huggingface.co/docs/transformers/perplexity" class="external text" rel="nofollow">Hugging Face 关于计算困惑度的文档</a>

## 参考文献

- Jelinek, F., Bahl, L. R., & Mercer, R. L. (1977). *Perplexity — a Measure of the Difficulty of Speech Recognition Tasks*. <a href="https://pubs.aip.org/asa/jasa/article/62/S1/S63/642598" class="external text" rel="nofollow">JASA:62(S1):S63</a>.
- Jurafsky, D., & Martin, J. H. (2021). *Speech and Language Processing* (3-й вып., гл. 3: N-gram Language Models). <a href="https://web.stanford.edu/~jurafsky/slp3/3.pdf" class="external text" rel="nofollow">PDF</a>.
- Radford, A. et al. (2019). *Language Models are Unsupervised Multitask Learners*. <a href="https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf" class="external text" rel="nofollow">OpenAI white paper</a>.
- Brown, T. B. et al. (2020). *Language Models are Few-Shot Learners*. <a href="https://arxiv.org/abs/2005.14165" class="external text" rel="nofollow">arXiv:2005.14165</a>.
- Kaplan, J. et al. (2020). *Scaling Laws for Neural Language Models*. <a href="https://arxiv.org/abs/2001.08361" class="external text" rel="nofollow">arXiv:2001.08361</a>.
- Wang, C. et al. (2022). *Perplexity by PLM Is Unreliable for Evaluating Text Quality*. <a href="https://arxiv.org/abs/2210.05892" class="external text" rel="nofollow">arXiv:2210.05892</a>.
- Meister, C., & Cotterell, R. (2021). *Language Model Evaluation Beyond Perplexity*. <a href="https://arxiv.org/abs/2106.00085" class="external text" rel="nofollow">arXiv:2106.00085</a>.
- Hu, Y. et al. (2024). *Can Perplexity Reflect Large Language Model's Ability in Long Text Understanding?*. <a href="https://arxiv.org/abs/2405.06105" class="external text" rel="nofollow">arXiv:2405.06105</a>.
- Lazaridou, A. et al. (2021). *Mind the Gap: Assessing Temporal Generalization in Neural Language Models*. <a href="https://openreview.net/pdf?id=73OmmrCfSyy" class="external text" rel="nofollow">NeurIPS 2021</a>.

## 注释

1.  <span id="cite_note-ru_wiki-1">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-ru_wiki_1-0) “Перплексия”。*Википедия*。 <a href="https://ru.wikipedia.org/wiki/Перплексия" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-en_wiki-2">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-en_wiki_2-0) “Perplexity”. *Wikipedia*. <a href="https://en.wikipedia.org/wiki/Perplexity" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-comet_eval-3">↑ <sup>[3.0](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-comet_eval_3-0)</sup> <sup>[3.1](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-comet_eval_3-1)</sup> <sup>[3.2](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-comet_eval_3-2)</sup> <sup>[3.3](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-comet_eval_3-3)</sup> <sup>[3.4](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-comet_eval_3-4)</sup> Morgan, Abby. “Perplexity for LLM Evaluation”. *Comet AI Blog*, 21 Nov 2024. <a href="https://www.comet.com/site/blog/perplexity-for-llm-evaluation/" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-readme_jelinek-4">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-readme_jelinek_4-0) “README.md · evaluate-measurement/perplexity”. *Hugging Face*. <a href="https://huggingface.co/spaces/evaluate-measurement/perplexity/blob/c4de5d6dae834c200992d54151402b80b6b46494/README.md" class="external autonumber" rel="nofollow">[4]</a></span>
5.  <span id="cite_note-stanford_slp-5">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-stanford_slp_5-0) Jurafsky, Dan, and James H. Martin. *Speech and Language Processing*, 3rd ed., Chapter 3: N-gram Language Models, draft (2021). <a href="https://web.stanford.edu/~jurafsky/slp3/3.pdf" class="external autonumber" rel="nofollow">[5]</a></span>
6.  <span id="cite_note-jurafsky_slp3-6">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-jurafsky_slp3_6-0) Jurafsky, Dan, and James H. Martin. *Speech and Language Processing*, 3rd ed., Chapter 3: N-gram Language Models, draft (2021). <a href="https://web.stanford.edu/~jurafsky/slp3/3.pdf" class="external autonumber" rel="nofollow">[6]</a></span>
7.  <span id="cite_note-gpt2_issue-7">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-gpt2_issue_7-0) “Perplexity number of wikitext-103 on gpt-2 don't match the paper”. *GitHub, huggingface/transformers, Issue \#483*. <a href="https://github.com/huggingface/transformers/issues/483" class="external autonumber" rel="nofollow">[7]</a></span>
8.  <span id="cite_note-hu_long_context-8">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-hu_long_context_8-0) Hu, H., et al. “Can Perplexity Reflect Large Language Model's Ability in Long Text Understanding?”. *arXiv:2405.06105* \[cs.CL\], 10 мая 2024 г. <a href="https://ar5iv.labs.arxiv.org/html/2405.06105" class="external autonumber" rel="nofollow">[8]</a></span>
9.  <span id="cite_note-wang_unreliable-9">[↑](https://systems-analysis.info/int/Perplexity_(metric)_%E2%80%94_%E5%9B%B0%E6%83%91%E5%BA%A6#cite_ref-wang_unreliable_9-0) Wang, C., et al. “Perplexity by PLM Is Unreliable for Evaluating Text Quality”. *arXiv:2210.05892* \[cs.CL\], 12 окт. 2022 г. <a href="https://ar5iv.labs.arxiv.org/html/2210.05892" class="external autonumber" rel="nofollow">[9]</a></span>
