Prompt 技巧指南-让 ChatGPT 回答更准确

随着 ChatGPT 等大型语言模型 (LLM)的兴起,人们慢慢发现,怎么样向 LLM 提问、以什么技巧提问,是获得更加准确的回答的关键,也由此产生了提示工程这个全新的领域。

提示工程(prompt engineering)是一门相对较新的领域,用于开发和优化提示以有效地将语言模型 (LM) 用于各种应用程序和研究主题。即时的工程技能有助于更好地理解LLM的功能和局限性。研究人员使用提示工程来提高 LLM 在广泛的常见和复杂任务(例如问题回答和算术推理)上的能力。开发人员使用提示工程来设计与 LLM 和其他工具交互的强大且有效的提示技术。

本指南介绍一些常见的 prompt 高级方法,可以帮助你从 LLM 得到更加准确的回答。

Zero-shot (零样本)

即不提供任何参考回答案例,直接问问题,这是最简单的,也是人机交互或者聊天时,最常见的方式。

Prompt:

bash 复制代码
1 Classify the text into neutral, negative, or positive. 
2 
3 Text: I think the vacation is okay.
4 Sentiment:

输出:

bash 复制代码
Neutral

Few-Shot (少样本)

虽然大型语言模型已经展示了卓越的零样本能力,但在使用零样本设置时它们仍然无法完成更复杂的任务。为了改进这一点,使用少量提示作为一种技术来启用上下文学习,在提示中提供样例以引导模型获得更好的性能。这些样例用作后续示例的条件,我们希望模型在这些示例中生成响应。

Prompt:

bash 复制代码
1 A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses
2 the word whatpu is:
3 We were traveling in Africa and we saw these very cute whatpus.
4 To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses
5 the word farduddle is:

输出:

bash 复制代码
When we won the game, we all started to farduddle in celebration.

我们可以观察到,该模型仅通过提供一个示例(即 1-shot)就以某种方式学会了如何执行任务。对于更困难的任务,我们可以尝试增加样例(例如,3-shot、5-shot、10-shot 等)。

Chain-of-Thought(CoT)

当我们问一个稍微复杂的问题,可能会得到错误的回答。

Prompt:

bash 复制代码
1 The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. 
2 
3 A: 

输出:

bash 复制代码
Yes, the odd numbers in this group add up to 107, which is an even number.

这不是正确的回答,这个例子表现出了原始模型的局限性,也意味着需要更高级的提示工程。

思想链 (CoT)提示可以通过中间推理步骤启用复杂的推理能力。我们可以将它与少量提示结合使用,以便更复杂的推理任务中获得更好的结果。比如在上面的例子中,我们用 CoT 方法即可得到正确的结果。

Prompt:

bash 复制代码
1 The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.
2 A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False.
3 
4 The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1. 
5 A:

输出:

bash 复制代码
Adding all the odd numbers (15, 5, 13, 7, 1) gives 41. The answer is False.

Zero-Shot CoT

Zero-shot 可以和 CoT 结合起来用,即不给例子,直接让 LLM 在回答里带上一步步思考,并得到最后的答案。这样即省了 token 的消耗,又可以得到准确的答案。最常见的一种方式是在问题后面加上 "Let's think step by step"。

Prompt:

bash 复制代码
1 I went to the market and bought 10 apples. I gave 2 apples to the neighbor and 2 to the repairman. I then went and bought 5 more apples and ate 1. How many apples did I remain with?
2 
3 Let's think step by step.

输出:

bash 复制代码
1 First, you started with 10 apples.
2 You gave away 2 apples to the neighbor and 2 to the repairman, so you had 6 apples left.
3 Then you bought 5 more apples, so now you had 11 apples.
4 Finally, you ate 1 apple, so you would remain with 10 apples.

Automatic Prompt Engineer (APE)

自动提示工程 (Automatic Prompt Engineer,APE )将"用 prompt 生成问题"定义为"自然语言合成",是一个黑盒优化问题。它首先使用一个大型语言模型(作为推理模型)提供输出样例,以生成任务的候选 prompt。这些候选解决方案将指导搜索过程。APE 最后会使用目标模型执行 prompt,然后根据计算的评估分数选择最合适的 prompt。

PAL (Program-Aided Language Models)

Program-Aided Language Models(程序辅助语言模型)使用 LLM 阅读自然语言问题,并生成程序作为中间推理步骤的方法。(PAL) 与思维链提示的不同之处在于,它不是使用自由格式的文本来获得解决方案,而是将解决方案步骤变为编程代码运行,提高了结果的准确性。该方法的缺点是需要较长的提示样例,通常也是一些程序代码,这样才能让 LLM 也用代码回答。

相关推荐
kakaZhui1 小时前
【多模态大模型】端侧语音大模型minicpm-o:手机上的 GPT-4o 级多模态大模型
人工智能·chatgpt·aigc·llama
风雨中的小七4 小时前
解密prompt系列49. 回顾R1之前的思维链发展路线
prompt
坚毅不拔的柠檬柠檬12 小时前
AI革命下的多元生态:DeepSeek、ChatGPT、XAI、文心一言与通义千问的行业渗透与场景重构
人工智能·chatgpt·文心一言
维维180-3121-145519 小时前
AI赋能生态学暨“ChatGPT+”多技术融合在生态系统服务中的实践技术应用与论文撰写
人工智能·chatgpt
♡喜欢做梦19 小时前
Deepseek 与 ChatGPT:AI 浪潮中的双子星较量
ai·chatgpt·deepseek
Orange--Lin1 天前
【用deepseek和chatgpt做算法竞赛】——还得DeepSeek来 -Minimum Cost Trees_5
人工智能·算法·chatgpt
技术程序猿华锋1 天前
OpenAI 周活用户破 4 亿,GPT-4.5 或下周发布,微软加紧扩容服务器
microsoft·chatgpt·deepseek
南 阳2 天前
百度搜索全面接入DeepSeek-R1满血版:AI与搜索的全新融合
人工智能·chatgpt
workflower2 天前
Prompt Engineering的重要性
大数据·人工智能·设计模式·prompt·软件工程·需求分析·ai编程
forestsea2 天前
DeepSeek 提示词:定义、作用、分类与设计原则
人工智能·prompt·deepseek