什么是提示? - 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要执行的任务或指令、任务的上下文(例如,相关域的描述)、演示示例以及您希望LLMs在 Amazon Bedrock 上用于其响应的输入文本。根据您的使用案例、数据的可用性和任务,您的提示应包含这些组成部分中的一个或多个。

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

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:"""

在 LLMs Amazon Bedrock 上使用时,用户可以复制并粘贴此模板,填写自己的文本和几个示例来完成提示。本节还提供了其他模板。

注意

双大括号 {{ 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: 时使用格式。