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 也用代码回答。

相关推荐
敲代码不忘补水1 小时前
Prompt 初级版:构建高效对话的基础指南
prompt
饮尽夏日1 小时前
【PromptEngineeringGuide】用自己的话复述总结
prompt
给自己一个 smile1 小时前
如何高效使用Prompt与AI大模型对话
人工智能·ai·prompt
龙的爹23338 小时前
论文翻译 | LLaMA-Adapter :具有零初始化注意的语言模型的有效微调
人工智能·gpt·语言模型·自然语言处理·nlp·prompt·llama
CM莫问8 小时前
大语言模型入门(三)——提示词编写注意事项
人工智能·语言模型·自然语言处理·prompt·kimi
学习前端的小z13 小时前
【AIGC】ChatGPT提示词解析:如何打造个人IP、CSDN爆款技术文案与高效教案设计
人工智能·chatgpt·aigc
三桥君20 小时前
Prompt:在AI时代,提问比答案更有价值
人工智能·ai·大模型·prompt·产品经理·三桥君
敲代码不忘补水20 小时前
Prompt 模版解析:诗人角色的创意引导与实践
prompt·提示词工程·langgpt 提示词·结构化提示词
Jet-W1 天前
Prompt技巧总结和示例分享
ai·prompt·ai对话
wgggfiy1 天前
chatgpt学术科研prompt模板有哪些?chatgpt的学术prompt有哪些?学术gpt,学术科研
论文阅读·人工智能·gpt·chatgpt·prompt·aigc