以通用大模型为基础,越来越多的人要学会和AI打交道,各个企业也会基于现有大模型构建私域的模型,那么我今天介绍的这个法宝之一“Prompt提示词”,在未来就非常重要.
无论您是普通人、研究人员、开发人员,还是只是想在自己的领域中将ChatGPT作为个人助手的人,本文都是为您编写的。我使用简单易懂的语言,提供实用的解释,并在每个提示技术中提供了示例和提示公式。通过本系列文章,您将学习如何使用提示工程技术来控制ChatGPT的输出,并生成符合您特定需求的文本。
什么是 Prompt 工程?
Prompt 工程是创建提示或指导像 ChatGPT 这样的语言模型输出的过程。它允许用户控制模型的输出并生成符合其特定需求的文本。
ChatGPT 是一种先进的语言模型,能够生成类似于人类的文本。它建立在 Transformer 架构上,可以处理大量数据并生成高质量的文本。
然而,为了从 ChatGPT 中获得最佳结果,重要的是要了解如何正确地提示模型。提示可以让用户控制模型的输出并生成相关、准确和高质量的文本。在使用 ChatGPT 时,了解它的能力和限制非常重要。
该模型能够生成类似于人类的文本,但如果没有适当的指导,它可能无法始终产生期望的输出。
这就是 Prompt 工程的作用,通过提供清晰而具体的指令,您可以引导模型的输出并确保其相关。
Prompt 公式是提示的特定格式,通常由三个主要元素组成:
● 任务:对提示要求模型生成的内容进行清晰而简洁的陈述。
● 指令:在生成文本时模型应遵循的指令。
● 角色:模型在生成文本时应扮演的角色。
在本文中,我们将探讨可用于 ChatGPT 的各种 Prompt 工程技术。我们将讨论不同类型的提示,以及如何使用它们实现您想要的特定目标。因为ChatGPT,对英文有良好的支持方式,所以这里对于样例会采用中英两种文字说明.
一 标准提示
标准提示是一种简单的方法,通过为模型提供一个特定的任务来引导ChatGPT的输出。例如,如果您想生成一篇新闻文章的摘要,您可以提供一个任务,如“总结这篇新闻文章”。
提示公式:“Generate a [task] 生成一个[任务]”
例如:
Generating a summary of a news article生成新闻文章的摘要:
任务:Summarize this news article 总结这篇新闻文章
提示公式:“Generate a summary of this news article 生成这篇新闻文章的摘要”
Generating a product review生成一篇产品评论:
任务:Write a review of a new smartphone为一款新智能手机撰写评论
提示公式:“Generate a review of this new smartphone 生成这款新智能手机的评论”
此外,标准提示可以与其他技术(如角色提示和种子词提示)结合使用,以增强ChatGPT的输出。
二 指令提示
现在,让我们开始探索“指令提示技术”,以及如何使用它从ChatGPT中生成高质量的文本。
指令提示技术是通过为模型提供具体指令来引导ChatGPT的输出的一种方法。这种技术对于确保输出相关和高质量非常有用。
要使用指令提示技术,您需要为模型提供清晰简洁的任务,以及具体的指令以供模型遵循。
例如,如果您正在生成客户服务响应,您将提供任务,例如“generate responses to customer inquiries(生成响应客户查询)”的指令,例如“ Generate[task]following these instructions: [instructions] ”。
提示公式:“按照以下指示生成[任务]:[指令]”
示例:
生成客户服务响应:
任务:Generate responses to customer inquiries 生成响应客户查询
指令:The responses should be professional and provide accurate information 响应应该专业且提供准确的信息
提示公式:“Generate professional and accurate responses to customer inquiries following these instructions: The responses should be professional and provide accurate information.按照以下指示生成专业且准确的客户查询响应:响应应该专业且提供准确的信息。”
生成法律文件:
任务:Generate a legal document 生成法律文件
指令:The document should be in compliance with relevant laws and regulations 文件应符合相关法律法规
提示公式:Generate a legal document that is compliant with relevant laws and regulations following these instructions: The document should be in compliance with relevant laws and regulations.“按照以下指示生成符合相关法律法规的法律文件:文件应符合相关法律法规。”
使用指令提示技术时,重要的是要记住指令应该清晰具体。这将有助于确保输出相关和高质量。可以将指令提示技术与下一章节中解释的“角色提示”和“种子词提示”相结合,以增强ChatGPT的输出。
三 角色提示
角色提示技术是通过为ChatGPT指定一个特定的角色来引导其输出的一种方式。这种技术对于生成针对特定上下文或受众的文本非常有用。
要使用角色提示技术,您需要为模型提供一个清晰具体的角色。
例如,如果您正在生成客户服务回复,您可以提供一个角色,如“customer service representative 客户代表”。
提示公式:“Generate [task] as a [role] 作为[角色]生成[任务]”
示例:
Generating customer service responses 生成客户服务回复:
任务: Generate responses to customer inquiries生成对客户查询的回复
角色:Customer service representative 客户服务代表
提示公式:Generate responses to customer inquiries as a customer service representative. 作为客户服务代表,生成对客户查询的回复。
Generating a legal document 生成法律文件:
任务:Generate a legal document 生成法律文件
角色:Lawyer 律师
提示公式:Generate a legal document as a lawyer. 作为律师,生成法律文件.
将角色提示技术与指令提示和种子词提示结合使用可以增强ChatGPT的输出。
下面是一个示例,展示了如何将指令提示、角色提示和种子词提示技术结合使用:
任务:Generate a product description for a new smartphone Instructions: The description should be informative, persuasive and highlight the unique features of the smartphone 为新智能手机生成产品描述,描述应该是有信息量的,具有说服力,并突出智能手机的独特功能
角色:Marketing representative Seed-word: "innovative" 市场代表 种子词:“创新的”
提示公式:(Role) As a marketing representative, (Task) generate an (Instructions) informative, persuasive product description that highlights the (SeedWord)innovative features of the new smartphone. The smartphone has the following features [insert your features] 作为市场代表,生成一个有信息量的、有说服力的产品描述,突出新智能手机的创新功能。该智能手机具有以下功能[插入您的功能]
在这个示例中,指令提示用于确保产品描述具有信息量和说服力。角色提示用于确保描述是从市场代表的角度书写的。而种子词提示则用于确保描述侧重于智能手机的创新功能。
以下是如何将标准提示、角色提示和种子词提示技术结合使用的示例:
任务:Generate a product review for a new laptop Instructions: The review should be objective, informative and highlight the unique features of the laptop 为一台新笔记本电脑撰写产品评论, 指示:评论应客观、信息丰富,强调笔记本电脑的独特特点
角色:Tech expert 技术专家
种子词: “powerful 强大的”
提示公式:“As a tech expert, generate an objective and informative product review that highlights the powerful features of the new laptop. 作为一名技术专家,生成一个客观而且信息丰富的产品评论,强调新笔记本电脑的强大特点。”
在这个示例中,标准提示技术用于确保模型生成产品评论。角色提示用于确保评论是从技术专家的角度写的。而种子词提示用于确保评论侧重于笔记本电脑的强大特点。
四 “让我们思考一下”提示
“Let's think about this 让我们思考一下”提示是一种技巧,可鼓励ChatGPT生成反思和思考性的文本。这种技术适用于撰写论文、诗歌或创意写作等任务。
“Let's think about this 让我们思考一下”提示的公式非常简单,即“让我们思考一下”后跟一个主题或问题。
例如:
Generating a reflective essay 生成一篇反思性论文:
任务:Write a reflective essay on the topic of personal growth 就个人成长主题写一篇反思性论文
提示公式:Let's think about this: personal growth “让我们思考一下:个人成长”
Generating a poem 生成一首诗:
任务:Write a poem about the changing seasons 写一首关于季节变化的诗
提示公式:Let's think about this: the changing seasons “让我们思考一下:季节变化”
这个提示要求对特定主题或想法展开对话或讨论。发言者邀请ChatGPT参与讨论相关主题。
模型提供了一个提示,作为对话或文本生成的起点。
然后,模型使用其训练数据和算法生成与提示相关的响应。这种技术允许ChatGPT根据提供的提示生成上下文适当且连贯的文本。
要使用“让我们思考一下提示”技术与ChatGPT,您可以遵循以下步骤:
1. 确定您要讨论的主题或想法。
2. 制定一个明确表达主题或想法的提示,并开始对话或文本生成。
3. 用“让我们思考”或“让我们讨论”开头的提示,表明您正在启动对话或讨论。
以下是使用此技术的一些提示示例:
提示:“Let's think about the impact of climate change on agriculture 让我们思考气候变化对农业的影响”
提示:“Let's discuss the current state of artificial intelligence 让我们讨论人工智能的当前状态”
提示:“Let's talk about the benefits and drawbacks of remote work 让我们谈谈远程工作的好处和缺点” 您还可以添加开放式问题、陈述或一段您希望模型继续或扩展的文本。
提供提示后,模型将使用其训练数据和算法生成与提示相关的响应,并以连贯的方式继续对话。
这种独特的提示有助于ChatGPT以不同的视角和角度给出答案,从而产生更具动态性和信息性的段落。
使用提示的步骤简单易行,可以真正提高您的写作水平。尝试一下,看看效果如何吧。
五 自洽提示
自洽提示是一种技术,用于确保ChatGPT的输出与提供的输入一致。这种技术对于事实核查、数据验证或文本生成中的一致性检查等任务非常有用。
自洽提示的提示公式是输入文本后跟着指令“Please ensure the following text is self-consistent 请确保以下文本是自洽的”。
或者,可以提示模型生成与提供的输入一致的文本。
提示示例及其公式:
示例1:Text Generation 文本生成
任务:Generate a product review 生成产品评论
指令:The review should be consistent with the product information provided in the input 评论应与输入中提供的产品信息一致
提示公式:“Generate a product review that is consistent with the following product information [insert product information] 生 成与以下产品信息一致的产品评论[插入产品信息]”
示例2:Text Summarization 文本摘要
任务:Summarize a news article 概括一篇新闻文章
指令:The summary should be consistent with the information provided in the article 摘要应与文章中提供的信息一致
提示公式:“Summarize the following news article in a way that is consistent with the information provided [insert news article] 用与提供的信息一致的方式概括以下新闻文章[插入新闻文章]”
示例3:Text Completion 文本完成
任务:Complete a sentence 完成一个句子
指令:The completion should be consistent with the context provided in the input 完成应与输入中提供的上下文一致
提示公式:“Complete the following sentence in a way that is consistent with the context provided [insert sentence] 以与提供的上下文一致的方式完成以下句子[插入句子]”
示例4:
1. Fact-checking 事实核查:
任务:Check for consistency in a given news article 检查给定新闻文章的一致性
输入文本:“The article states that the population of the city is 5 million, but later on, it says that the population is 7 million. 文章中陈述该城市的人口为500万,但后来又说该城市的人口为700万。”
提示公式:“Please ensure the following text is self- consistent: The article states that the population of the city is 5 million, but later on, it says that the population is 7 million. 请确保以下文本是自洽的:文章中陈述该城市的人口为500万,但后来又说该城市的人口为700万。”
2. Data validation 数据验证:
任务:Check for consistency in a given data set 检查给定数据集的一致性
输入文本:“The data shows that the average temperature in July is 30 degrees, but the minimum temperature is recorded as 20 degrees. 数据显示7月份的平均温度为30度,但最低温度记录为20度。”
提示公式:“Please ensure the following text is self- consistent: The data shows that the average temperature in July is 30 degrees, but the minimum temperature is recorded as 20 degrees. 请确保以下文本是自洽的:数据显示7月份的平均温度为30度,但最低温度记录为20度。”
六 种子词提示
种子词提示是一种通过提供特定的种子词或短语来控制ChatGPT输出的技术。种子词提示的提示公式是种子词或短语,后跟指令“Please generate text based on the following seed-word 请根据以下种子词生成文本”。
示例:
文本生成:
任务:Generate a story about a dragon 编写一篇有关龙的故事
种子词:“龙”
提示公式:“Please generate text based on the following seed-word: Dragon 请根据以下种子词生成文本:龙”
种子词提示可以与角色提示和指令提示相结合,以创建更具体和有针对性的生成文本。通过提供种子词或短语,模型可以生成与该种子词或短语相关的文本,并通过提供有关期望输出和角色的信息,模型可以以特定于角色或指令的风格或语气生成文本。这样可以更好地控制生成的文本,并可用于各种应用程序。
以下是提示示例及其公式:
示例1:文本生成
任务:Generate a poem 编写一首诗
指令:The poem should be related to the seed word "love" and should be written in the style of a sonnet 诗应与种子词“爱”相关,并以十四行诗的形式书写。
角色:Poet 诗人
提示公式:“Generate a sonnet related to the seed word 'love' as a poet 以诗人的身份,生成一个与种子词‘爱’相关的十四行诗”
示例2:Text Completion 文本完成
任务:Complete a sentence 完成一句话
指令:The completion should be related to the seed word "science" and should be written in the style of a research paper 完成应与种子词“科学”相关,并以研究论文的形式书写。
角色:Researcher 研究员
提示公式:“Complete the following sentence in a way that is related to the seed word 'science' and in the style of a research paper as a researcher: [insert sentence]作为研究员,请在与种子词“科学”相关且以研究论文的形式书写的情况下完成以下句子:[插入句子]”
示例3:Text Summarization 文本摘要
任务:Summarize a news article 摘要一篇新闻文章
指令:The summary should be related to the seed word "politics" and should be written in a neutral and unbiased tone 摘要应与种子词“政治”相关,并以中立和公正的语气书写。
角色:Journalist 记者
提示公式:“Summarize the following news article in a way that is related to the seed word 'politics' in a neutral and unbiased tone as a journalist: [insert news article] 作为记者,请以中立和公正的语气摘要以下新闻文章,与种子词“政治”相关:[插入新闻文章]”