本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
Amazon Bedrock 上 LLMs 支援的常見任務包括文字分類、摘要,以及問題和答案 (包含和不含內容)。對於這些任務,您可以使用下列範本和範例來協助您建立 Amazon Bedrock 文字模型的提示。
文字分類
對於文字分類,提示詞中包含一個問題,以及數個可能的答案選項,且模型必須以正確的選擇回應。此外,如果您在提示詞中包含答案選項,Amazon Bedrock 上的 LLM 會輸出更準確的回應。
第一個範例是一個簡單的多重選擇分類問題。
|
|
(提示來源:San Francisco 上的 Wikipedia
情緒分析是一種分類形式,其中模型會從文字中表示的選項清單中選擇情緒。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
下列範例使用AnthropicClaude模型來分類文字。如AnthropicClaude指南
(來源:寫入者 AWS) |
|
(提示來源: AWS,使用的模型:AnthropicClaude)
問答,不含上下文
在沒有上下文的問答提示詞中,模型必須以其內部知識回答問題,而不使用任何上下文或文件。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
模型激發也可以幫助問答任務。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
|
|
(提示來源: AWS,使用的模型:AI21 LabsJurassic-2 Ultrav1)
問答,含上下文
在含有上下文的問答提示詞中,使用者會提供後面接著問題的輸入文字,且模型必須根據輸入文字中提供的資訊來回答問題。在文字之後將問題放在最後,可以幫助 Amazon Bedrock 上的 LLM 更清楚回答這個問題。模型激發也適用於此使用案例。
|
|
(提示來源:https://en.wikipedia.org/wiki/Red_panda,使用的模型:Amazon Titan Text)
提示AnthropicClaude模型時,用 XML 標籤包裝輸入文字會很有幫助。在下列範例中,輸入文字包含在 <text></text>
中。
|
|
(提示來源:Super Bowl LV 展上的 Wikipedia
摘要
對於摘要任務,提示詞是一段文字,此模型必須以較短的段落進行回應,該段落會擷取輸入要點。長度(句子或段落數)的輸出規範對於此使用案例很有幫助。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
在下列範例中, 會將給定的文字AnthropicClaude摘要為一個句子。若要在提示詞中包含輸入文字,請將文字格式化為 XML 標記: <text> {{text content}} </text>
。在提示中使用 XML 是提示AnthropicClaude模型時的常見做法。
|
|
(提示來源:Nash 平衡的 Wikipedia
產生文字
根據提示,Amazon Bedrock 上的 LLM 可以使用與描述相符的原始文字作出回應。以下是一個範例:
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
對於生成文字使用案例,指定詳細的任務需求有助於發揮良好作用。在以下範例中,我們要求模型產生附帶驚嘆號的回應。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
在以下範例中,使用者在產生文字時提示模型擔任特定人員的角色。請注意簽名如何反映模型在回應中所擔任的角色。
|
|
(提示來源: AWS,使用的模型:AI21 LabsJurassic-2 Ultrav1)
產生程式碼
此提示詞描述使用者預期產生模型之程式碼的任務或函式,以及程式設計語言。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
|
|
(提示來源: AWS,使用的模型:AnthropicClaude)
數學
輸入描述在某種程度上需要數學推理的問題,其可能是數字、邏輯、幾何或其他方式。對於此類問題,透過在指令中新增片語來要求模型漸進方式解決問題會很有幫助,例如 Let’s
think step by step
或 Think step by step to come up with the right
answer.
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
以下範例還示範要求模型逐步思考:
|
|
(提示來源: AWS,使用的模型:AI21 LabsJurassic-2 Ultrav1)
理性/邏輯思維
對於複雜的推理任務或需要邏輯思考的問題,我們可以要求模型進行邏輯推論,並解釋其答案。
|
|
(提示來源: AWS,使用的模型:Amazon Titan Text)
以下是使用 AnthropicClaude模型的另一個範例:
|
|
(提示來源:https://https://en.wikipedia.org/wiki/Barber_paradox) Anthropic Claude
實體擷取
從提供的輸入問題中擷取實體。從產生的文字擷取實體,並將其放在 XML 標籤中以供進一步處理。
|
(提示來源: AWS,使用的模型:Amazon Titan Text G1- Premier)
範例:
User: You are an expert entity extractor who extracts entities from provided input question.
You are responsible for extracting following entities: name, location
Please follow below instructions while extracting the Name, and reply in <name></name>
XML Tags:
- These entities include a specific name of a person, animal or a thing
- Please extract only specific name name entities mentioned in the input query
- DO NOT extract the general mention of name by terms of "name", "boy", "girl",
"animal name", etc.
Please follow below instructions while extracting the location, and reply
in <location></location> XML Tags:
- These entities include a specific location of a place, city, country or a town
- Please extract only specific name location entities mentioned in the input query
- DO NOT extract the general mention of location by terms of "location", "city", "country",
"town", etc.
If no name or location is found, please return the same input string as is.
Below are some examples:
input: How was Sarah's birthday party in Seattle, WA?
output: How was <name>Sarah's</name> birthday party
in <location>Seattle, WA</location>?
input: Why did Joe's father go to the city?
output: Why did <name>Joe's</name> father go to the city?
input: What is the zipcode of Manhattan, New york city?
output: What is the zipcode of <location>Manhattan,New york city<location>?
input: Who is the mayor of San Francisco?
Bot:
Chain-of-thought推理
提供如何衍生答案的step-by-step分析。事實檢查並驗證模型如何產生答案。
|
(提示來源: AWS,使用的模型:Amazon Titan Text G1- Premier)
範例:
User: If Jeff had 100 dollars, and he gave $20 to Sarah,
and bought lottery tickets with another $20. With the lottery
tickets he bought he won 35 dollars. Jeff then went to buy
his lunch and spend 40 dollars in lunch. Lastly he made a
donation to charity for $20. Stephen met with Jeff and wanted
to lend some money from him for his taxi. How much maximum money
can Jeff give to Stephen, given that he needs to save $10 for
his ride back home?. Please do not answer immediately, think
step by step and show me your thinking.
Bot: