---
title: "Top-p sampling — Top-pサンプリング"
source: "https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0"
wiki: "systems-analysis.info/int"
article: "Top-p_sampling_—_Top-pサンプリング"
language: "ja"
categories:
  - "Category:Japanese"
  - "Category:Large language models"
  - "Category:LLM core concepts"
  - "Category:Machine learning"
  - "Category:Systems analysis terminology"
revision_id: 8230
wiki_created_at: 2026-09-07T01:14:17Z
wiki_modified_at: 2026-09-07T01:14:17Z
downloaded_at: 2026-09-07T23:24:12Z
---

# Top-p sampling — Top-pサンプリング

**Top‑pサンプリング**（**Top-p sampling**）は、**核サンプリング**（英語: *Nucleus Sampling*）としても知られ、テキスト生成のために大規模言語モデル（LLM）で使用される確率的なデコーディング手法です。この手法は2019年にAri Holtzmanらによって、固定的なTop‑kサンプリングの改良版として提案されました。その考え方は、生成の各ステップで累積確率のしきい値$p$に基づいて候補の集合を動的に選択することです。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)</sup>

## コンセプト

Top‑pの基本的な考え方は、各ステップで、合計確率が指定されたしきい値$p$以上となるような、最も確率の高いトークンの**最小**集合（*核*、英語: *nucleus*）を選択することです。数学的には、語彙$V$に対する条件付き確率分布$P(x \mid x_{1:i - 1})$について、核$V^{(p)}$は次のように定義できます：

$\sum\limits_{x \in V^{(p)}}P(x \mid x_{1:i - 1}) \geq p\quad\text{and}\quad\forall\, S \subset V^{(p)}:\ \sum\limits_{x \in S}P(x \mid x_{1:i - 1}) < p.$

これと同等の定義として、トークンを$P(x \mid x_{1:i - 1})$の降順でソートし、累積確率質量が$p$以上となる**最短のプレフィックス**を取る方法があります。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)</sup>

核が決定された後、$V^{(p)}$外のトークンの確率はゼロに設定され、核内部の確率は再正規化されます（合計が1になるように調整されます）。次のトークンは、この切り詰められた分布からサンプリングされます。

### 動的な適応

- 「鋭い」分布（モデルの確信度が高い場合）では、核は小さくなります。少数のトークンで累積確率が$p$以上に達するため、一貫性が向上します。
- 「平坦な」分布（もっともらしい続きの候補が多い場合）では、核は大きくなります。選択肢が広がり、多様性が増します。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)</sup>

## 他のデコーディング手法との比較

### Top‑p vs. Top‑k - Top-pとTop-kの比較

- **Top‑k**は常に、最も確率の高い固定数$k$個のトークンから選択を行います。「鋭い」分布では、これにより確率の低い不要な選択肢が「数を満たすために」追加される可能性があり、逆に「平坦な」分布では、トップ$k$に入らなかった妥当な続きが切り捨てられることがあります。
- **Top‑p**は各ステップのデータに応じて候補集合のサイズを調整するため、異なるタイプの分布に対してより柔軟で安定した挙動を示します。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)</sup>

### Top‑p vs. Temperature - Top-pとTemperatureの比較

- **Temperature**（温度）は、分布全体の形状を再形成する（より鋭く、またはより滑らかにする）が、トークンを**切り捨てることはない**ため、確率の低い選択肢でさえゼロではない確率を保持します。<sup>[\[2\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-hf-gen-2)</sup>
- **Top‑p**は、分布の**裾を厳密に切り捨てる**ため、低確率のトークンはサンプリングから完全に除外され、明らかに不適切な続きが生成されるのを防ぐのに役立ちます。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)</sup>

プロバイダーからの実践的なアドバイスとして、スタイルやランダム性を調整する際には、通常\`temperature\`**または**\`top_p\`の**いずれか**を変更し、両方を同時に変更することは避けるべきだとされています。これは、分布への「二重の」影響を避け、診断を容易にするためです。<sup>[\[3\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-azure-rec-3)</sup>

## 実践的な応用と推奨事項

Top-pは、その柔軟性と制御性の組み合わせにより、現代のLLMで広く利用されています。

- **典型的な値の範囲** 実践では、$p \approx 0.90\text{–}0.95$が頻繁に使用されます（Transformersのガイドや例を参照。多くのSDKでは**0.95**が「デフォルト」または推奨値として挙げられています）。<sup>[\[2\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-hf-gen-2)[\[4\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-vertex-params-4)</sup>
  - 1.0に近い値（例：0.98–0.99）は多様性を高めます。より多くのトークンが核に含まれるようになります。
  - 小さな値（例：0.80–0.90）は決定性を高め、出力の「抑制」を強めます。
  - $p = 1$の場合、切り捨ては行われなくなり、語彙全体から（temperatureを考慮して）選択が行われます。<sup>[\[2\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-hf-gen-2)</sup>

<!-- -->

- **ライブラリおよびAPIとの互換性**
  - Transformersには*TopPLogitsWarper*が実装されており、そこでは追加のしきい値\`min_tokens_to_keep\`（通常≥1）が使用されます。これは、非常に小さな$p$と「鋭い」分布の場合に核が空になるのを防ぎます。<sup>[\[5\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-hf-warp-5)</sup>
  - いくつかのAPIでは\`top_p\`パラメータが利用可能である一方、\`top_k\`は存在しない場合があります。パラメータのサポートとそのセマンティクスは、**特定のモデルやプロバイダーに依存します**（例えば、一部の推論モデルでは確率的設定が制限されることがあります）。詳細はOpenAI、Azure、Googleの公式ドキュメントを参照してください。<sup>[\[6\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-openai-top-p-6)[\[3\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-azure-rec-3)[\[4\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-vertex-params-4)</sup>

<!-- -->

- **長文テキストと反復性** 一連の実験により、nucleus samplingは、特に長いシーケンスにおいて、greedy/beamサーチや固定Top-kと比較して、テキストの変質（反復、決まり文句）への傾向を低減させることが示されています。<sup>[\[1\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-holtzman2019-1)[\[7\]](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_note-tan2024-7)</sup>

## 関連項目

- 温度
- 大規模言語モデル

## 参考文献

- Holtzman, A. et al. (2020). *The Curious Case of Neural Text Degeneration*. <a href="https://arxiv.org/abs/1904.09751" class="external text" rel="nofollow">arXiv:1904.09751</a>.
- Fan, A. et al. (2018). *Hierarchical Neural Story Generation*. <a href="https://arxiv.org/abs/1805.04833" class="external text" rel="nofollow">arXiv:1805.04833</a>.
- Meister, C. et al. (2023). *Locally Typical Sampling*. <a href="https://arxiv.org/abs/2202.00666" class="external text" rel="nofollow">arXiv:2202.00666</a>.
- Su, Y.; Collier, N. (2022). *Contrastive Search Is What You Need for Neural Text Generation*. <a href="https://arxiv.org/abs/2210.14140" class="external text" rel="nofollow">arXiv:2210.14140</a>.
- O’Brien, S.; Lewis, M. (2023). *Contrastive Decoding Improves Reasoning in Large Language Models*. <a href="https://arxiv.org/abs/2309.09117" class="external text" rel="nofollow">arXiv:2309.09117</a>.
- Yu, S. et al. (2023). *Conformal Nucleus Sampling*. <a href="https://aclanthology.org/2023.findings-acl.3.pdf" class="external text" rel="nofollow">ACL Findings 2023</a>.
- Tan, Q. et al. (2024). *A Thorough Examination of Decoding Methods in the Era of Large Language Models*. <a href="https://arxiv.org/abs/2402.06925" class="external text" rel="nofollow">arXiv:2402.06925</a>.
- Finlayson, M. et al. (2024). *Basis‑Aware Truncation Sampling for Neural Text Generation*. <a href="https://arxiv.org/abs/2412.14352" class="external text" rel="nofollow">arXiv:2412.14352</a>.
- Chen, S. J. et al. (2025). *Decoding Game: On Minimax Optimality of Heuristic Text Generation Methods*. <a href="https://arxiv.org/abs/2410.03968" class="external text" rel="nofollow">arXiv:2410.03968</a>.
- Sen, J. et al. (2025). *Advancing Decoding Strategies: Enhancements in Locally Typical Sampling for LLMs*. <a href="https://arxiv.org/abs/2506.05387" class="external text" rel="nofollow">arXiv:2506.05387</a>.

## 脚注

1.  <span id="cite_note-holtzman2019-1">↑ <sup>[1.0](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-0)</sup> <sup>[1.1](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-1)</sup> <sup>[1.2](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-2)</sup> <sup>[1.3](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-3)</sup> <sup>[1.4](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-4)</sup> <sup>[1.5](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-holtzman2019_1-5)</sup> Holtzman, A., Buys, J., Du, L., Forbes, M., & Choi, Y. (2019). *The Curious Case of Neural Text Degeneration*. arXiv:1904.09751. <a href="https://arxiv.org/abs/1904.09751" class="external autonumber" rel="nofollow">[1]</a></span>
2.  <span id="cite_note-hf-gen-2">↑ <sup>[2.0](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-hf-gen_2-0)</sup> <sup>[2.1](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-hf-gen_2-1)</sup> <sup>[2.2](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-hf-gen_2-2)</sup> Hugging Face Transformers. *Generation strategies (top‑k, top‑p, temperature)*. <a href="https://huggingface.co/docs/transformers/main/en/generation_strategies" class="external autonumber" rel="nofollow">[2]</a></span>
3.  <span id="cite_note-azure-rec-3">↑ <sup>[3.0](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-azure-rec_3-0)</sup> <sup>[3.1](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-azure-rec_3-1)</sup> Microsoft Learn (Azure OpenAI). *Text/Chat Completions — parameters*. 「temperatureまたはtop_pのいずれかを変更するが、両方を同時に変更しない」という推奨。<a href="https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/completions" class="external autonumber" rel="nofollow">[3]</a></span>
4.  <span id="cite_note-vertex-params-4">↑ <sup>[4.0](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-vertex-params_4-0)</sup> <sup>[4.1](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-vertex-params_4-1)</sup> Google AI / Vertex AI. *Generation parameters (topP/topK) for text/Gemini*. Examples with topP≈0.95. <a href="https://ai.google.dev/gemini-api/docs/parameters" class="external autonumber" rel="nofollow">[4]</a> <a href="https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text#parameters" class="external autonumber" rel="nofollow">[5]</a></span>
5.  <span id="cite_note-hf-warp-5">[↑](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-hf-warp_5-0) Transformers API. *TopPLogitsWarper* (parameters and behavior, including \`min_tokens_to_keep\`). <a href="https://huggingface.co/docs/transformers/main/en/main_classes/text_generation#transformers.TopPLogitsWarper" class="external autonumber" rel="nofollow">[6]</a></span>
6.  <span id="cite_note-openai-top-p-6">[↑](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-openai-top-p_6-0) OpenAI API Reference. *top_p*. <a href="https://platform.openai.com/docs/api-reference/chat/create#chat-create-top_p" class="external autonumber" rel="nofollow">[7]</a></span>
7.  <span id="cite_note-tan2024-7">[↑](https://systems-analysis.info/int/Top-p_sampling_%E2%80%94_Top-p%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AA%E3%83%B3%E3%82%B0#cite_ref-tan2024_7-0) Tan, Q. et al. (2024). *A Thorough Examination of Decoding Methods in the Era of Large Language Models*. arXiv:2402.06925. <a href="https://arxiv.org/abs/2402.06925" class="external autonumber" rel="nofollow">[8]</a></span>
