# 第九章：解码策略：模型如何生成文本

训练好的语言模型拥有了对文本的深层理解和生成能力，但**如何从模型输出的概率分布中选取词元来构建完整的文本**，是一个独立且重要的技术问题。不同的解码策略直接影响生成文本的质量、多样性和一致性。

本章将从自回归解码的基本机制出发，逐步讨论贪心搜索、束搜索和各种采样策略的设计逻辑与适用场景，并探讨推理时计算扩展这一新兴范式——如何通过在推理阶段投入更多计算来提升模型的深度推理能力。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yeasy.gitbook.io/llm_internals/di-san-bu-fen-tui-li-yu-bu-shu-pian/09_decoding.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
