什麼是提示詞? - Amazon Bedrock

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

什麼是提示詞?

提示是您身為使用者所提供的一組特定輸入,可引導 LLMs Amazon Bedrock 為指定任務或指示產生適當的回應或輸出。

User Prompt: Who invented the airplane?

當被此提示查詢時,Titan 提供輸出:

Output: The Wright brothers, Orville and Wilbur Wright are widely credited with inventing and manufacturing the world's first successful airplane.

(提示來源: AWS,使用的模型:Amazon Titan 文字)

提示詞的元件

單一提示包含數個元件,例如您想要 LLMs 執行的任務或指示、任務內容 (例如相關網域的描述)、示範範例,以及您希望 Amazon Bedrock LLMs在其回應中使用的輸入文字。根據您的使用案例、資料的可用性以及任務,您的提示應該結合一或多個這些元件。

考慮此提示範例 Titan 摘要檢閱:

User Prompt: The following is text from a restaurant review: “I finally got to check out Alessandro’s Brilliant Pizza and it is now one of my favorite restaurants in Seattle. The dining room has a beautiful view over the Puget Sound but it was surprisingly not crowded. I ordered the fried castelvetrano olives, a spicy Neapolitan-style pizza and a gnocchi dish. The olives were absolutely decadent, and the pizza came with a smoked mozzarella, which was delicious. The gnocchi was fresh and wonderful. The waitstaff were attentive, and overall the experience was lovely. I hope to return soon." Summarize the above restaurant review in one sentence.

(提示來源: AWS)

根據此提示,Titan 會以簡潔的單行餐廳評論摘要來回應。評論中提到關鍵事實,並依所需傳達要點。

Output: Alessandro's Brilliant Pizza is a fantastic restaurant in Seattle with a beautiful view over Puget Sound, decadent and delicious food, and excellent service.

(使用的模型:Amazon Titan 文字)

指令 Summarize the above restaurant review in one sentence 和評論文字 I finally got to check out ... 都是這種類型的輸出所必需的。兩者缺一不可,否則模型將沒有足夠的資訊來產生明智的總結。此指示會告訴 LLM 該怎麼做,而文字是 LLM操作所在的輸入內容 (The following is text from a restaurant review) 提供了額外的資訊和關鍵字,這些資訊和關鍵字指導模型在制定其輸出時使用輸入。

在下面的範例中,文字Context: Climate change threatens people with increased flooding ...是 LLM可用來執行回答問題任務輸入Question: What organization calls climate change the greatest threat to global health in the 21st century?”

User prompt: Context: Climate change threatens people with increased flooding, extreme heat, increased food and water scarcity, more disease, and economic loss. Human migration and conflict can also be a result. The World Health Organization (WHO) calls climate change the greatest threat to global health in the 21st century. Adapting to climate change through efforts like flood control measures or drought-resistant crops partially reduces climate change risks, although some limits to adaptation have already been reached. Poorer communities are responsible for a small share of global emissions, yet have the least ability to adapt and are most vulnerable to climate change. The expense, time required, and limits of adaptation mean its success hinge on limiting global warming. Question: What organization calls climate change the greatest threat to global health in the 21st century?

(提示詞來源:https://en.wikipedia.org/wiki/Climate_change)

AI21 Labs 根據提示中提供的內容,使用正確組織名稱的 Jurasic 回應。

Output: The World Health Organization (WHO) calls climate change the greatest threat to global health in the 21st century.

(使用的模型:AI21 Labs Jurassic-2 Ultra v1)

少量樣本提示與零樣本提示

有時,提供一些範例有助於LLMs更好地校準其輸出以符合您的期望,也稱為少量擷取畫面提示內容內學習 ,其中擷取畫面對應於配對的範例輸入和所需的輸出。為了說明這一點,首先是零樣本情緒分類提示的範例,其中提示文字中沒有提供輸入-輸出配對的範例:

User prompt: Tell me the sentiment of the following headline and categorize it as either positive, negative or neutral: New airline between Seattle and San Francisco offers a great opportunity for both passengers and investors.

(提示來源: AWS)

Output: Positive

(使用的模型:Amazon Titan 文字)

以下是情緒分類提示的少量樣本版本:

User prompt: Tell me the sentiment of the following headline and categorize it as either positive, negative or neutral. Here are some examples: Research firm fends off allegations of impropriety over new technology. Answer: Negative Offshore windfarms continue to thrive as vocal minority in opposition dwindles. Answer: Positive Manufacturing plant is the latest target in investigation by state officials. Answer:

(提示來源: AWS)

Output: Negative

(使用的模型:Amazon Titan 文字)

下列範例使用 Anthropic Claude 模型。使用 時 Anthropic Claude 模型時,最好使用 <example></example> 標籤來包含示範範例。我們也建議在範例中使用不同的分隔符號 (例如 H:A:),以避免與分隔符號 Human: 和整個提示 Assistant: 混淆。請注意,對於最後幾個拍攝範例,最後的 A: 會離開,以支持 Assistant:,提示 Anthropic Claude 以產生答案。

User prompt: Human: Please classify the given email as "Personal" or "Commercial" related emails. Here are some examples. <example> H: Hi Tom, it's been long time since we met last time. We plan to have a party at my house this weekend. Will you be able to come over? A: Personal </example> <example> H: Hi Tom, we have a special offer for you. For a limited time, our customers can save up to 35% of their total expense when you make reservations within two days. Book now and save money! A: Commercial </example> H: Hi Tom, Have you heard that we have launched all-new set of products. Order now, you will save $100 for the new products. Please check our website. Assistant: Output: Commercial

(提示來源: AWS,使用的模型:Anthropic Claude)

提示詞範本

提示詞範本會指定提示詞的格式,其中包含可交換的內容。提示範本是LLMs用於分類、摘要、問題回答等不同使用案例的「配方」。提示詞範本可能包含指示、少量樣本範例,以及適用於特定使用案例的特定內容和問題。下列範例是一個範本,您可以使用 Amazon Bedrock 文字模型來執行少量樣本情緒分類:

Prompt template: """Tell me the sentiment of the following {{Text Type, e.g., “restaurant review”}} and categorize it as either {{Sentiment A}} or {{Sentiment B}}. Here are some examples: Text: {{Example Input 1}} Answer: {{Sentiment A}} Text: {{Example Input 2}} Answer: {{Sentiment B}} Text: {{Input}} Answer:"""

使用者可以複製並貼上此範本,填入自己的文字和少量擷取範例,以在 Amazon Bedrock LLMs上使用 時完成提示。本節提供更多範本。

注意

雙大括號 {{ and }} 會標示要放入範本中資料特定資訊的位置,且不應包含在提示文字中。

維持對 Amazon Bedrock 推論請求的召回

如果您使用API呼叫存取 Amazon Bedrock 模型,請注意,除非目前的提示中包含先前的互動,否則模型不會回收先前的提示和先前的請求。在請求中包含先前的提示可讓您進行對話式互動或提出後續請求。

如果您正在存取 Anthropic Claude 使用API呼叫而非 Amazon Bedrock 文字遊樂場的模型,您可以將提示以對話方式包裝,以取得所需的回應 (適用於 Titan 文字和 AI21 Labs 侏羅紀模型系列,不需要)。下列範例會示範對話式提示詞:

User prompt: Human: Describe where sea otters live in two sentences. Assistant: Output: Here is a two sentence description of where sea otters live: Sea otters live in the northern Pacific Ocean along the coasts of Russia, Alaska, Canada, and the continental United States. They prefer coastal habitats like rocky shores, kelp forests, and estuaries where they have access to shallow, nearshore waters.

(提示來源: AWS,使用的模型:Anthropic Claude)

請注意提示詞的主要內容是如何像這樣包裝的:\n\nHuman: {{Main Content}}\n\nAssistant:。用於 Anthropic Claude 模型,透過 傳送的提示API必須包含 \n\nHuman: 和 \n\nAssistant:

在 上使用對話模式 Titan,您可以在提示模型User: {{}} \n Bot: 時使用 的格式。