← 返回目录

Sampling controls

第 4 / 34 卷日期:

减少大语言模型( LLM)的输出长度并不会使其生成的文本在风格或内容上更简洁,它只是让模型在达到限制时停止预测更多标记。若您需要更短的输出长度,可能还需对提示进行针对性设计以适应需求。

输出长度限制对某些 LLM 提示技术尤为重要,例如 ReAct(推理 ‑ 行动循环),该场景下模型可能会在所需响应后持续生成无用标记。

需注意:生成更多标记会消耗 LLM 更多算力,导致能耗增加、响应延迟及成本上升。

采样控制

大语言模型( LLM)并非直接预测单一标记,而是预测下一个可能标记的概率分布,模型词汇表中的每个标记都会被赋予一个概率值。随后通过采样这些概率分布来决定实际输出的标记。

温度( Temperature)、 Top‑K 和 Top‑P 是最常见的配置参数,用于控制如何根据预测出的标记概率筛选出最终输出的单个标记。

温度

温度参数控制标记选择的随机性程度。较低温度适用于需要确定性输出的提示词,而较高温度可能产生更多样化或出人意料的结果。当温度设为 0 时(贪婪解码模式)

全站分卷索引 · 34 卷
  1. 1Introduction
  2. 2Prompt engineering
  3. 3LLM output configuration
  4. 4Sampling controls
  5. 5Top-K and top-P
  6. 6Putting it all together
  7. 7Prompting techniques
  8. 8One-shot & few-shot
  9. 9System, contextual and role prompting
  10. 10System prompting
  11. 11Role prompting
  12. 12Contextual prompting
  13. 13Step-back prompting
  14. 14Chain of Thought (CoT)
  15. 15Self-consistency
  16. 16Tree of Thoughts (ToT)
  17. 17ReAct (reason & act)
  18. 18Automatic Prompt Engineering
  19. 19Code prompting
  20. 20Prompts for explaining code
  21. 21Prompts for translating code
  22. 22Prompts for debugging and reviewing code
  23. 23What about multimodal prompting?
  24. 24Design with simplicity
  25. 25Be specific about the output
  26. 26Control the max token length
  27. 27Experiment with input formats and writing styles
  28. 28Adapt to model updates
  29. 29JSON Repair
  30. 30Working with Schemas
  31. 31Experiment together with other prompt engineers
  32. 32CoT Best practices
  33. 33Summary
  34. 34Endnotes