什么是提示工程
提示工程通过设计模型的文本输入,引导大语言模型(LLM),最大化其在特定任务上的性能表现。
常见的大语言模型:ChatGPT,文心一言,Bard,LLAMA
提示工程是如何起作用的
提示工程根据不同的任务需求,设计合适的提示格式,以引导指令遵循模型生成期望的输出。
由于指令遵循模型的训练方式或它们所使用的数据,有一些特定的提示格式能够非常好地与手头的任务相匹配。
接下来,我们会介绍一些可靠有效的提示格式。但是也欢迎您探索不同的格式,以适配您的特定任务。
设计提示工程的原则
1:使用最优秀的模型
作为用户我们应该使用最新最强大的模型,当前最强大的模型是GPT4。
当然,针对与不同任务类型,可以选择其他模型比如”code-davinci-002″,这个模型是为代码生成训练的。
2:使用英文(翻译回中文)
模型的训练数据中,英文占有较大比重,因此,在执行英文的提示输入时,模型会生成质量更高的文本。
特别是在与你需要大量文本生成的场景下。在使用GPT模型时候,中文的回复可能会显著缩短生成的文本长度。但是你可以在提示词中声明 “用英文回答”。
3:在提示的开头放置指令,并使用###或”””来分隔指令和上下文。
在提示的开头放置指令可以提高生成文本的质量。
例如:
Summarize the text below as a bullet point list of the most important points.
{text input here}
使用分隔符号对上下文分隔可以提升生成文本的质量。
例如:
Summarize the text below as a bullet point list of the most important points.
Text: “””
{text input here}
“””
4:给出具体,详细的提示词
给出具体,详细的提示词,以说明你想生成文本的结果样式、长度、行文风格、格式等。
例如:
效果不好的提示词:
Write a poem about OpenAI.
效果更好的提示词:
Write a short inspiring poem about OpenAI, focusing on the recent GPT4 product launch (GPT4 is a multi modal model) in the style of {预期风格}
5:通过例子,为语言模型限定期望的输出格式
效果不好的提示词:
Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes. Text: {text}
效果较好的提示词:
Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes Desired format: Company names: