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

相关推荐
张艾拉 Fun AI Everyday24 分钟前
从 ChatGPT 到 OpenEvidence:AI 医疗的正确打开方式
人工智能·chatgpt
zhangfeng113331 分钟前
DrugGPT chatgpt druggen 之间的关系 ,DrugGPT是基于gpt2基础上开发的
chatgpt·生物信息
BeingACoder6 小时前
【SAA】SpringAI Alibaba学习笔记(二):提示词Prompt
java·人工智能·spring boot·笔记·prompt·saa·springai
leafff12310 小时前
一文了解LLM应用架构:从Prompt到Multi-Agent
人工智能·架构·prompt
Ztop11 小时前
GPT-5.1 已确认!OpenAI下一步推理升级?对决 Gemini 3 在即
人工智能·gpt·chatgpt
檀越剑指大厂1 天前
【ChatGPT系列】ChatGPT Atlas:未来浏览器的智慧体验
chatgpt
托尼吴1 天前
理解提示词Prompt
prompt
Hello.Reader1 天前
思维链(CoT)× 智能体(Agent)× 提示词(Prompt)讲解
prompt·agent·cot
Geo_V2 天前
OpenAI 大模型 API 使用示例
python·chatgpt·openai·大模型应用·llm 开发
福大大架构师每日一题2 天前
⽬前 主流的开源模型体系 有哪些?
chatgpt·开源