经验法则和示例
这是OpenAI给出的使用他们家model api时设计prompt的一些建议
1.使用最新型号
为了获得最佳效果,我们通常建议使用最新、功能最强大的模型。较新的模型往往更容易进行提示工程。
注意:提示推理模型和提示 GPT 模型时需要考虑一些差异。更多详情请点击此处。
2. 将说明放在提示的开头,并使用 ### 或 “”” 分隔说明和上下文。
效果欠佳❌:
1 | Summarize the text below as a bullet point list of the most important points. |
更好✅:
1 | Summarize the text below as a bullet point list of the most important points. |
3. 务必具体、详细描述所需的内容、结果、长度、格式、风格等。
请具体说明背景、结果、长度、格式、风格等。
效果欠佳❌:
1 | Write a poem about OpenAI. |
更好✅:
1 | Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet} |
4. 通过示例阐明所需的输出格式
效果欠佳❌:
1 | Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes. |
展示并讲解——当模型被展示特定的格式要求时,它们的响应速度会更快。这也使得以编程方式可靠地解析多个输出变得更加容易。
更好✅:
1 | Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes |
5. 先尝试zero shot,然后尝试few shot,两种方法都不奏效,最后进行微调。
✅ zero shot
1 | Extract keywords from the below text. |
✅ few shot - 请提供几个例子
1 | Extract keywords from the corresponding texts below. |
✅微调:请在此处查看微调最佳实践。
6. 减少“空泛”和不精确的描述
效果欠佳❌:
1 | The description for this product should be fairly short, a few sentences only, and not too much more. |
更好✅:
1 | Use a 3 to 5 sentence paragraph to describe this product. |
7. 不要只说不要做什么,还要说应该做什么
效果欠佳❌:
1 | The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT. |
更好✅:
1 | The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faq |
8. 代码生成专用——使用“引导词”来引导模型朝着特定模式发展
效果欠佳❌:
1 | # Write a simple python function that |
在下面的代码示例中,添加“ import ”语句会提示模型应该开始用Python编写代码。(类似地,“SELECT”语句则提示应该开始编写SQL语句。)
更好✅:
1 | # Write a simple python function that |
9. 使用“生成任何内容”功能
开发者可以使用“生成任何内容”功能来描述任务或预期的自然语言输出,并收到定制的提示。
参数
通常情况下,我们发现**model** 和是改变模型输出最常用的参数。 **temperature**
**model**性能更高的型号通常价格更贵,延迟也可能更高。**temperature**-该指标衡量模型输出不太可能出现的词元的频率。数值越高temperature,输出结果越随机(通常也越有创意)。然而,这与“真实性”并不相同。对于大多数事实性应用场景,例如数据提取和真实问答,该temperature值为 0 时效果最佳。**max_completion_tokens**(最大长度) - 不控制输出的长度,而是对词元生成的硬性限制。理想情况下,您不会经常达到此限制,因为您的模型会在认为完成或遇到您定义的停止序列时停止。**stop**(停止序列) - 一组字符(标记),当生成这些字符时,将导致文本生成停止。