> 自媒体 > AI人工智能 > 释放ChatGPT的真正潜力:Prompt技巧完整指南
释放ChatGPT的真正潜力:Prompt技巧完整指南
来源:Freemen聊技术
2023-04-03
356
管理

早上好~ 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的例子:

1
点赞
赏钱
0
收藏
免责声明:本文仅代表作者个人观点,与华威派无关。其原创性以及文中陈述文字和内容未经本网证实,对本文以及其中全部或者 部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
凡本网注明 “来源:XXX(非华威派)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对 其真实性负责。
如因作品内容、版权和其它问题需要同本网联系的,请在一周内进行,以便我们及时处理。
QQ:2443165046 邮箱:info@goodmaoning.com
关于作者
清水大树(普通会员)
点击领取今天的签到奖励!
签到排行
1
0
分享
请选择要切换的马甲:

个人中心

每日签到

我的消息

内容搜索