Sampling controls
减少大语言模型( LLM)的输出长度并不会使其生成的文本在风格或内容上更简洁,它只是让模型在达到限制时停止预测更多标记。若您需要更短的输出长度,可能还需对提示进行针对性设计以适应需求。
输出长度限制对某些 LLM 提示技术尤为重要,例如 ReAct(推理 ‑ 行动循环),该场景下模型可能会在所需响应后持续生成无用标记。
需注意:生成更多标记会消耗 LLM 更多算力,导致能耗增加、响应延迟及成本上升。
采样控制
大语言模型( LLM)并非直接预测单一标记,而是预测下一个可能标记的概率分布,模型词汇表中的每个标记都会被赋予一个概率值。随后通过采样这些概率分布来决定实际输出的标记。
温度( Temperature)、 Top‑K 和 Top‑P 是最常见的配置参数,用于控制如何根据预测出的标记概率筛选出最终输出的单个标记。
温度
温度参数控制标记选择的随机性程度。较低温度适用于需要确定性输出的提示词,而较高温度可能产生更多样化或出人意料的结果。当温度设为 0 时(贪婪解码模式)
全站分卷索引 · 34 卷
- 1Introduction
- 2Prompt engineering
- 3LLM output configuration
- 4Sampling controls
- 5Top-K and top-P
- 6Putting it all together
- 7Prompting techniques
- 8One-shot & few-shot
- 9System, contextual and role prompting
- 10System prompting
- 11Role prompting
- 12Contextual prompting
- 13Step-back prompting
- 14Chain of Thought (CoT)
- 15Self-consistency
- 16Tree of Thoughts (ToT)
- 17ReAct (reason & act)
- 18Automatic Prompt Engineering
- 19Code prompting
- 20Prompts for explaining code
- 21Prompts for translating code
- 22Prompts for debugging and reviewing code
- 23What about multimodal prompting?
- 24Design with simplicity
- 25Be specific about the output
- 26Control the max token length
- 27Experiment with input formats and writing styles
- 28Adapt to model updates
- 29JSON Repair
- 30Working with Schemas
- 31Experiment together with other prompt engineers
- 32CoT Best practices
- 33Summary
- 34Endnotes