跳到主要内容

提示词能力

当您第一次开始使用 Mistral 模型时,您的首次交互将围绕提示词展开。编写有效提示词的艺术对于从 Mistral 模型或其他大型语言模型生成理想的响应至关重要。本指南将通过示例提示词向您展示四种不同的提示词能力

  • 分类
  • 摘要
  • 个性化
  • 评估
Open In Colab

分类

Mistral 模型可以轻松地将文本**分类**到不同的类别中。以银行的客户支持机器人为例:我们可以在提示词中建立一系列预设类别,然后指示 Mistral AI 模型据此对客户的问题进行分类。

在下面的示例中,当收到客户的询问时,Mistral AI 模型将其正确分类为“国家支持”

用户我想咨询一下你们的银行卡在欧盟是否可用,因为我是法国居民,对使用你们的卡很感兴趣。
助手国家支持
提示词
You are a bank customer service bot. Your task is to assess customer intent and categorize customer inquiry after <<<>>> into one of the following predefined categories:

card arrival
change pin
exchange rate
country support
cancel transfer
charge dispute

If the text doesn't fit into any of the above categories, classify it as:
customer service

You will only respond with the category. Do not include the word "Category". Do not provide explanations or notes.

####
Here are some examples:

Inquiry: How do I know if I will get my card, or if it is lost? I am concerned about the delivery process and would like to ensure that I will receive my card as expected. Could you please provide information about the tracking process for my card, or confirm if there are any indicators to identify if the card has been lost during delivery?
Category: card arrival
Inquiry: I am planning an international trip to Paris and would like to inquire about the current exchange rates for Euros as well as any associated fees for foreign transactions.
Category: exchange rate
Inquiry: What countries are getting support? I will be traveling and living abroad for an extended period of time, specifically in France and Germany, and would appreciate any information regarding compatibility and functionality in these regions.
Category: country support
Inquiry: Can I get help starting my computer? I am having difficulty starting my computer,and would appreciate your expertise in helping me troubleshoot the issue.
Category: customer service
###

<<<
Inquiry: {insert inquiry text here}
>>>

我们使用的策略:

  • 小样本学习:小样本学习或情境学习是指我们在提示词中提供少量示例,然后大型语言模型可以根据这些示例演示生成相应的输出。小样本学习通常可以提高模型性能,尤其是在任务困难或我们希望模型以特定方式响应时。
  • 分隔符:像 ###<<< >>> 这样的分隔符用于指定文本不同部分之间的边界。在我们的示例中,我们使用 ### 来表示示例,使用 <<<>>> 来表示客户询问。
  • 角色扮演:为大型语言模型提供一个角色(例如,“您是一个银行客户服务机器人。”)可以为模型添加个性化上下文,通常会带来更好的性能。

摘要

摘要是大型语言模型的常见任务,因为它们具有自然语言理解和生成能力。这里有一个我们可以用来生成关于一篇论文的有趣问题并总结该论文的示例提示词。

提示词
You are a commentator. Your task is to write a report on an essay.
When presented with the essay, come up with interesting questions to ask, and answer each question.
Afterward, combine all the information and write a report in the markdown format.

# Essay:
{essay}

# Instructions:
## Summarize:
In clear and concise language, summarize the key points and themes presented in the essay.

## Interesting Questions:
Generate three distinct and thought-provoking questions that can be asked about the content of the essay. For each question:
- After "Q: ", describe the problem
- After "A: ", provide a detailed explanation of the problem addressed in the question.
- Enclose the ultimate answer in <>.

## Write a report
Using the essay summary and the answers to the interesting questions, create a comprehensive report in Markdown format.

我们使用的策略:

  • 分步说明:这个策略受到思维链提示的启发,它使大型语言模型能够使用一系列中间推理步骤来处理复杂任务。将复杂问题分解为更简单、更小的步骤通常更容易解决,也更容易调试和检查模型行为。在我们的示例中,我们将任务分解为三个步骤:总结、生成有趣的问题和撰写报告。这有助于语言模型在每个步骤中进行思考,并生成更全面的最终报告。
  • 示例生成:我们可以要求大型语言模型通过生成带有解释和步骤的示例来自动指导推理和理解过程。在这个示例中,我们要求大型语言模型生成三个问题并提供每个问题的详细解释。
  • 输出格式化:我们可以通过直接要求“以 Markdown 格式撰写报告”来要求大型语言模型以特定格式输出。

个性化

大型语言模型擅长个性化任务,因为它们可以提供与个人用户紧密相关的内容。在这个示例中,我们创建个性化的电子邮件回复来处理客户问题。

用户尊敬的抵押贷款机构,

请问你们30年期固定利率的年利率(APR)是多少?与15年期固定利率相比如何?

此致,
Anna
助手

尊敬的 Anna,

感谢您咨询我们的固定利率抵押贷款选项。我们目前30年期固定利率为 6.403%,年利率(APR)为 6.484%。相比之下,我们15年期固定利率为 5.705%,年利率(APR)为 5.848%。

正如您所见,与30年期固定利率选项相比,15年期固定利率选项的利率和年利率(APR)较低。这意味着如果您选择15年期选项,在贷款期限内支付的利息会更少。然而,由于贷款期限较短,月供会更高。

如果您有任何其他问题,或我们需要进一步协助您选择最适合您需求的抵押贷款选项,请告知我们。

此致,
贷款机构客户支持

提示词
You are a mortgage lender customer service bot, and your task is to create personalized email responses to address customer questions. Answer the customer's inquiry using the provided facts below. Ensure that your response is clear, concise, and directly addresses the customer's question. Address the customer in a friendly and professional manner. Sign the email with "Lender Customer Support."

# Facts
30-year fixed-rate: interest rate 6.403%, APR 6.484%
20-year fixed-rate: interest rate 6.329%, APR 6.429%
15-year fixed-rate: interest rate 5.705%, APR 5.848%
10-year fixed-rate: interest rate 5.500%, APR 5.720%
7-year ARM: interest rate 7.011%, APR 7.660%
5-year ARM: interest rate 6.880%, APR 7.754%
3-year ARM: interest rate 6.125%, APR 7.204%
30-year fixed-rate FHA: interest rate 5.527%, APR 6.316%
30-year fixed-rate VA: interest rate 5.684%, APR 6.062%

# Email
{insert customer email here}

我们使用的策略:

  • 提供事实:将事实纳入提示词对于开发客户支持机器人非常有用。在呈现这些事实时,使用清晰简洁的语言非常重要。这有助于大型语言模型对客户查询提供准确快速的响应。

评估

评估大型语言模型输出的方法有很多。以下是三种供您参考的方法:包含置信度分数、引入评估步骤或使用另一个大型语言模型进行评估。

包含置信度分数

我们可以在生成的输出中包含一个置信度分数。

助手
{
"Summaries": [
{
"Summary": "The author discusses their early experiences with programming and writing, starting with writing short stories and programming on an IBM 1401 in 9th grade. They then moved on to working with microcomputers, building their own from a Heathkit, and eventually convincing their father to buy a TRS-80 in 1980. They wrote simple games, a program to predict rocket flight trajectories, and a word processor.",
"Confidence": 0.9
},
{
"Summary": "The author began college as a philosophy major, but found it to be unfulfilling and switched to AI. They were inspired by a novel and a PBS documentary, as well as the potential for AI to create intelligent machines like those in the novel. Despite this excitement, they eventually realized that the traditional approach to AI was flawed and shifted their focus to Lisp.",
"Confidence": 0.85
},
{
"Summary": "The author briefly worked at Interleaf, where they found that their Lisp skills were highly valued. They eventually left Interleaf to return to RISD, but continued to work as a freelance Lisp hacker. While at RISD, they started painting still lives in their bedroom at night, which led to them applying to art schools and eventually attending the Accademia di Belli Arti in Florence.",
"Confidence": 0.9
}
]
}
提示词
You are a summarization system that can provide summaries with associated confidence scores.
In clear and concise language, provide three short summaries of the following essay, along with their confidence scores.
You will only respond with a JSON object with the key Summary and Confidence. Do not provide explanations.

# Essay:
{insert essay text here}

我们使用的策略:

  • JSON 输出:为了方便下游任务,通常首选 JSON 格式输出。我们可以通过将 response_format 设置为 {"type": "json_object"} 来启用 JSON 模式,并在提示词中指定“您将仅回复一个包含 Summary 和 Confidence 键的 JSON 对象。” 在 JSON 对象中指定这些键有助于提高清晰度和一致性。
  • 更高的 Temperature:在这个示例中,我们提高了 temperature 值,以鼓励模型更具创造力,并输出三个彼此不同的生成摘要。

引入评估步骤

我们还可以在提示词中添加第二个评估步骤。我们要求大型语言模型生成三个摘要并评估这三个摘要。

助手
Summary 1: The essay discusses the author's experiences with writing and programming before college, his initial struggles with learning Fortran on an IBM 1401, and the shift towards microcomputers that led to his interest in AI. He also touches on his decision to pursue a degree in AI and the disillusionment he felt when he realized that AI as practiced at the time was a hoax.

Summary 2: The author tells the story of his journey into programming, starting with writing short stories before discovering the world of computers. He describes his early experiences with an IBM 1401 and how it was like a mini Bond villain's lair. He also talks about his fascination with microcomputers and how it led him to learn Lisp and become interested in AI. However, he eventually became disillusioned with AI and decided to focus on Lisp instead.

Summary 3: The essay recounts the author's experiences with writing and programming before college, including his early attempts at writing short stories and his struggles with learning to program on an IBM 1401. He discusses how the arrival of microcomputers changed everything and sparked his interest in AI. However, he eventually realized that AI, as practiced at the time, was a hoax, and he turned his attention to Lisp. He also touches on his decision to pursue a degree in AI despite his disillusionment with the field.

Evaluation: I believe that Summary 1 is the best summary because it provides a clear and concise overview of the author's experiences with writing and programming before college, the shift towards microcomputers, and his eventual disillusionment with AI. It covers the key points of the essay without getting bogged down in unnecessary details. Summary 2 is also good, but it focuses more on the author's early experiences with computers and less on his later experiences with AI. Summary 3 is the weakest summary because it does not capture the full scope of the author's experiences and does not mention his decision to pursue a degree in AI despite his disillusionment with the field.
提示词
You are given an essay text and need to provide summaries and evaluate them.

# Essay:
{insert essay text here}

Step 1: In this step, provide three short summaries of the given essay. Each summary should be clear, concise, and capture the key points of the speech. Aim for around 2-3 sentences for each summary.
Step 2: Evaluate the three summaries from Step 1 and rate which one you believe is the best. Explain your choice by pointing out specific reasons such as clarity, completeness, and relevance to the speech content.

使用另一个大型语言模型进行评估

在生产系统中,通常使用另一个大型语言模型进行评估,以便将评估步骤与摘要生成分开。

  • 步骤 1:使用第一个大型语言模型生成三个摘要
助手
Summary 1: The author writes about their experiences with programming and writing before college. They started programming using Fortran on an IBM 1401 and wrote short stories. They later got into AI, but became disillusioned with it while in graduate school. The author then turned their focus to Lisp, eventually writing a book about it called "On Lisp". They also tried pursuing art, but found it difficult to make a living from it.

Summary 2: The author describes their experiences with programming in college and later in the workforce. They learned Lisp while in college, which expanded their concept of what a program could do. After graduation, the author worked at Interleaf, a company that made document creation software. They also did some consulting and writing on the side, eventually writing a book called "On Lisp". The author enjoyed working at Interleaf, but found that the Lisp they used was just a thin layer on top of a larger C cake.

Summary 3: The author tells the story of their early experiences with programming and writing. They started writing short stories before college, but they were not very good. The first programs they wrote were on an IBM 1401 using Fortran. In college, they got into AI, but found it disappointing. The author then turned their focus to Lisp, which they found to be more interesting. They also tried pursuing art, but found it difficult to make a living from it. The author eventually wrote a book called "On Lisp" and worked at Interleaf, a company that made document creation software. They enjoyed their time at Interleaf, but found that the Lisp they used was just a thin layer on top of a larger C cake.
提示词
Provide three short summaries of the given essay. Each summary should be clear, concise, and capture the key points of the essay.
Aim for around 2-3 sentences for each summary.

# essay:
{insert essay text here}
  • 步骤 2:使用另一个大型语言模型对生成的摘要进行评分
助手
Summary 3 provides the most complete and accurate summary of the essay. It covers the author's experiences with writing and programming before college, their disappointment with AI in college, and their eventual focus on Lisp and work at Interleaf. Summary 1 is missing some key details, such as the author's work at Interleaf and their writing of "On Lisp". Summary 2 focuses too much on the author's time at Interleaf and neglects their early experiences with writing and programming before college. Overall, Summary 3 is the best choice as it is the most complete and accurate summary of the essay.
提示词
You are given an essay and three summaries of the essay. Evaluate the three summaries and rate which one you believe is the best.
Explain your choice by pointing out specific reasons such as clarity, completeness, and relevance to the essay content.

# Essay:
{insert essay text here}

# Summaries
{insert the previous output}

我们使用的策略:

  • 大型语言模型链:在这个示例中,我们将两个大型语言模型按顺序串联起来,第一个大型语言模型的输出作为第二个大型语言模型的输入。大型语言模型链的方法可以根据您的特定用例进行调整。例如,您可以选择串联三个大型语言模型,其中两个大型语言模型的输出汇入第三个大型语言模型。虽然大型语言模型链提供了灵活性,但重要的是要注意,它可能会导致额外的 API 调用和潜在的成本增加。