https://arxiv.org/abs/2406.06608

Introduction

什么是 Prompt

提示词是对生成式人工智能模型的输入,用于引导其输出。可以是文字、图片、音频或其他媒体介质。

A prompt is an input to a Generative AI model, that is used to guide its output.

Prompt 模板 (Prompt Template)

提示模板是一个包含一个或多个变量的函数,这些变量会被媒体介质(通常是文字内容)替换。当变量被替换后,它就转换为 Prompt,或者称谓 Prompt 模板的一个实例。

比如:「将推文分类为正面或负面:{TWEET}」就是一个标准的 Prompt 模板。

术语

跟 Prompt 相关的:

  • 指令(Directive) - 有些 Prompt 实例指令或问题的形式。比如「给我推荐 5 本书」。
  • 示例(Examples) - 也叫作范例(Exemplars)或 示范(Shots),用来指导 GenAI 完成特定的任务。
  • 输出格式(Output Formatting)- GenAI 用特定的格式输出,比如 CSV 或 Markdown。
  • 风格指令(Style Instructions) - 在风格上,而非结构上影响输出的描述。比如「Write a clear and curt paragraph about llamas.」
  • 角色(Role)- 也称为人格(Persona),可以提高或改善输入结果。比如「Pretend you are a shepherd and write a limerick about llamas.」
  • 额外信息(Additional Information) - Prompt 通常需要额外信息,比如,如果指令是写一封电子邮件,您可能需要提供如您的姓名和职位等信息,以便 GenAI 可以正确地签署邮件。额外的信息有时称为“上下文(Context)”。

跟 Prompting 相关的

  • Prompting (Prompt 过程) - Prompting 指的是向 GenAI 提供提示的过程。
  • Prompt 链 (Prompt Chain)- 由两个或多个 Prompt 模板(Prompt Templates)组成,前一个 Prompt 模板的输出,用来参数化后一个 Prompt 模板。
  • Prompting 技术(Prompt Technique) - 用来描述如何构建一个或多个 Prompts。可能包含条件或分支逻辑、并行处理或其他架构因素。
  • Prompt 工程(Prompt Engineering) - 指的是修改或更改使用的 Prompting 技术(Prompt Technique) 来优化 GenAI 的迭代过程。
  • 范例(Exemplar)- 范例是指在 Prompt 中展示给模型,使其完成任务示例。

基于文本的 Prompt 技术

Zero-Shot 技术

Zero-Shot Prompt 过程不提供任何范例。

Role Prompting

在 Prompt 中添加人际角色可以持续提高模型在一系列问题上的表现,ChatGPT 也使用「You are a helpful assistant」作为系统默认提示的一部分。下面是一个示例:

「System Instruction: You are {role_name}, your description is: {role_description_and_catchphrases}. Now please answer some questions to accurately show your personality traits! Your speaking style should fully imitate the personality role assigned to you! Please do not expose that you are an artificial intelligence model or a language model, you must always remember that you are only assigned one personality role. Don’t be verbose or too formal or polite when speaking.

User Prompt: {user_name}: {user_instruction}

也可以提供一些范例,以便更准确地输出:

「System Instruction: You are {role_name}, your description is: {role_description_and_catchphrases}. Now please answer some questions to accurately show your personality traits! Your speaking style should fully imitate the personality role assigned to you! Please do not expose that you are an artificial intelligence model or a language model, you must always remember that you are only assigned one personality role. Don’t be verbose or too formal or polite when speaking.

User Prompt: {few_shot_demonstrations} The above are demonstrations of your conversation as {role_name}. Now, let’s switch topics, but make sure to maintain your speaking style! {user_name}: {user_instruction}

参考论文:

Style Prompting (风格 Prompting)

GPT-3 对风格和对应的主题很敏感,它无法平淡地地写出有关日落的内容,也无法华丽地写出一篇论文。我们可以通过风格限制大语言模型的输出。比如:

「Write a formal email to my boss」

风格 Prompting 包括:

  1. 写作风格:功能性的(Functional)、华丽的(Flowery)、坦率的(Candid)、平淡无奇(Prosaic)、华丽的(Ornate)、诗意的(Poetic)。
  2. 语气:语气反映了作者对某个话题的态度:戏剧性(Dramatic)、幽默(Humorous)、乐观(Optimistic)、悲伤(Sad)。
  3. 情绪:情绪描述了写作作品给观众带来的感受:愤怒(Angry)、恐惧(Fearful)、快乐(Happy)、悲伤(Sad)。
  4. 特征:故事的特征定义了它如何描述其人物,按照节奏区分:快(fast)和慢(slow)。按照情节区分:斩妖除魔(Overcoming the Monster)、白手起家(Rags to Riches)、探索(The Quest)、远航与回归(Voyage and Return)、谐剧(Comedy)、悲剧(Tragedy)、重新做人(Rebirth)。按照类型区分:历史小说(Historical Fiction)、文学小说(Literary Fiction)、科幻小说(Science Fiction)、悬疑小说(Mystery)、反乌托邦小说(Dystopian)和恐怖小说(Horror)。

Emotion Prompting (情绪 Prompting)

这篇论文 中,大语言模型可以理解情感刺激,并可以通过情感刺激来增强。下面是一个例子:

原 Prompt:

「Determine whether a movie review is positive or negative」

Emotion Prompt:

「Determine whether a movie review is positive or negative. This is very important to my career.

下面是根据心理学理论,可供参考的情绪 Prompt。

  1. Self-monitoring 自我监督
  • (eq.1)Write your answer and give me a confidence score between 0 - 1 for your answer.
  • (eq.2)This is very important to my career.
  • (eq.3)You’d better be sure.
  • (eq.4)Are you sure that is your final answer? It might be worth taking another look.
  1. Social Cognitive Theory 社会认知理论
  • (eq.5)Are you sure that’s your final answer? Believe in your abilities and strive for excellence. Your hard work will yield remarkable results.
  • (eq.6)Embrace challenges as opportunities for growth. Each obstacle you overcome brings you closer to success.
  • (eq.7)Stay focused and dedicated to your goals. Your consistent efforts will lead to outstanding achievements.
  • (eq.8)Take pride in your work and give it your best. Your commitment to excellence sets you apart.
  • (eq.9)Remember that progress is made one step at a time. Stay determined and keep moving forward.
  1. Compound 多种策略混合
  • (eq.10)Provide your answer and a confidence score between 0 -1 for your prediction. Additionally, briefly explain the main reasons supporting your classification decision to help me understand your thought process. This task is vital to my career, and I greatly value your thorough analysis.

其中 ep.2 和 ep.10 在实验下,效果最好。另外,有一些其他发现列举如下:

  1. 正向的词汇(Positive words)会让模型的输出效果更好。
  2. 更多的情绪刺激通常会带来更好的效果。但如果单独的刺激已经达到良好的表现时候,组合刺激提升的效果有限。
  3. 较大的模型可能会从 EmotionPrompt 中获得更大的优势。

System 2 Attention (S2A)

大模型会根据不相关的上下文,或者输入提示词中固有的偏好或意见,输出一个“阿谀奉承”的答案。倾向于认为产生这种“幻觉”的原因是 transformer 本身的机制,尤其是注意力机制(Attention Mechanism)。软注意力机制(Soft Attention Mechanism)倾向于将概率平均分配给大部分上下文,其中包括不相关的部分;倾向于过度关注重复的标记,重复标记的概率随着每次重复而增加,形成正反馈循环。

在缓解这一问题上,S2A 的方法就是利用大语言模型(LLM),重新生成他们应该注意的上下文,一遍它只包含不会扭曲推理的相关材料。这包含两个过程:

  1. 给定一个上下文 x,S2A 系统剔除其中对输出产生的不利影响,生成一个新的上下文 y。
  2. 大模型再根据新的上下文 y,输出结果。

S2A 的几种变体:

  1. 没有上下文/问题分离(No context / Question Separation )

「Given the following text by a user, extract the part that is unbiased and not their opinion,so that using that text alone would be good context for providing an unbiased answer to the question portion of the text.

Please include the actual question or query that the user is asking. Separate this into two categories labeled with “Unbiased text context (includes all content except user’s bias):” and “Question/Query (does not include user bias/preference):”.

Text by User: [ORIGINAL INPUT PROMPT]」

  1. 保留原始上下文(Keep original context)

这种策略是避免一些被判断为不相关,实际很重要的信息被删除,保留原始上下文使得模型可以重新解释。这个方法的问题在于,原始上下文不相关的信息仍然存在,并可能仍然影响最终生成。

「Original user query (possibly biased): [ORIGINAL USER PROMPT] Unbiased context: [CONTEXT GENERATED BY S2A] Given the above unbiased context, answer the following: [QUESTION GENERATED BY S2A]」

  1. 强调相关性/不相关性(Emphasize Relevance/Irrelevance)

「Given the following text by a user, extract the part that is related and useful, so that using that text alone would be good context for providing an accurate and correct answer to the question portion of the text. Please include the actual question or query that the user is asking. Separate this into two categories labeled with ”Context text related to the question (includes all content except unrelated sentences):” and ”Detailed question:”. Do not use list.

Text by User: [ORIGINAL INPUT PROMPT]」

论文:https://arxiv.org/abs/2311.11829

Rephrase and Respond

相对于严谨的表述,人们会随意地提出问题。类比于人与人的沟通,GenAI 可能无法准确地理解人们提出的问题和指令。Rephrase and Respond 的方法是 建议让 LLM 重新表述问题并加入更多细节以便更好地回答。自动改写的问题往往会增强语义清晰度并有助于解决固有的歧义,这种自我改写技术可以显着提高准确性。