GPT 使用指南
GPT 是使用对话的方式进行使用的, 但是与我们平时聊天不同的是, GPT 并不能限定聊天的上下文.
就比如你与你的朋友进行聊天, 其实是限定了你与你的朋友之间这样的一个范围, 你们的上下文就是关于你们看到的事情或者是你们共同知道的事情, 这时你们聊天就就非常自然. 不需要去限定范围, 而且你的朋友以及你都相互了解对方, 知道以什么样的方式进行对话, 因为谈话对象不同就已经天然的限定了范围.
所以, 如果你在使用 GPT 的过程中没有去限定范围你的对话范围, 以及你想要什么, 那么你大概率会得到一个非常宽泛的答案. 因为 GPT 并不知道你的习惯, 你询问的问题具体范围, 你预期的答案是什么样的格式的, 等等. 这样导致我们可能需要进行多轮对话, 或者得不到我们想要的答案. 以下是我找到的一些方法, 希望能够帮到你.
怎么进行提问
Zero-Shot Chain of Thought
其实我们刚刚开始时候使用, 大多数都是使用 Zero-Shot Prompts
也就是直接提问, 因为没有限定范围. 所以因为它的灵活性和通用性,它的输出有时可能不够准确,或不符合预期。这可能需要对模型进行进一步的微调或添加更多的提示文本来纠正
所以针对此, 提出了 Zero-Shot Chain of Thought
也就是在你的提问结尾加上 Let's work this out in a step by step way to be sure we have the right answer.
. 让模型的输出更加准确. 这个做法是来自Large Language Models Are Human-Level Prompt Engineers
为什么加上这句话能提高 GPT 的输出结果的正确性. 因为 GPT 是按照前面生成的内容来决定后续生成的内容的. 每个字都是, 所以如果你让他将自己推理的过程展示出来, 大概率结果会更加准确.
就像下面这个例子:
不过并不能保证结果完全正确, 因为只要其中的推理步骤出现错误, 那么就可能导致最终结果的错误.
旧版本是这篇论文, 使用的是
Let‘s think step by step
不过这个方法对模型大小有要求(2022 年 Wei 等人的论文表明)
Few-Shot Chain of Thought
说明 Few-Shot Prompting 之前, 先了解下 Few-Shot ,通过给 GPT 模型展示一些输入和输出的配对样例,让它学习任务的逻辑和格式,然后用同样的方式处理新的输入.
以下是 Brown 等人在 2020 年论文中使用的例子1
2
3
4
5A "whatpu" is a small, furry animal native to Tanzania. An example of a sentence that uses
the word whatpu is:
We were traveling in Africa and we saw these very cute whatpus.
To do a "farduddle" means to jump up and down really fast. An example of a sentence that uses
the word farduddle is:
输出是这样的:1
When we won the game, we all started to farduddle in celebration.
但就像 Zero-Shot 中的一样, 可能会出现逻辑问题. 所以就可以用类似 Zero-Shot Chain of Thought 中的方式, 在给出示例的同时, 也给出推理的步骤.
Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
通过向大语言模型展示一些少量的样例,并在样例中解释推理过程,大语言模型在回答提示时也会显示推理过程。这种推理的解释往往会引导出更准确的结果。
论文中举例了一个例子:1
2
3
4
5
6
7
8
9
10
11
12
13
14The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.
A: The answer is False.
The odd numbers in this group add up to an even number: 17, 10, 19, 4, 8, 12, 24.
A: The answer is True.
The odd numbers in this group add up to an even number: 16, 11, 14, 4, 8, 13, 24.
A: The answer is True.
The odd numbers in this group add up to an even number: 17, 9, 10, 12, 13, 4, 2.
A: The answer is False.
The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
A:
得到结果:1
The answer is True.
相比这样询问:1
2
3
4
5
6
7
8
9
10
11
12
13
14The odd numbers in this group add up to an even number: 4, 8, 9, 15, 12, 2, 1.
A: Adding all the odd numbers (9, 15, 1) gives 25. The answer is False.
The odd numbers in this group add up to an even number: 17, 10, 19, 4, 8, 12, 24.
A: Adding all the odd numbers (17, 19) gives 36. The answer is True.
The odd numbers in this group add up to an even number: 16, 11, 14, 4, 8, 13, 24.
A: Adding all the odd numbers (11, 13) gives 24. The answer is True.
The odd numbers in this group add up to an even number: 17, 9, 10, 12, 13, 4, 2.
A: Adding all the odd numbers (17, 9, 13) gives 39. The answer is False.
The odd numbers in this group add up to an even number: 15, 32, 5, 13, 82, 7, 1.
A:
就能得到正确的结果1
Adding all the odd numbers (15, 5, 13, 7, 1) gives 41. The answer is False.
不过根据 论文 的研究表明. 标签的正确性不重要, 即使是随机的标签, 使用适当的格式也能得到你想要的.
相关信息: 斯坦福大学的讲义Natural Language Processing with Deep Learning
使用 Prompt 框架
Elavis Saravia
Elavis Saravia 总结了 prompt 的使用方式
- Instruction (必须): 希望执行的任务
- Context (可选): 提供上下文语境
- Input Data (可选): 为模型提供数据
- Output Indicator (可选): 告知我们想要的输出方式
这些元素你可以随意组合:
对信息进行处理: Instruction + Input Data + Output Indicator
推理:Instruction + Context + Input Data
Matt Nigh
Matt Nigh 定义的 CRISPE 也是另外一个不错的选择.
主要定义了以下规则
- CR:Capacity and Role:你希望 ChatGPT 扮演的角色或者拥有的能力。例如,你可以让 ChatGPT 扮演一个专家、一个老师、一个朋友、一个助手等等。你也可以告诉 ChatGPT 你需要 ChatGPT 具备什么样的知识、技能或者经验。这样, ChatGPT 可以根据你的要求来调整 ChatGPT 的回答或者行为。
- I: Insight: 是指对你的请求的背景、情境和目的的解释。它可以帮助 ChatGPT 更好地理解你想要 ChatGPT 做什么,以及为什么要这样做
- S: Statement:这个词语是指你具体要求 ChatGPT 做什么。例如,你可以让 ChatGPT 回答一个问题、写一篇文章、生成一张图片、编写一段代码等等。你应该尽量清楚地描述你的任务,包括任务的内容、范围、格式、要求等等。
- P: Personality:这个词语是指你希望 ChatGPT 展现的风格、性格或者态度。例如,你可以让 ChatGPT 表现得幽默、严肃、友好、专业等等。你也可以告诉 ChatGPT 你喜欢哪些人或者作品的风格,让 ChatGPT 参考他们的方式来回答或者创作。
- E: Experiment:这个词语是指你想要 ChatGPT 给你提供多个不同的例子或者方案。例如,你可以让 ChatGPT 给你展示几种不同的图片风格、文章结构、代码实现等等。这样,你可以从中选择最适合你的那一个,或者对比他们的优缺点。
步骤 | 示例提示 |
---|---|
Capacity and Role(能力和角色) | Act as an expert on software development on the topic of machine learning frameworks, and an expert blog writer. (作为一个软件开发方面的专家,以及一个机器学习框架主题的博客作者。 ) |
Insight(情境) | The audience for this blog is technical professionals who are interested in learning about the latest advancements in machine learning. (这篇博客的受众是对机器学习最新进展感兴趣的技术专业人士。 ) |
Statement(任务) | Provide a comprehensive overview of the most popular machine learning frameworks, including their strengths and weaknesses. Include real-life examples and case studies to illustrate how these frameworks have been successfully used in various industries. (提供一个全面的概述,介绍最流行的机器学习框架,包括它们的优势和劣势。包含真实的例子和案例分析,说明这些框架在不同行业中的成功应用。 ) |
Personality(风格) | When responding, use a mix of the writing styles of Andrej Karpathy, Francois Chollet, Jeremy Howard, and Yann LeCun. (在回答时,使用 Andrej Karpathy、Francois Chollet、Jeremy Howard 和 Yann LeCun 这四位大牛的写作风格的混合。 ) |
Experiment(实验) | Give me multiple different examples. (给我多个不同的例子。 ) |
最终的输出结果是这样1
Act as an expert on software development on the topic of machine learning frameworks, and an expert blog writer. The audience for this blog is technical professionals who are interested in learning about the latest advancements in machine learning. Provide a comprehensive overview of the most popular machine learning frameworks, including their strengths and weaknesses. Include real-life examples and case studies to illustrate how these frameworks have been successfully used in various industries. When responding, use a mix of the writing styles of Andrej Karpathy, Francois Chollet, Jeremy Howard, and Yann LeCun.