赞
踩
提示工程是一门相对较新的学科,用于开发和优化提示,以便为各种应用程序和研究主题有效地使用语言模型(lm)。快速的工程技能有助于更好地理解大型语言模型(llm)的功能和局限性。研究人员使用即时工程来提高llm在广泛的常见和复杂任务上的能力,如问题回答和算术推理。开发人员使用提示工程设计与llm和其他工具接口的健壮而有效的提示技术。
文章来源:xGuides, papers, lecture, and resources for prompt engineering (github.com)
提示工程是一门相对较新的学科,用于开发和优化提示,以便为各种应用程序和研究主题有效地使用语言模型(lm)。
Prompt engineering is a relatively new discipline for developing and optimizing prompts to efficiently use language models (LMs) for a wide variety of applications and research topics.
快速的工程技能有助于更好地理解大型语言模型(llm)的功能和局限性。
Prompt engineering skills help to better understand the capabilities and limitations of large language models (LLMs).
研究人员使用即时工程来提高llm在广泛的常见和复杂任务上的能力,如问题回答和算术推理。
Researchers use prompt engineering to improve the capacity of LLMs on a wide range of common and complex tasks such as question answering and arithmetic reasoning.
开发人员使用提示工程设计与llm和其他工具接口的健壮而有效的提示技术。
Developers use prompt engineering to design robust and effective prompting techniques that interface with LLMs and other tools.
本指南涵盖了标准提示的基础知识,提供了如何使用提示进行交互和指导大型语言模型(llm)的粗略概念。
This guide covers the basics of standard prompts to provide a rough idea on how to use prompts to interact and instruct large language models (LLMs).
除非另有说明,所有示例都使用’ text-davinci-003 '(使用OpenAI的playground)进行测试。
All examples are tested with text-davinci-003
(using OpenAI’s playground) unless otherwise specified.
它使用默认配置,例如’ temperature=0.7 ‘和’ top-p=1 '。
It uses the default configurations, e.g., temperature=0.7
and top-p=1
.
主题:
Topic:
-[基本提示](# Basic - Prompts)
[关于LLM设置的一个单词](# A - Word -on- LLM - Settings)
-[标准提示](# Standard - Prompts)
[提示元素](# Elements -of-a- Prompt)
-[设计提示的一般提示](# General - Tips -for- Designing - Prompts)
您已经可以通过提示实现很多功能,但结果的质量取决于您提供了多少信息。
You can already achieve a lot with prompts, but the quality of results depends on how much information you provide it.
提示符可以包含您传递给模型的“指令”或“问题”等信息,还包括其他细节,如“输入”或“示例”。
A prompt can contain information like the instruction
or question
you are passing to the model and including other details such as inputs
or examples
.
下面是一个简单提示符的基本示例:
Here is a basic example of a simple prompt:
提示
Prompt
’ ’ ’
天空是
The sky is
' ' '
输出:
Output:
’ ’ ’
蓝色的
blue
晴朗的日子天空是蓝色的。
The sky is blue on a clear day.
在阴天,天空可能是灰色或白色的。
On a cloudy day, the sky may be gray or white.
' ' '
正如您所看到的,语言模型输出了一个字符串的延续,这些字符串对于上下文“the sky is”是有意义的。
As you can see, the language model outputs a continuation of strings that make sense give the context "The sky is"
.
输出可能是意想不到的,或者与我们想要完成的任务相去甚远。
The output might be unexpected or far from the task we want to accomplish.
这个基本示例还强调了为我们想要实现的具体目标提供更多上下文或说明的必要性。
This basic example also highlights the necessity to provide more context or instructions on what specifically we want to achieve.
让我们试着改进一下:
Let’s try to improve it a bit:
提示:
Prompt:
’ ’ ’
完成句子:
Complete the sentence:
天空是
The sky is
' ' '
输出:
Output:
’ ’ ’
今天真漂亮。
so beautiful today.
' ' '
好点了吗?
Is that better?
好吧,我们告诉模型完成句子,所以结果看起来更好,因为它完全遵循了我们告诉它做的事情(“完成句子”)。
Well, we told the model to complete the sentence so the result looks a lot better as it follows exactly what we told it to do (“complete the sentence”).
这种设计最佳提示来指导模型执行任务的方法被称为**提示工程。
This approach of designing optimal prompts to instruct the model to perform a task is what’s referred to as prompt engineering.
上面的例子基本说明了llm在当今的应用前景。
The example above is a basic illustration of what’s possible with LLMs today.
今天的llm能够执行各种高级任务,从文本摘要到数学推理再到代码生成。
Today’s LLMs are able to perform all kinds of advanced tasks that range from text summarization to mathematical reasoning to code generation.
关于LLM设置的一个词
当使用提示时,您将通过API或直接与LLM交互。
When working with prompts, you will be interacting with the LLM via an API or directly.
您可以配置一些参数以获得不同的提示结果。
You can configure a few parameters to get different results for your prompts.
温度——简而言之,温度越低,结果就越确定,因为总是选择下一个可能最高的令牌。
Temperature - In short, the lower the temperature the more deterministic the results in the sense that the highest probable next token is always picked.
温度升高可能导致更多的随机性,鼓励更多样化或创造性的产出。
Increasing temperature could lead to more randomness encouraging more diverse or creative outputs.
我们实际上是在增加其他可能令牌的权值。
We are essentially increasing the weights of the other possible tokens.
在应用方面,我们可能希望在基于事实的QA中使用较低的温度,以鼓励更真实和简洁的回答。
In terms of application, we might want to use lower temperature for something like fact-based QA to encourage more factual and concise responses.
对于诗歌创作或其他创造性任务,提高温度可能是有益的。
For poem generation or other creative tasks it might be beneficial to increase temperature.
Top_p -类似地,使用Top_p,一种称为核采样的温度采样技术,您可以控制模型在生成响应时的确定性。
Top_p - Similarly, with top_p, a sampling technique with temperature called nucleus sampling, you can control how deterministic the model is at generating a response.
如果你想要的是准确而真实的答案,就把这个值保持低。
If you are looking for exact and factual answers keep this low.
如果您正在寻找更多样化的响应,则增加到更高的值。
If you are looking for more diverse responses, increase to a higher value.
一般的建议是只改变一个,而不是两个。
The general recommendation is to alter one not both.
在开始一些基本的示例之前,请记住,根据您使用的LLM版本的不同,结果可能会有所不同。
Before starting with some basic examples, keep in mind that your results may vary depending on the version of LLM you are using.
上面我们尝试了一个非常简单的提示符。
We have tried a very simple prompt above.
标准的提示符格式如下:
A standard prompt has the following format:
’ ’ ’
< >的问题吗?
<Question>?
' ' '
这可以格式化为QA格式,这是许多QA数据集的标准格式,如下所示:
This can be formatted into a QA format, which is standard in a lot of QA dataset, as follows:
’ ’ ’
问:< >的问题吗?
Q: <Question>?
答:
A:
' ' '
鉴于上面的标准格式,一种流行而有效的提示技术被称为少镜头提示,其中我们提供了示例。
Given the standard format above, one popular and effective technique to prompting is referred to as few-shot prompting where we provide exemplars.
少镜头提示可以格式化如下:
Few-shot prompts can be formatted as follows:
’ ’ ’
< >的问题吗? <Question>? <回答> <Answer> < >的问题吗? <Question>? <回答> <Answer> < >的问题吗? <Question>? <回答> <Answer> < >的问题吗? <Question>? ' ' '
你已经可以猜到它的QA格式版本是这样的:
And you can already guess that its QA format version would look like this:
’ ’ ’
问:< >的问题吗? Q: <Question>? 回答:< > A: <Answer> 问:< >的问题吗? Q: <Question>? 回答:< > A: <Answer> 问:< >的问题吗? Q: <Question>? 回答:< > A: <Answer> 问:< >的问题吗? Q: <Question>? 答: A: ' ' '
请记住,不需要使用QA格式。
Keep in mind that it’s not required to use QA format.
格式取决于手头的任务。
The format depends on the task at hand.
例如,您可以执行一个简单的分类任务,并给出如下示例来演示该任务:
For instance, you can perform a simple classification task and give exemplars that demonstrate the task as follows:
提示:
Prompt:
’ ’ ’
这太棒了! This is awesome! / /积极的 // Positive 这太糟糕了! This is bad! / / - // Negative 哇,那部电影太棒了! Wow that movie was rad! / /积极的 // Positive 多么可怕的演出! What a horrible show!
输出:
Output:
’ ’ ’
负
Negative
' ' '
少镜头提示实现了上下文内学习,这是语言模型学习仅给出几个示例的任务的能力。
Few-shot prompts enable in-context learning which is the ability of language models to learn tasks given only a few examples.
我们将在即将发布的指南中看到更多的实践。
We will see more of this in action in the upcoming guides.
随着我们介绍越来越多的示例和应用程序,可以使用提示工程,您将注意到组成提示的某些元素。
As we cover more and more examples and applications that are possible with prompt engineering, you will notice that there are certain elements that make up a prompt.
提示符可以包含以下任何组件:
A prompt can contain any of the following components:
指令 -您希望模型执行的特定任务或指令
Instruction - a specific task or instruction you want the model to perform
上下文 -可以涉及外部信息或额外的上下文,可以引导模型做出更好的响应
Context - can involve external information or additional context that can steer the model to better responses
输入数据 -是我们想要找到响应的输入或问题
Input Data - is the input or question that we are interested to find a response for
输出指示灯 -表示输出的类型或格式。
Output Indicator - indicates the type or format of output.
提示符并不需要所有的组件,格式取决于手头的任务。
Not all the components are required for a prompt and the format depends on the task at hand.
我们将在接下来的指南中介绍更多具体的例子。
We will touch on more concrete examples in upcoming guides.
设计提示符的一般技巧
这里有一些建议,当你在设计你的提示时要记住:
Here are some tips to keep in mind while you are designing your prompts:
从简单开始
当您开始设计提示时,您应该记住,这实际上是一个迭代过程,需要进行大量实验才能获得最佳结果。
As you get started with designing prompts, you should keep in mind that it is really an iterative process that requires lot of experimentation to get optimal results.
使用像OpenAI或coherence这样的简单游乐场是一个很好的起点。
Using a simple playground like OpenAI’s or Cohere’s is a good starting point.
你可以从简单的提示开始,随着你的目标达到更好的效果,不断添加更多的元素和上下文。
You can start with simple prompts and keep adding more elements and context as you aim for better results.
因此,对提示进行版本控制非常重要。
Versioning your prompt along the way is vital for this reason.
当我们阅读指南时,你会看到许多例子,具体,简单和简洁往往会给你更好的结果。
As we read the guide you will see many examples where specificity, simplicity, and conciseness will often give you better results.
当你有一项包含许多不同子任务的大任务时,你可以试着把它分解成更简单的子任务,并随着你得到更好的结果而不断增加。
When you have big task that involves many different subtasks, you can try to break down the task into simpler subtasks and keep building up as you get better results.
这避免了在一开始就给提示设计过程增加太多的复杂性。
This avoids adding too much complexity to the prompt design process at the beginning.
您可以为各种简单的任务设计有效的提示,使用命令来指导模型实现您想要实现的任务,如“写”、“分类”、“总结”、“翻译”、“订购”等。
You can design effective prompts for various simple tasks by using commands to instruct the model what you want to achieve such as “Write”, “Classify”, “Summarize”, “Translate”, “Order”, etc.
记住,你也需要做很多实验,看看哪种效果最好。
Keep in mind that you also need to experiment a lot so see what works best.
使用不同的关键字、上下文和数据尝试不同的说明,看看哪种最适合您的特定用例和任务。
Trying different instructions with different keywords, context, and data and see what works best for your particular use case and task.
通常,上下文与您试图执行的任务越具体、越相关,效果就越好。
Usually, the more specific and relevant the context is to the task you are trying to perform, the better.
在即将发布的指南中,我们将谈到抽样和添加更多上下文的重要性。
We will touch on the importance of sampling and adding more context in the upcoming guides.
其他人建议将说明放在提示符的开头。
Others recommend that instructions are placed at the beginning of the prompt.
还建议使用一些清晰的分隔符,如“###”来分隔指令和上下文。
It’s also recommended that some clear separator like “###” is used to separate the instruction and context.
例如:
For instance:
提示:
Prompt:
’ ’ ’
###指令
### Instruction ###
将以下文字翻译成西班牙语:
Translate the text below to Spanish:
文本:“你好!”
Text: "hello!"
' ' '
输出:
Output:
’ ’ ’
¡你好!
¡Hola!
' ' '
要非常具体地说明您希望模型执行的指令和任务。
Be very specific about the instruction and task you want the model to perform.
提示符的描述性和细节性越强,结果就越好。
The more descriptive and detailed the prompt is, the better the results.
当你有一个想要的结果或你正在寻找的生成风格时,这一点尤其重要。
This is particularly important when you have a desired outcome or style of generation you are seeking.
没有特定的令牌或关键字可以带来更好的结果。
There aren’t specific tokens or keywords that lead to better results.
更重要的是要有一个好的格式和描述性的提示。
It’s more important to have a good format and descriptive prompt.
事实上,在提示符中提供示例对于以特定格式获得所需的输出非常有效。
In fact, providing examples in the prompt is very effective to get desired output in specific formats.
在设计提示符时,你还应该记住提示符的长度,因为它的长度是有限制的。
When designing prompts you should also keep in mind the length of the prompt as there are limitations regarding how long this can be.
考虑你的简历应该有多具体和详细是需要考虑的。
Thinking about how specific and detailed you should be is something to consider.
太多不必要的细节不一定是一个好方法。
Too many unnecessary details is not necessarily a good approach.
细节应该是相关的,并有助于手头的任务。
The details should be relevant and contribute to the task at hand.
这是你需要经常尝试的东西。
This is something you will need to experiment with a lot.
我们鼓励进行大量的试验和迭代,以优化应用程序的提示。
We encourage a lot of experimentation and iteration to optimize prompts for your applications.
例如,让我们尝试一个简单的提示符来从一段文本中提取特定的信息。
As an example, let’s try a simple prompt to extract specific information from a piece of text.
提示:
Prompt:
’ ’ ’
提取以下文本中的地名。 Extract the name of places in the following text. 需要的格式: Desired format: : < comma_separated_list_of_company_names > Place: <comma_separated_list_of_company_names> 输入:“尽管这些进展对研究人员来说是鼓舞人心的,但仍有许多问题有待解决。 Input: "Although these developments are encouraging to researchers, much is still a mystery. 里斯本尚帕利莫未知中心的神经免疫学家恩里克·维加-费尔南德斯(Henrique Veiga-Fernandes)说:“我们经常在大脑和我们在外围看到的影响之间有一个黑盒子。” “We often have a black box between the brain and the effect we see in the periphery,” says Henrique Veiga-Fernandes, a neuroimmunologist at the Champalimaud Centre for the Unknown in Lisbon. “如果我们想将其用于治疗,我们实际上需要了解其机制。” “If we want to use it in the therapeutic context, we actually need to understand the mechanism."" ' ' '
输出:
Output:
’ ’ ’
地点:尚帕利莫未知中心,里斯本
Place: Champalimaud Centre for the Unknown, Lisbon
' ' '
输入文本来自这篇自然文章。
Input text is obtained from this Nature article.
避免不严谨
考虑到上面关于细节和改进格式的建议,很容易陷入想要在提示上太聪明的陷阱,可能会创建不精确的描述。
Given the tips above about being detailed and improving format, it’s easy to fall into the trap of wanting to be too clever about prompts and potentially creating imprecise descriptions.
具体而直接通常会更好。
It’s often better to be specific and direct.
这里的类比与有效的沟通非常相似——越直接,越有效
The analogy here is very similar to effective communication – the more direct, the more eff
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。