如何向GPT-3和Codex提供清晰有效的指令。

Prompt 是怎样工作的

由于指令跟随模型的训练方式或它们所接受的数据,有特定的提示格式可以很好地配合当前任务并可靠地发挥作用。以下是我们发现可靠有效的一些提示格式,但请随意尝试不同格式,以找到最适合您任务的格式。

经验法则和示例

注意:"{text input here}“是实际文本/上下文的占位符

1. 使用最新模型

为了获得最佳结果,我们通常建议使用最新、功能最强大的模型。截至2022年11月,生成文本的最佳选项是“text-davinci-003”模型,生成代码的最佳选项是“code-davinci-002”模型。

2. 在提示的开头放置说明,并使用###或”““分隔指令和上下文

低效方式

Summarize the text below as a bullet point list of the most important points.

{text input here}

高效方式

Summarize the text below as a bullet point list of the most important points.

Text: """
{text input here}
"""

3. 请尽可能具体、描述性和详细地说明所需的上下文、结果、长度、格式、风格等。

请具体说明上下文、结果、长度、格式和风格等。

低效方式

Write a poem about OpenAI. 

高效方式

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. 通过示例来表达所需的输出格式。

低效方式

Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.

Text: {text}

展示并告诉 - 当显示特定格式要求时,模型的响应更好。这也使得可编程地可靠地解析多个输出变得更容易。

高效方式

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

Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: {text}

5. 从零开始,然后进行少量训练(例如),两者都不起作用,然后再微调。

零训练

Extract keywords from the below text.

Text: {text}

Keywords:

少量训练 - 提供几个例子

Extract keywords from the corresponding texts below.

Text 1: Stripe provides APIs that web developers can use to integrate payment processing into their websites and mobile applications.
Keywords 1: Stripe, payment processing, APIs, web developers, websites, mobile applications
##
Text 2: OpenAI has trained cutting-edge language models that are very good at understanding and generating text. Our API provides access to these models and can be used to solve virtually any task that involves processing language.
Keywords 2: OpenAI, language models, text processing, API.
##
Text 3: {text}
Keywords 3:

微调:在此处查看微调最佳实践。链接

6. 减少“fluffy”和不精确的描述。

低效方式

The description for this product should be fairly short, a few sentences only, and not too much more.

高效方式

Use a 3 to 5 sentence paragraph to describe this product.

7. 不要只说什么不能做,而是说应该做什么

低效方式

The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.

Customer: I can’t log in to my account.
Agent:

高效方式

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

Customer: I can’t log in to my account.
Agent:

8. 代码生成特定 - 使用“引导词”来引导模型朝着特定的模式发展。

低效方式

# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers

在下面的代码示例中,向模型添加“import”提示,以指示它应该开始使用Python编写。(类似地,“SELECT”是SQL语句开头的好提示。)

高效方式

# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
 
import

参数

通常,我们发现模型和温度是改变模型输出的最常用参数。

  1. 模型 - 高性能模型更昂贵且延迟更高。

  2. 温度 - 衡量模型输出较不可能标记的频率。 温度越高,输出就越随机(通常也更有创意)。 然而,这并不等同于“真实性”。 对于大多数事实使用情况,例如数据提取和真实问答,温度为0最好。

  3. max_tokens(最大长度)- 不控制输出长度,但限制令牌生成的硬截止限制。 理想情况下,您不会经常达到此限制,因为您的模型将在认为自己已完成或遇到您定义的停止序列时停止。

  4. stop(停止序列)- 一组字符(标记),生成时将导致文本生成停止。