探秘神秘世界:量子物理对孩子来说是什么?🔥关注Freemen,探索更多科技奇观!🔍实习机会来啦,杭

学会提问 2年前 (2023) lida
177 0 0

文章主题:量子物理, 岗位推荐, 杭州

666ChatGPT办公新姿势,助力做AI时代先行者!

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

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

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

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

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

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

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

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

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

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

探秘神秘世界:量子物理对孩子来说是什么?🔥关注Freemen,探索更多科技奇观!🔍实习机会来啦,杭

一些通用原则

从简单到复杂:

在写一个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 dont 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 dont have any information about your interests. However, heres 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: ill 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 hes been stirred by the powerful work of his co-stars.

Sentiment: positive

Text: ill 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: ill bet the video game is a lot more fun than the film.

Sentiment:

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

Quantum physics might sound like a big word for a little one, but it’s all about tiny things that make our world work magic! Picture atoms, those tiny building blocks of everything, and instead of being solid, they can be in two places at once! That’s called superposition. And when you look really closely, these atoms can even change their behavior without anyone watching, which is called entanglement. It’s like having a toy that becomes different just because you think about it! This special kind of science helps us understand how light and matter interact in ways we never knew before. So next time you play with your blocks, imagine they’re quantum physicists exploring the universe! 🌟

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: Whats the oldest building in US?

Ouput: Location

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

Input: ill 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: Lets 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 = <<30*4=120>>120 minutes to climb the hill.

It takes Tom 120/60 = <<120/60=2>>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 = $<<9.5*2=19>>19. cost of the socks and shoes is $19 + $92 = $<<19+92=111>>111.

Jack need $111 – $40 = $<<111-40=71>>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只是简单增加了“lets think step by step“这句话,

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

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

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

一般给出的例子中,涉及的推导步骤越多、效果越好;但如果问题很简单、例子太过复杂,效果也不好如果例子涉及多个步骤,用换行符“\n”,要比用文字“第n步”,或者“.”、”;”等字符分隔多个步骤效果更好

Self-Ask(自我提问)(基于CoT的一个衍生技术):

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

从而形成一个思维链,

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

探秘神秘世界:量子物理对孩子来说是什么?🔥关注Freemen,探索更多科技奇观!🔍实习机会来啦,杭

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

分而治之:

对于复杂的问题,

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

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

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

极坐标系中,点$(-2, \frac{3\pi}{4})$的直角坐标是( ). A. $(2, -1)$ B. $(-1, 2)$ C. $(1, -2)$ D. $(-2, 1)$

Clues:

✨Scarlett alone graced the cozy lounge, her presence marking the room’s tranquility. 🤝In this serene space, she savored the moment, lost in thought amidst the soft lighting and comfortable seating. 💆‍♀️2. The vintage sofa exuded charm, its worn leather inviting a story to unfold. 📚 nearby, a stack of books whispered secrets, waiting for their next reader. 📖3. A gentle breeze danced through the windows, carrying the aroma of freshly brewed coffee that filled the air. ☕️A symphony of scents, it was the perfect配乐 for Scarlett’s solitude.4. The sound of爵士 music played softly in the background, adding a touch of elegance to the atmosphere. 🎵It seemed to harmonize with her own thoughts, mirroring her悠闲 pace.5. Time stood still as she indulged in her private sanctuary, away from the hustle and bustle of daily life. 🕞️6. Yet, amidst this serenity, a sense of connection lingered – a reminder that even in solitude, we are never truly alone. 💬Remember to keep the tone informative yet engaging, and use relevant keywords for SEO优化.

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

🌟Colonel Mustard, the sole occupant of the observatory, found himself alone amidst the stars. 🌠His presence, undisturbed by fellow stargazers, cast a solitary glow over the astronomical wonder. 🔑As the sole key holder, he held the secrets of the universe within his grasp, waiting for the next clue to unravel the mystery. 💡

🔍Professor Plum’s whereabouts were a mystery, as he failed to be found either 📚in the library or 🎳at 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

地点:杭州

探秘神秘世界:量子物理对孩子来说是什么?🔥关注Freemen,探索更多科技奇观!🔍实习机会来啦,杭

探秘神秘世界:量子物理对孩子来说是什么?🔥关注Freemen,探索更多科技奇观!🔍实习机会来啦,杭

AI时代,掌握AI大模型第一手资讯!AI时代不落人后!

免费ChatGPT问答,办公、写作、生活好得力助手!

扫码右边公众号,驾驭AI生产力!

相关文章