关于人工智能:Prompt-技巧指南让-ChatGPT-回答准确十倍

3次阅读

共计 2628 个字符,预计需要花费 7 分钟才能阅读完成。

出品人:Towhee 技术团队 作者:张晨

随着 ChatGPT 等大型语言模型 (LLM)的衰亡,人们缓缓发现,怎么样向 LLM 发问、以什么技巧发问,是取得更加精确的答复的要害,也由此产生了提醒工程这个全新的畛域。

提醒工程 (prompt engineering) 是一门绝对较新的畛域,用于开发和优化提醒以无效地将语言模型 (LM) 用于各种应用程序和钻研主题。即时的工程技能有助于更好地了解 LLM 的性能和局限性。钻研人员应用提醒工程来进步 LLM 在宽泛的常见和简单工作(例如问题答复和算术推理)上的能力。开发人员应用提醒工程来设计与 LLM 和其余工具交互的弱小且无效的提醒技术。

本指南介绍一些常见的 prompt 高级办法,能够帮忙你从 LLM 失去更加精确的答复。

Zero-shot(零样本)

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

Prompt:

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

输入:

Neutral

Few-Shot(少样本)

尽管大型语言模型曾经展现了卓越的零样本能力,但在应用零样本设置时它们依然无奈实现更简单的工作。为了改良这一点,应用大量提醒作为一种技术来启用上下文学习,在提醒中提供样例以疏导模型取得更好的性能。这些样例用作后续示例的条件,咱们心愿模型在这些示例中生成响应。

Prompt:

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:

输入:

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:

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

输入:

Yes, the odd numbers in this group add up to 107, which is an even number.

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

思维链 (CoT)提醒能够通过两头推理步骤启用简单的推理能力。咱们能够将它与大量提醒联合应用,以便更简单的推理工作中取得更好的后果。比方在下面的例子中,咱们用 CoT 办法即可失去正确的后果。

Prompt:

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:

输入:

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:

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.

输入:

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

相干材料:

  • GitHub 指南:https://github.com/dair-ai/Prompt-Engineering-Guide
  • 中文指南:https://www.promptingguide.ai/zh

本文由 mdnice 多平台公布

正文完
 0