玩转ChatGPT:吴恩达/OpenAI合作教程《面向开发者的ChatGPT提示工程》

一、写在前面

最近,吴恩达与CloseOpenAI合作出了一个教程《面向开发者的ChatGPT提示工程》,第一时间就观摩了,有些体会,现在把个人觉得有意思的搬运过来。

我的机器学习入门就是看的吴恩达的教程!大佬长得像冯巩,哈哈哈。

原版视频地址:

https://www.deeplearning.ai/short-courses/chatgpt-prompt-engineering-for-developers/

B站已经有中文版:

https://space.bilibili.com/15467823/channel/seriesdetail?sid=3247315&ctype=0

下面是第一节课的笔记。多说一句,我觉得第一节课的内容干货满满(讲的是方法论,值得细细评味),后面的课都是基于这些原则展开:

二、提示工程的两个关键原则

(1)Write clear and specific instructions. 编写清晰而具体的指令

(a)你应该通过提供尽可能清晰和具体的指令来表达你希望模型做什么,这将引导模型走向预期的输出,并减少你得到不相关或不正确反应的机会。

(b)不要把写一个清晰的提示和写一个简短的指令混淆起来,因为在许多情况下,较长的指令实际上为模型提供了更清晰描述和上下文,可以带来更详细和相关的输出。

总结一下:指令越清晰越好,越具体越好,不要吝啬你的句子。

(c)帮助你写出清晰而具体的指示的第一个策略:使用分隔符来明确指出输入的不同部分。举个例子:

咒语:将 {文本} 中的主要内容总结成一句话,50个字左右。

{所谓的不平衡数据集指的是数据集各个类别的样本量极不均衡。以二分类问题为例,假设正类的样本数量远大于负类的样本数量,通常情况下通常情况下把多数类样本的比例接近100:1这种情况下的数据称为不平衡数据。不平衡数据的学习即需要在分布不均匀的数据集中学习到有用的信息。}

 总结一下:使用定界符(如大括号)可以使模型清晰地了解需要总结的确切文本,定界符可以是任何明确的标点符号,将特定文本片段与提示的其他部分分开。

(d)帮助你写出清晰而具体的指示的第二个策略:要求一个结构化的输出。比如说,以Markdown、HTML或JSON格式输出,或者像我之前以表格的形式展示。举个例子:

咒语:生成一个包含三个编造的书名作者和流派的列表。分别以表格的形式展示出它们的书籍ID、书名、作者和流派。

(e)帮助你写出清晰而具体的指示的第三个策略:要求模型检查条件是否得到满足。有点拗口,她是这么解释的,如果任务中的假设不一定被满足,那么我们可以告诉模型先检查这些假设。如果这些假设不被满足,指出这一点,并在完成任务的过程中停止。你也可以考虑潜在的边缘情况,告诉模型应该如何处理它们以避免意外的错误或结果。举个例子:

咒语:如果 {文本} 的主要内容包含步骤信息,那么按照下面格式对文本内容进行总结:

材料:

步骤:

第一步:...

第二步:-

第N步:-

如果 {文本} 的主要内容不包含步骤信息,那么久简单输出“无法改写”。

{啤酒鸭是一道非常受欢迎的烤鸭菜肴。制作啤酒鸭需要准备鸭子、啤酒、食盐、老抽、白糖、姜、大葱和香料袋(八角、草果、桂皮、丁香、花椒等)等材料。首先,将鸭子宰杀并清理干净,去掉内脏和头部,然后将鸭子整洗净备用。接下来,将香料袋中的香料放入锅中煸炒出香味,取出备用。然后,煮开一锅水,加入适量啤酒、食盐、老抽、白糖、姜、大葱和香料袋,煮至香味溢出。将煮好的啤酒汁放凉,将鸭子浸泡在啤酒汁中腌制4小时以上(越久越入味)。为了让鸭肉入味,可以在啤酒汁中加入适量盐和酱油,也可以在鸭子表面涂抹适量酱油和料酒。将腌制好的鸭子放在烤箱中,以180度烤40分钟,取出后涂上蜂蜜,再放回烤箱继续烤20分钟左右,直到鸭皮金黄酥脆。在烤制的过程中,可以根据自己口味调整烤制时间和温度,以达到最佳口感。最后,取出烤好的啤酒鸭,切成合适的块状即可食用。煮汁时可加入香料袋,使啤酒汁更香,涂上蜂蜜可增添甜味。享用啤酒鸭时,可以搭配啤酒或其他饮料,更加美味可口。}

 我把文本换一下:

(f)帮助你写出清晰而具体的指示的第四个策略:在指令中举一个具体的例子,让模型依葫芦画瓢。这个就不举例子了,大家都懂怎么操作。

总结:首先我们需要编写清晰而具体的指令。提供了4个策略,使用分隔符来明确指出输入的不同部分;要求一个结构化的输出;要求模型检查条件是否得到满足;在指令中举一个具体的例子,让模型依葫芦画瓢。

(2)Give the model time to think. 给模型思考的时间

大佬解释:如果一个模型因急于得出结论而出现推理错误,应该尝试重新设计询问,要求模型有一连串或一系列相关的推理,然后再由模型提供最终答案。如果你给一个模型一个太过复杂的任务,那么它就无法在短时间内或用很少的词来完成,最终可能会编造一个不正确的答案。

说人话就是,要给模型思考的时间,好比我们算一道数学题都要打草稿呢。

(a)第一个策略:指定完成一项任务所需的步骤。直接举例她的第一个例子:

咒语:Perform the following actions:

1 - Summarize the following text delimited by triple backticks with 1 sentence.

2 - Translate the summary into Chinses.

3 - List each name in the Chinese summary.

4 - Output a sheet object that contains the following keys: chinese_summary, num_names.

Separate your answers with line breaks.

Text:

‘’’ In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck-Jack tripped on a stone and tumbled down the hill, with Jill following suit. Through slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight. ‘’’

 然后,她又换了一个咒语(主要是输出格式有变化):

Perform the following actions:

1 - Summarize the following text delimited by <> with 1 sentence.

2 - Translate the summary into Chinese.

3 - List each name in the Chinese summary.

4 - Output a sheet object that contains the following keys: chinese_summary, num_names.

Use the following format:

Text: <text to summarize>

Summary: <summary translation>

Translation: <summary translation>

Name: <list of names in Chinese summary>

Output JOSN: <josn with summary and num_names>

Text:

< In a charming village, siblings Jack and Jill set out on a quest to fetch water from a hilltop well. As they climbed, singing joyfully, misfortune struck-Jack tripped on a stone and tumbled down the hill, with Jill following suit. Through slightly battered, the pair returned home to comforting embraces. Despite the mishap, their adventurous spirits remained undimmed, and they continued exploring with delight. >

 总结一下:首先读取文本 ——> 用英文总结文本内容 ——> 翻译总结句子 ——> 提取名字 ——> 输出JOSN格式。把任务层层分解,一步一步解决,最后汇总。

(b)第二个策略:指示模型不要急于得出结论,先尝试找出解决方案。模型给出结论以后,告诉TA正确与否。所谓的人在回路?看看她的例子:

咒语:Determine if the students solution is correct or not.

Question:

Im building a solar power installation and I need help working out the financials.

- Land costs $100 / square foot

- I can buy solar panels for $250 / square foot

- I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot

What is the total cost for the first year of operations as a function of the number of square feet.

Students Solution:

Let x be the size of the installation in square feet.

Costs:

  1. Land cost: 100x
  2. Solar panel cost: 250x
  3. Maintenance cost: 100,000 + 100x

Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

 然而,模型给出的结论是学生是正确的。确实,学生的解题思路没问题,只是粗心看错了一个数字。咋一看,确实以为是正确的。

 所以,需要修改策略:让模型自己就这个问题想出方案,然后再和学生的方案作对比,这样就能准确地判断学生的方案是否正确。

咒语:Determine if the students solution is correct or not.

To solve the problem do the following:

- First, work out your own solution to the problem.

- Then compare your solution to the students solution and evaluate if the students solution is correct or not. Dontt decide if the students solution is correct until you have done the problem yourself.

Use the following format:

Question:

‘’’

question here

‘’’

Students solution:

‘’’

Students solution here

‘’’

Actual solution:

‘’’

steps to work out the solution and your solution here

‘’’

is the students solution the same as actual solution just calculated:

‘’’

yes or no

‘’’

student grade:

‘’’

correct or incorrect

‘’’

Question:

Im building a solar power installation and I need help working out the financials.

- Land costs $100 / square foot

- I can buy solar panels for $250 / square foot

- I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot

What is the total cost for the first year of operations as a function of the number of square feet.

Students Solution:

Let x be the size of the installation in square feet.

Costs:

  1. Land cost: 100x
  2. Solar panel cost: 250x
  3. Maintenance cost: 100,000 + 100x

Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

 有没有一种感觉,TA的思维模式,有点像人类,甚至犯的错误都很像。

总结:模型也是急性子,拍脑袋给出的答案正确率不高。解决办法:给TA思考的时间,还有引导TA先自己想办法,比对后再下结论。总之就是,三思而后行!

三、模型的局限

我们都见识过了,叫一本正经地胡说八道:

大佬说:尽管语言模型在训练过程中已经接触了大量的知识,在其训练过程中,它并没有完美地记住它所看到的信息。因此,它对自己的知识边界并不十分了解,这意味着它可能会尝试回答一些晦涩难懂的问题,并且可以编造一些听起来很有道理但实际上并不真实的事情。我们把这些编造的想法称为幻觉(Hallucination)。

大佬给的建议:有一个额外的策略来减少幻觉,如果你想让模型基于文本生成答案,你需要先要求模型从文本中找到任何相关的引用,然后要求它使用这些引用来回答问题。

嗯,她没给案例!!!

四、写在最后

  1. 信息量十足。直接听官方的课程,少走弯路。
  2. 后面6节课,有缘再见。因为我看了一遍,没啥惊艳的,可能是我水平不够。待我有所感悟,在加更一期。

猜你喜欢

转载自blog.csdn.net/qq_30452897/article/details/130468345
今日推荐