花粉乐分享平台宣传视频
> 乐学堂 > > 释放ChatGPT的真正潜力:Prompt技巧完整指南
释放ChatGPT的真正潜力:Prompt技巧完整指南
来源:Freemen聊技术
2023-04-03 09:46:52
303
管理

早上好~ Freemen又和大家见面啦,新的一周元气满满!

点关注,不迷路。记得关注我哦~

上次介绍了一些ChatGPT相关的小工具,

用过一段时间的同学都会发现,

Prompt(提示词)的好坏对于能否充分发挥ChatGPT的潜力有着决定性的作用。

那么我们如何最大化ChatGPT对我们学习、工作的助力呢?

本文将从简单到复杂,梳理一下目前常见的Prompt技巧,

他山之石可以攻玉,相信这些经验定能给大家带来帮助。

文末对本期重点进行了总结。

(下文中引用格式的内容为Prompt)

一些通用原则

从简单到复杂:

在写一个Prompt时,你可能会想到很多能让Prompt更好的点,

但最好还是先写一个简单的Prompt看效果,

不满意再逐步修改Prompt增加更多的提示,

很多时候我们会发现简单的Prompt就可以得到不错的效果。

Prompt要足够具体:

一般Prompt越具体,描述性越强,其效果越好。

这里更重要的是Prompt的格式和描述,

不要试图找到一两个魔法词,一下就能提高效果。

同时也要注意平衡Prompt的长度,

简单但具体的Prompt是最好的,

毕竟ChatGPT有Context大小限制,

太多不必要的细节可能还会起到反作用。

避免使用模糊的词:

比如下面这个Prompt:

"Explain the concept of prompt engineering. Keep the explanation short, only a few sentences, and don't be too descriptive."

"short","a few",”too"这几个词就比较模糊,而改成下面这个Prompt就准确了很多:

"Use 2-3 sentences to explain the concept of prompt engineering to a high school student."

说你要做什么,而不是不做什么:

有时你即使在Prompt中强调不要干什么,

但ChatGPT可能还是会忽略你的否定性要求,比如这个Prompt:

The following is an agent that recommends movies to a customer. DO NOT ASK FOR INTERESTS. DO NOT ASK FOR personal INFORMATION.

Customer: Please recommend a movie based on my interests.

Agent:

其得到的输出是:

Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?

而改成下面这样:

The following is an agent that recommends movies to a customer. The agent is responsible to recommend a movie from the top global trending movies. It should refrain from asking users for their preferences and avoid asking for personal information. .".

Customer: Please recommend a movie based on my interests.

Agent:

得到的输出是:

Sorry, I don't have any information about your interests. However, here's a list of the top global trending movies right now: [list of movies]. I hope you find something you like!

基础Prompt技巧

Zero-shot(零提示):

Prompt最基础的形式,

你直接向ChatGPT提出问题即可,

比如下面这个情感分类问题:

Text: i'll bet the video game is a lot more fun than the film.

Sentiment:

Few-shot(少量提示):

这个技巧就是先给ChatGPT几个例子,

然后让ChatGPT回答自己的问题,

还是上面的情感分类问题:

Text: (lawrence bounces) all over the stage, dancing, running, sweating, mopping his face and generally displaying the wacky talent that brought him fame in the first place.

Sentiment: positive

Text: despite all evidence to the contrary, this clunker has somehow managed to pose as an actual feature movie, the kind that charges full admission and gets hyped on tv and purports to amuse small children and ostensible adults.

Sentiment: negative

Text: for the first time in years, de niro digs deep emotionally, perhaps because he's been stirred by the powerful work of his co-stars.

Sentiment: positive

Text: i'll bet the video game is a lot more fun than the film.

Sentiment:

通过给ChatGPT提供几个例子,能显著提升其回答的准确性,

这里有几个需要注意的点:

例子和最后的问题越相似,效果越好例子的多样性越多,效果越好例子的排序最好随机,以上面的分类问题为例,先全部都是positive,然后全部都是negative容易误导ChatGPT如果你发现ChatGPT给出的答案总是一定的倾向性,可以试着打乱例子的排序看看效果Instruction (说明意图):

上面few-shot这个技巧,

本质可以理解为通过例子向ChatGPT说明自己的意图,

所以你也可以直接说明意图,之后再提出问题:

Please label the sentiment towards the movie of the given movie review. The sentiment label should be "positive" or "negative".

Text: i'll bet the video game is a lot more fun than the film.

Sentiment:

指出你的目标受众是另一种说明意图的方法:

Describe what is quantum physics to a 6-year-old kid.

Few-shot Instruction:

你也可以把few-shot和Instruction组合起来进一步说明意图:

Definition: Determine the speaker of the dialogue, "agent" or "customer".

Input: I have successfully booked your tickets.

Ouput: agent

Definition: Determine which category the question asks for, "Quantity" or "Location".

Input: What's the oldest building in US?

Ouput: Location

Definition: Classify the sentiment of the given movie review, "positive" or "negative".

Input: i'll bet the video game is a lot more fun than the film.

Output:

Chain of Thought(CoT,思维链):

即告诉ChatGPT要先给出思考过程,最后再给出最终答案,

有点像做数学题,需要先给出中间的推导步骤,最后才是最终答案。

下面是一个Zero-shot 的CoT:

Question: Marty has 100 centimeters of ribbon that he must cut into 4 equal parts. Each of the cut parts must be divided into 5 equal parts. How long will each final cut be?

Answer: Let's think step by step:

也可以在CoT中加入几个例子,下面是一个Few-shot的CoT:

Question: Tom and Elizabeth compete to climb a hill. Elizabeth takes 30 minutes. Tom takes four times as long as Elizabeth does. How many hours does it take Tom to climb up the hill?

Answer: It takes Tom 30*4 = <>120 minutes to climb the hill.

It takes Tom 120/60 = <>2 hours to climb the hill.

So the answer is 2.

===

Question: Jack needs to buy two pairs of socks and a pair of soccer shoes. Each pair of socks cost $9.50, and the shoes cost $92. Jack has $40. How much more money does Jack need?

Answer: The cost of socks is $9.50 x 2 = $<>19. cost of the socks and shoes is $19 $92 = $<>111.

Jack need $111 - $40 = $<>71 more.

So the answer is 71.

===

Question: Marty has 100 centimeters of ribbon that he must cut into 4 equal parts. Each of the cut parts must be divided into 5 equal parts. How long will each final cut be?

Answer:

思维链虽然在我们看起来很简单,

甚至Zero-shot的CoT只是简单增加了“let's think step by step"这句话,

但其推理能力却出现了巨大的提升,你可能想知道为什么会这样?

很遗憾,目前还没有明确的研究结果。

使用CoT也有两个需要注意的细节:

一般给出的例子中,涉及的推导步骤越多、效果越好;但如果问题很简单、例子太过复杂,效果也不好如果例子涉及多个步骤,用换行符"n",要比用文字"第n步",或者"."、";"等字符分隔多个步骤效果更好Self-Ask(自我提问)(基于CoT的一个衍生技术):

其基本思路就是让ChatGPT不断地问自己问题(问题的答案则可以来自外部API),

从而形成一个思维链,

下面是一个Few-shot self-ask的例子:

LangChain也有一个类似的实现,有兴趣的同学可以参考以详细了解这个技术。

分而治之:

对于复杂的问题,

CoT是让ChatGPT自己把思考过程写下来,

我们也可以人为地为ChatGPT设定思考过程,或者说是工作流程,

以下是OpenAI自己给出的例子:

Use the following clues to answer the following multiple-choice question.Clues:1. Miss Scarlett was the only person in the lounge.2. The person with the pipe was in the kitchen.3. Colonel Mustard was the only person in the observatory.4. Professor Plum was not in the library nor the billiard room.5. The person with the candlestick was in the observatory.

Question: Was Colonel Mustard in the observatory with the candlestick?(a) Yes; Colonel Mustard was in the observatory with the candlestick(b) No; Colonel Mustard was not in the observatory with the candlestick(c) Unknown; No enough information to determine whether Colonel Mustard was in the observatory with the candlestickSolution:

得到的答案是:

Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick

现在让我们换个Prompt为ChatGPT设定工作思路:

Use the following clues to answer multiple-choice questions with this procedure:

(1) First, go through the clues one by one and consider whether the clue is potentially relevant

(2) Second, combine the relevant clues to reason out the answer to the question (3) Third, map the answer to one of the multiple choice answers: either (a), (b), or (c)

Clues:

1. Miss Scarlett was the only person in the lounge.

2. The person with the pipe was in the kitchen.

3. Colonel Mustard was the only person in the observatory.

4. Professor Plum was not in the library nor the billiard room.

5. The person with the candlestick was in the observatory.

Question: Was Colonel Mustard in the observatory with the candlestick?

(a) Yes; Colonel Mustard was in the observatory with the candlestick

(b) No; Colonel Mustard was not in the observatory with the candlestick

(c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick

Solution:

(1) First, go through the clues one by one and consider whether the clue is potentially relevant:

我们得到的输出是:

Clue 1: Miss Scarlett was the only person in the lounge. This clue is not relevant.

Clue 2: The person with the pipe was in the kitchen. This clue is not relevant.

Clue 3: Colonel Mustard was the only person in the observatory. This clue is relevant.

Clue 4: Professor Plum was not in the library nor the billiard room. This clue is not relevant.

Clue 5: The person with the candlestick was in the observatory. This clue is relevant.

(2) Second, combine the relevant clues to reason out the answer to the question:

Clue 3 and Clue 5 both say that the person with the candlestick was in the observatory. Colonel Mustard was the only person in the observatory, so Colonel Mustard was the person with the candle

(3) Third, write the final answer:

(a) Yes; Colonel Mustard was in the observatory with the candlestick

这回我们得到了正确答案。

重点总结

无论使用什么Prompt技巧,都应该让你的Prompt尽可能简单、具体、准确,有话直说;在此基础上,才是Zero-shot, Few-shot, Instruction, CoT以及分而治之等技巧;在Few-shot中,例子的多样性和排序对结果有较大的影响;在CoT中,例子的复杂度和描述方式对结果也有很大影响;这些技巧还可以组合起来使用:如Few-Shot Instruction, Zero-shot CoT, Few-Shot CoT等;CoT还有一个衍生技术叫做Self-Ask:让ChatGPT自己提问,我们通过外部API来给它答案,帮助它逐步推导出问题的答案;除了本文描述的基础技巧外,还有一些更复杂的Prompt技术,后面继续同大家分享。

文章来源:我的两分钱 作者:我的两分钱

今天就介绍到这里,下面是今天的岗位推荐,来Freemen app查看更多高薪IT岗位!

记得点关注哦~

今日推荐:

安卓开发工程师

岗位要求:

1. 全日制统招本科毕业,3年左右工作经验;

2. 精通Android高级特性和SDK的使用,熟练掌握品牌手机和Android版本之间的区别;

3. 熟练掌握Android各种调优工具,可以精确定位bug,熟练掌握IO,内存和CPU的优化;

4. 掌握Android端电量和流量优化技巧;

5. 掌握安卓中绘图机制;

6.有JNI编程优先的考虑。

薪资:20-30K

地点:杭州

花粉社群VIP加油站

1
点赞
赏礼
赏钱
0
收藏
免责声明:本文仅代表作者个人观点,与花粉乐分享无关。其原创性以及文中陈述文字和内容未经本网证实,对本文以及其中全部或者 部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
凡本网注明 “来源:XXX(非花粉乐分享)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对 其真实性负责。
如因作品内容、版权和其它问题需要同本网联系的,请在一周内进行,以便我们及时处理。
QQ:2443165046 邮箱:info@hflfx.com
关于作者
(Array)
文章
455
主题
0
关注
0
粉丝
0
点击领取今天的签到奖励!
签到排行
随手拍
54个圈友 0个话题
华为手机随手拍,记录生活点滴之美好
华为P30pro
51个圈友 0个话题
这里是华为P30pro手机交流圈,欢迎华为P30pro用户进群交流
体验官
60个圈友 2个话题
华为花粉体验官,体验官专属的交流群
登录后查看您创建的圈子
登录后查看您创建的圈子
所有圈子
猜你喜欢
杭州互联网违法和不良信息举报平台 网络110报警服务 浙ICP备17046585号
1
0
分享
请选择要切换的马甲:

个人中心

每日签到

我的消息

内容搜索