这一讲——Iterative Prompt Development(迭代地获取提示词),是由吴恩达老师来主讲,他用之前开发机器学习应用的角度类比了提示词迭代开发的过程,具体如下如所示:
具体来讲,就是想法 -> 实现 -> 结果 -> 分析的一个循环过程。
而提示词的开发也是一个类似逐步优化的过程,即 提示词 -> LLM(大语言模型)给出结果 -> 结果分析 -> 提示词再优化。根据模型的输出反馈,对提示词进行逐步完善,有点RLHF的意思了。
这一讲中,吴恩达老师特别地diss了下类似30个完美的prompt这类标题的文章,理由很简单,对于一类具体的问题,可能真的需要针对性的优化提示词,才能更好的解决问题。
视频中diss的原话如下:
This is why I personally have not paid as much attention to the internet articles that say 30 perfect prompts, because I think there probably isn't a perfect prompt for everything
并且吴恩达老师还在视频的最后又强调了下这个观点——提示词工程师的重点不是找到一个完美的提示词,而是形成一个完善的为自己应用寻找最合适提示词的过程。
I think the key to being an effective prompt engineer isn't so much about knowing the perfect prompt, it's about having a good process to develop prompts that are effective for your application.
具体到提示词的迭代过程,其实也是一个逐步迭代的试错过程,视频中介绍的步骤如下:
这个过程是任务相关的,也就是说你必须事先知道自己需要什么样的结果,比如说结果中必须包含什么,必须不能有什么,具体的格式是什么等等。
这里展示的例子是从一个商品的技术规格报告生成一份零售网站的商品描述,提示词的具体变化如下:
- 初始提示词——仅描述了任务
prompt = f"""
Your task is to help a marketing team create a
description for a retail website of a product based
on a technical fact sheet.
Write a product description based on the information
provided in the technical specifications delimited by
triple backticks.
Technical specifications: ```{fact_sheet_chair}```
"""
- 优化提示词1——限制生成的长度
prompt = f"""
...... # 略去了与原始提示词相同的任务描述
Use at most 50 words.
Technical specifications: ```{fact_sheet_chair}```
"""
这里需要注意,LLM在长度限制的响应上,不是那么精准,这一点在后面的summarizing一讲中也有说明。
- 优化提示词2——增加具体细节描述(商品材质+技术标准)
prompt = f"""
...... # 略去了与原始提示词相同的任务描述
The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.
At the end of the description, include every 7-character
Product ID in the technical specification.
Use at most 50 words.
Technical specifications: ```{fact_sheet_chair}```
"""
- 优化提示词3——输出特定格式(HTML)文本
prompt = f"""
...... # 略去了与原始提示词相同的任务描述
The description is intended for furniture retailers,
so should be technical in nature and focus on the
materials the product is constructed from.
At the end of the description, include every 7-character
Product ID in the technical specification.
After the description, include a table that gives the
product's dimensions. The table should have two columns.
In the first column include the name of the dimension.
In the second column include the measurements in inches only.
Give the table the title 'Product Dimensions'.
Format everything as HTML that can be used in a website.
Place the description in a <div> element.
Technical specifications: ```{fact_sheet_chair}```
"""
至此,就完成了提示词的迭代。
这一讲,通过一个提示词优化的例子,描述了提示词优化的过程,但在实际应用开发中,我们需要通过更多的例子来测试、迭代提示词,以获得更好的结果。
所以,吴恩达老师推荐的一个提示词开发的过程如下:
- try something
- analyze where the result does not give what you want
- clarify instructions, give more time to think
- refine prompts with a batch of examples
关注算法工程笔记公众号,回复提示词,获取课程对应的课件和jupyter notebook文件(仅限个人学习使用,请勿用于商业用途)。