OpenAI官方提供的Prompt技巧,給OpenAI的模型提供更清晰有效的指令。
翻譯 From : https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-the-openai-api
Rules of Thumb and Examples 經(jīng)驗(yàn)法則和示例
注意:“ {此處輸入文本} ”或 "{text input here}"是實(shí)際文本/上下文的占位符 placeholder
1. 使用最新型號(hào)的模型
最新的模型更容易被Prompt激發(fā)好的結(jié)果
2.將Instruction放在Prompt的開頭,并使用 ###或 """ 將Instruction和上下文分開
效果較差?
Summarize the text below as a bullet point list of the most important points.
{text input here}
將下面的文字總結(jié)為最重要的要點(diǎn)列表。
{在此處輸入文本}
效果更好?
Summarize the text below as a bullet point list of the most important points.
Text: """
{text input here}
"""
將下面的文字總結(jié)為最重要的要點(diǎn)列表。
文字:"""
{在此處輸入文本}
"""
3. 盡可能具體、詳細(xì)地描述所需的背景、結(jié)果、長(zhǎng)度、格式、風(fēng)格等
效果較差?
Write a poem about OpenAI.
寫一首關(guān)于 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}
以{著名詩人}的風(fēng)格寫一首關(guān)于 OpenAI 的簡(jiǎn)短勵(lì)志詩,重點(diǎn)介紹最近的 DALL-E 產(chǎn)品發(fā)布(DALL-E 是一個(gè)文本到圖像的 ML 模型)
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}
提取以下文本中提到的實(shí)體。提取以下 4 種實(shí)體類型:公司名稱、人名、特定主題和主題。
文本:{text}
展示并說明 - 當(dāng)展示特定格式要求時(shí),模型會(huì)做出更好的響應(yīng)。這也使得以編程方式可靠地解析多個(gè)輸出變得更加容易。
效果更好?
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}
提取下面文本中提到的重要實(shí)體。首先提取所有公司名稱,然后提取所有人名,然后提取符合內(nèi)容的特定主題,最后提取一般的總體主題
所需格式:
公司名稱:<comma_separated_list_of_company_names>
人名:-||-
特定主題:-||-
一般主題:-||-
文本:{text}
5. 從零樣本開始,然后是少樣本,都不起作用,然后進(jìn)行微調(diào)
Zero-Shot ?
Extract keywords from the below text.
Text: {text}
Keywords:
從以下文本中提取關(guān)鍵字。
文本:{text}
關(guān)鍵字:
Few-Shot ?
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:
從下面相應(yīng)的文本中提取關(guān)鍵詞。
文本 1:Stripe 提供 API,Web 開發(fā)人員可以使用這些 API 將支付處理集成到他們的網(wǎng)站和移動(dòng)應(yīng)用程序中。
關(guān)鍵詞 1:Stripe、支付處理、API、Web 開發(fā)人員、網(wǎng)站、移動(dòng)應(yīng)用程序
##
文本 2:OpenAI 訓(xùn)練了非常擅長(zhǎng)理解和生成文本的尖端語言模型。我們的 API 提供對(duì)這些模型的訪問,可用于解決幾乎任何涉及處理語言的任務(wù)。
關(guān)鍵詞 2:OpenAI、語言模型、文本處理、API。
##
文本 3:{text}
關(guān)鍵詞 3:
微調(diào)? 微調(diào)的最佳實(shí)踐
6. 減少“空洞”和不精確的描述
效果較差?
The description for this product should be fairly short, a few sentences only, and not too much more.
該產(chǎn)品的描述應(yīng)該比較簡(jiǎn)短,只有幾句話,不要太多。
效果更好?
Use a 3 to 5 sentence paragraph to describe this product.
使用3到5個(gè)句子的段落來描述該產(chǎn)品。
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:
以下是代理與客戶之間的對(duì)話。請(qǐng)勿詢問用戶名或密碼。請(qǐng)勿重復(fù)。
客戶:我無法登錄我的帳戶。
代理:
效果更好?
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:
以下是代理與客戶之間的對(duì)話。代理將嘗試診斷問題并提出解決方案,同時(shí)避免詢問任何與 PII 相關(guān)的問題。不要詢問 PII(例如用戶名或密碼),而是讓用戶參考幫助文章 www.samplewebsite.com/help/faq
客戶:我無法登錄我的帳戶。
代理:
8. 代碼生成專用 - 使用“引導(dǎo)詞”推動(dòng)模型向特定模式發(fā)展
效果較差?
# Write a simple python function that
# 1. Ask me for a number in mile
# 2. It converts miles to kilometers
# 編寫一個(gè)簡(jiǎn)單的 Python 函數(shù),
# 1. 詢問我一個(gè)英里數(shù)
# 2. 將英里轉(zhuǎn)換為公里
效果更好?
在下面的代碼示例中,添加“ import ”提示模型應(yīng)該開始用 Python 編寫。(類似地,“ SELECT ”是 SQL 語句開頭的一個(gè)很好的提示。)
Write a simple python function that
1. Ask me for a number in mile
2. It converts miles to kilometers
import
# 編寫一個(gè)簡(jiǎn)單的 Python 函數(shù),
# 1. 詢問我一個(gè)英里數(shù)
# 2. 將英里轉(zhuǎn)換為公里
import
參數(shù)
通常,我們發(fā)現(xiàn)model 和 temperature是改變模型輸出最常用的參數(shù)。
-
model-性能更高的型號(hào)通常更昂貴,并且可能具有更高的延遲。 -
temperature-衡量模型輸出不太可能的標(biāo)記的頻率。 越高temperature,輸出越隨機(jī)(通常越有創(chuàng)意)。 但是,這與“真實(shí)性”不同。 對(duì)于大多數(shù)事實(shí)用例(例如數(shù)據(jù)提取和真實(shí)的問答),temperature0 是最好的。 -
max_tokens(最大長(zhǎng)度) - 不控制輸出的長(zhǎng)度,而是對(duì) token 生成的硬性截止限制。理想情況下,您不會(huì)經(jīng)常達(dá)到此限制,因?yàn)槟哪P蜁?huì)在它認(rèn)為完成時(shí)或達(dá)到您定義的停止序列時(shí)停止。 -
stop(停止序列) - 一組字符(標(biāo)記),當(dāng)生成時(shí),將導(dǎo)致文本生成停止。
其他參數(shù)說明請(qǐng)參見API參考。