什么是提示? - Amazon Bedrock

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

什么是提示?

提示是您(用户)提供的一组特定输入,可指导 Amazon Bedrock 上的 LLM 为给定任务或指令生成适当的响应或输出。

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 Text)

提示的组成部分

一条提示包括多个组成部分,例如,您希望 LLM 执行的任务或指令、任务的上下文(例如,相关域的描述)、演示示例以及您希望 Amazon Bedrock 上的 LLM 在响应中使用的输入文本。根据您的使用案例、数据的可用性和任务,您的提示应包含这些组成部分中的一个或多个。

考虑一下这个要求总结评论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 Text)

指令 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根据提示中提供的上下文,《侏罗纪》使用正确的组织名称进行回应。

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

(使用的型号:AI21 LabsJurassic-2 Ultrav1)

少样本与零样本提示

有时候,比较有用的做法是举几个例子来帮助 LLM 更好地校准输出以满足您的期望,这也称为少样本提示上下文内学习,其中样本与成对出现的示例输入和所需输出相对应。为了说明起见,在这里首先来看一个零样本情绪分类提示的示例,其中提示文本中没有提供示例输入-输出对:

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 Text)

以下是少样本版的情绪分类提示:

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 Text)

以下示例使用AnthropicClaude模型。使用AnthropicClaude模型时,最好使用<example></example>标签来包含演示示例。我们还建议在示例中使用不同的分隔符(例如 H:A:)以避免与整个提示的分隔符(Human:Assistant:)混淆。请注意,在最后的几个镜头示例中,最后一个A:被省略了Assistant:,而是提示生成AnthropicClaude答案。

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,使用的型号:AnthropicClaude)

提示模板

提示模板指定含可交换内容的提示的格式。提示模板是将 LLM 用于不同使用案例(例如分类、总结、问答等)的“秘诀”。提示模板可能包括指令、少样本示例,以及适合给定使用案例的特定上下文和问题。以下示例是一个模板,您可以借助该模板使用 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 上的 LLM 时,用户可以复制粘贴此模板,并填写自己的文本和少样本示例来完成提示。本节还提供了其他模板。

注意

双大括号 {{ and }} 标记模板中用于输入数据特定信息的位置,不应包含在提示文本中。

关于通过 API 调用使用 Amazon Bedrock 的重要注意事项

如果您要通过 API 调用访问 Amazon Bedrock 上的 LLM,请注意,除非当前提示中包含之前的交互,否则它们不会重新调用之前的提示和之前的请求。对于对话式交互或后续请求,可能需要这样做。

如果您使用 API 调用而不是 Amazon Bedrock 文本游乐场访问AnthropicClaude模型,则可以将提示封装成对话样式以获得所需的响应(对于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,使用的型号:AnthropicClaude)

请注意,提示主要内容的封装方式如下:\n\nHuman: {{Main Content}}\n\nAssistant:。对于AnthropicClaude模型,通过 API 发送的提示必须包含\ n\ n Human: 和。 \n\nAssistant:

要开启对话模式Titan,可以在提示模型User: {{}} \n Bot: 时使用格式。