The previous section showed some examples of prompts that contain an instruction, like 'Write
me a poem'. This kind of instruction may work well for certain types of tasks. However, for
other applications, another prompting technique called few-shot prompting may work better.
Few-shot prompts take advantage of the fact that large language models are incredibly good
at recognizing and replicating patterns in text data. The idea is to send the LLM a text pattern
that it learns to complete. For example, let's say you want to build an application that takes as
input a country name and outputs its capital city. Here's a text prompt designed to do just that:
In this prompt, you establish a pattern:
[country] : [capital]
. If you send this prompt to a
large language model, it will autocomplete the pattern and return something like this:
This model response may look a little strange. The model returned not only the capital of
Germany (the last country in your hand-written prompt), but also a whole list of additional
country/capital pairs. That's because the LLM is "continuing the pattern." If all you're trying to
do is build a function that tells you the capital of an input city ("Germany : Berlin"), you probably
don't really care about any of the text the model generates after "Berlin." Indeed, as application
designers, you'd probably want to truncate those extraneous examples. What's more, you'd
probably want to parameterize the input, so that Germany is not a xed string but a variable
前面的部分展示了一些包含指令的提示示例,例如“写一首诗”。这种指令可能对某些类型的任务
有效。但是,对于其他应用程序,另一种提示技术称为few-shot提示可能更有效。Few-shot提示
利用了大型语言模型在文本数据中识别和复制模式的能力。其想法是向LLM发送一个文本模式,
它学会了如何完成。例如,假设您想构建一个应用程序,该应用程序以国家名称作为输入,并输
出其首都城市。这是一个旨在实现此目的的文本提示: