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

相关推荐
马拉AI3 小时前
Andrej Karpathy 发布新项目 nanochat:一个从零开始构建的极简全栈式 ChatGPT 克隆
chatgpt
神码小Z13 小时前
特斯拉前AI总监开源的一款“小型本地版ChatGPT”,普通家用电脑就能运行!
人工智能·chatgpt
mit6.82415 小时前
[tile-lang] 张量核心 | 传统MMA->WGMMA | 底层自动选择优化
人工智能·chatgpt
AI拉呱_17 小时前
第144期《2025年AI现状报告》解读(二):产业篇
人工智能·chatgpt
哪吒编程2 天前
谁是最强编程大模型?横向对比GPT-5、GPT-5 Codex、Claude Sonnet 4.5、Gemini 2.5 Pro
gpt·chatgpt·claude
许泽宇的技术分享2 天前
百刀打造ChatGPT:nanochat极简LLM全栈实现深度解析
chatgpt·transformer·大语言模型·nanochat
算家计算2 天前
AI大神100美元手搓ChatGPT!nanochat教程爆火,4小时炼成聊天机器人
人工智能·chatgpt·资讯
猫头虎2 天前
Paper2Agent:将科研论文转化为可交互的AI智能体工具项目
人工智能·prompt·aigc·交互·pip·agi·ai-native
声网3 天前
阿里发布「夸克 AI 眼镜」:融合阿里购物、地图、支付生态;苹果拟收购计算机视觉初创 Prompt AI丨日报
人工智能·计算机视觉·prompt
Wade_Crab4 天前
第二章:动态 Prompt 管理与多科室智能问答系统
人工智能·spring·prompt