Prompt设计技巧和高级PE

目录

PD and PE:INTRODUCTION AND ADVANCED METHODS

1.Instructions

2.Basic Knowledge - Prompt

2.1 Prompt

2.2 Prompt Cases

2.3 Prompt Engineering

3. LLM 的局限

4. Prompt 设计技巧和方法

4.1 Chain of thought prompting

4.2 Encouraging the model to be factual through other means

4.3 Explicitly ending the prompt instructions

4.4 Being forceful

4.5 Use the AI to correct itself

4.6 Generate different opinions

4.7 Keeping state + role playing

4.8 Teaching an algorithm in the prompt

4.9 The order of the examples and the prompt

4.10 Affordances

5. Advanced PE

5.1 Chain of Thought (CoT)

5.2 Tree of Thought (ToT)

5.3 Reflection

5.4 Expert Prompting

5.5 Streamlining Complex Tasks with Chains

5.6 Guiding LLM Outputs with Rails

5.7 Streamlining Prompt Design with Automatic Prompt Engineering

5.8 Augmenting LLMs through External Knowledge - RAG

6.LLM Agents 大模型代理

6.1 Prompt Engineering Techniques for Agents

6.1.1 Reasoning without Observation (ReWOO)

6.1.2 Reason and Act (ReAct)

6.1.3 Dialog-Enabled Resolving Agents (DERA)

7.Prompt Engineering Tools and Frameworks

Conclusion


本文讨论了 Prompt 设计和 Prompt 工程(PE)的相关内容,包括其基本概念、LLM 的局限、设计技巧和方法、高级 PE 以及相关工具和框架等方面。

关键要点包括:

  • Prompt 的定义和构成:Prompt 是用户提供的用于指导 LLM 输出的文本型输入,由 Instructions、Questions、Input Data 和 Examples 构成,其中 Instructions 和 Questions 是必要的。

  • LLM 的局限:包括缺乏持久的上下文记忆、输出具有随机性、缺乏实时更新能力、可能生成“幻觉”、计算成本高、资源需求大以及专业领域性能欠佳。

  • Prompt 设计技巧和方法:如思维链提示、事实性增强、明确结束指令提示、强硬、自我纠正、生成不同意见、保持状态和角色扮演、通过提示词指导 LLM 学习、注意 Prompt 投喂顺序、提供性等。

  • 高级 PE:涵盖推理链、思维树、自我审查、专家提示、链式结构、Rails 引导 LLM 输出、自动提示词工程、通过外部知识增强 LLM 等。

  • 工具和框架:介绍了 LangChain、Semantic Kernel、Guidance Library、Nemo Guardrails、LlamaIndex、FastRAG、Auto-GPT、AutoGen 等用于 Prompt 工程的工具和框架。

PD and PE:INTRODUCTION AND ADVANCED METHODS

1.Instructions

Prompt Design 和 PE 依然成为了最大限度的发挥LLM潜力的关键。针对于此,本文介绍了核心概念、思想链、模型反思等先进技术,以及基于LLM代理背后的原理。同时提供了关于PE 的工具调查。

2.Basic Knowledge - Prompt

2.1 Prompt

Prompt是由用户提供的用于指导LLM输出的文本型输入。Prompt可以是简单的问题也可以是复杂的描述甚至特定任务。比如DALLE-3等文生图大模型的Prompt通常是描述性的,而GPT-4或者Gemini等LLM Prompt可以简单的问题描述也可以是复杂的、特定任务的描述。

Prompt = Instructions + Questions + Input Data + Examples,但是其中Instructions 和 Questions 是必要的,而其他Elements 是可有可无的。

暂时无法在飞书文档外展示此内容

2.2 Prompt Cases

  1. Instructions + questions :

“How should I write my college admission essay? Give me suggestions about the different sections I should include, what tone I should use, and what expressions I should avoid.”

  1. Instructions + input:

“Given the following information about me, write a 4 paragraph college essay: I am originally from Barcelona, Spain. While my childhood had different traumatic events, such as the death of my father when I was only 6, I still think I had quite a happy childhood.. During my childhood, I changed schools very often, and attended all kinds of schools, from public schools to very religious private ones. One of the most “exotic” things I did during those years is to spend a full school year studying 6th grade in Twin Falls, Idaho, with my extended family. I started working very early on. My first job, as an English teacher, was at age 13. After that, and throughout my studies, I worked as a teacher, waiter, and even construction worker.”

  1. Question + Examples:

“Here are some examples of TV shows I really like: Breaking Bad, Peaky Blinders, The Bear. I did not like Ted Lasso. What other shows do you think I might like?”

2.3 Prompt Engineering

Prompt engineering:

  1. At its core, a prompt is the textual interface through which users communicate their desires to the model.

  2. The essence of prompt engineering lies in crafting the optimal prompt to achieve a specific goal with a generative model.

  PE 不是简单的 Prompt 构建,可以彻底改变 ML 的某些方面,超越特征或架构工程等传统方法。

3. LLM 的局限

大型语言模型 (LLM),包括基于 Transformer 架构的模型,已成为推进自然语言处理的关键。这些模型在大量数据集上进行了预先训练以预测后续标记,表现出卓越的语言能力。但是 LLM 的固有限制仍然影响其应用和有效性。

Limitaions:

  1. 缺乏持久的上下文记忆

  2. 输出具有随机性,可能导致不一致

  3. 基于历史数据,缺乏实时更新能力

  4. 可能生成“幻觉”(即虚假的内容)

  5. 计算成本高,资源需求大

  6. 专业领域性能欠佳

4. Prompt 设计技巧和方法

4.1 Chain of thought prompting

思维链:通过强制模型遵循一系列“推理”步骤来明确鼓励模型是事实/正确的。

Prompt form:

4.2 Encouraging the model to be factual through other means

事实性增强:通过提供参考来源提示模型生成更真实的信息。

通过提示模型引用正确的来源来为模型指明正确的方向。可以有效地缓解-可能会产生不真实或错误的幻觉知识问题。

4.3 Explicitly ending the prompt instructions

明确结束指令提示::

基于 GPT 的 LLM 有一个特殊的消息 <|endofprompt|> ,它指示语言模型将代码后面的内容解释为完成任务。

强硬:LLM 是很聪明的,可以通过加粗或者大写英文单词或者字母,甚至加感叹号等方式增强你的语气,那么它就会更遵循你的Prompt。

4.5 Use the AI to correct itself

自我纠正:让LLM生成Respon

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值