type
status
date
slug
summary
tags
category
icon
password

Prompt Engineering 的定义

Prompt Engineering 是一种人工智能(AI)技术,它通过设计和改进 AI 的 prompt 来提高 AI 的表现。Prompt Engineering 的目标是创建高度有效和可控的 AI 系统,使其能够准确、可靠地执行特定任务。
简单理解 给 AI 模型的指令。它可以是一个问题、一段文字描述,甚至可以是带有一堆参数的文字描述。AI 模型会基于 prompt 所提供的信息,生成对应的文本,亦或者图片。

为什么需要学习 PE

  1. 大模型还不够完善,需要足够信息才能得到相对较好的答案;
  1. 人和人对话的时候是包含表情和动作的,也就是在一定的情景下,人是能感知到这个表情和动作的,但是大语言模型只能感知文字,并且根据知识库内容推测出答案;
💡
PE 在很多时候认为是一个过渡的产物,在未来的5年时候将不需要。

基本原则 & 建议

  1. 建议使用最新的模型
  1. Prompt 里最好包含完整的信息
  1. Prompt 最好简洁易懂,并减少歧义
  1. Prompt 要使用正确的语法、拼写,以及标点
  1. 从简单的先开始,并给产品多一点耐心

理论

Elavis Saravia 总结的框架


  • Instruction(必须): 指令,即你希望模型执行的具体任务。
  • Context(选填): 背景信息,或者说是上下文信息,这可以引导模型做出更好的反应。
  • Input Data(选填): 输入数据,告知模型需要处理的数据。
  • Output Indicator(选填): 输出指示器,告知模型我们要输出的类型或格式。
只要你按照这个框架写 prompt ,模型返回的结果都不会差。
当然,你在写 prompt 的时候,并不一定要包含所有4个元素,而是可以根据自己的需求排列组合。比如拿前面的几个场景作为例子:
  • 推理:Instruction + Context + Input Data
  • 信息提取:Instruction + Context + Input Data + Output Indicator

CRISPE Prompt Framework


另一个我觉得很不错的 Framework 是 Matt Nigh 的 CRISPE Framework,这个 framework 更加复杂,但完备性会比较高,比较适合用于编写 prompt 模板。CRISPE 分别代表以下含义:
  • CR: Capacity and Role(能力与角色)。你希望 ChatGPT 扮演怎样的角色。
  • I: Insight(洞察力),背景信息和上下文(坦率说来我觉得用 Context 更好)。
  • S: Statement(指令),你希望 ChatGPT 做什么。
  • P: Personality(个性),你希望 ChatGPT 以什么风格或方式回答你。
  • E: Experiment(尝试),要求 ChatGPT 为你提供多个答案。
以下是这几个参数的例子:
Step
Example
Capacity and Role
Act as an expert on software development on the topic of machine learning frameworks, and an expert blog writer.把你想象成机器学习框架主题的软件开发专家,以及专业博客作者。
Insight
The audience for this blog is technical professionals who are interested in learning about the latest advancements in machine learning.这个博客的读者主要是有兴趣了解机器学习最新进展技术的专业人士。
Statement
Provide a comprehensive overview of the most popular machine learning frameworks, including their strengths and weaknesses. Include real-life examples and case studies to illustrate how these frameworks have been successfully used in various industries.提供最流行的机器学习框架的全面概述,包括它们的优点和缺点。包括现实生活中的例子,和研究案例,以说明这些框架如何在各个行业中成功地被使用。
Personality
When responding, use a mix of the writing styles of Andrej Karpathy, Francois Chollet, Jeremy Howard, and Yann LeCun.在回应时,混合使用 Andrej Karpathy、Francois Chollet、Jeremy Howard 和 Yann LeCun 的写作风格。
Experiment
Give me multiple different examples.给我多个不同的例子。

基本使用场景 & 使用技巧

场景1:问答问题


使用技巧一:To do and Not To do
Instead of just saying what not to do, say what to do instead. 与其告知模型不能干什么,不妨告诉模型能干什么。
场景
Less Effective
Better
原因
推荐雅思必背英文单词
Please suggest me some essential words for IELTS
Please suggest me 10 essential words for IELTS
后者 prompt 会更加明确,前者会给大概 20 个单词。这个仍然有提升的空间,比如增加更多的限定词语,像字母 A 开头的词语。
推荐香港值得游玩的地方
Please recommend me some places to visit in Hong Kong. Do not recommend museums.
Please recommend me some places to visit in Hong Kong including amusement parks.
后者的推荐会更准确高效一些,但如果你想进行一些探索,那前者也能用。

场景2:基于示例回答


技巧 2:增加示例
场景
Less Effective
Better
原因
起产品名
Product description: A pair of shoes that can fit any foot size.Seed words: adaptable, fit, omni-fit.Product names:
Product description: A home milkshake makerSeed words: fast, healthy, compact.Product names: HomeShaker, Fit Shaker, QuickShake, Shake MakerProduct description: A pair of shoes that can fit any foot size.Seed words: adaptable, fit, omni-fit.Product names:
可以在下方运行这个案例,在不给示例的情况下 AI 会给你什么答案。
将电影名称转为 emoji
Convert Star Wars into emoji
Convert movie titles into emoji.Back to the Future: 👨👴🚗🕒Batman: 🤵🦇Transformers: 🚗🤖Star Wars:
可以在下方运行这个案例,在不给示例的情况下 AI 会给你什么答案。

场景3:推理


推理层面大模型表现很好

场景4:无中生有——写代码


技巧 3:使用引导词,引导模型输出特定语内容
Create a MySQL query for all students in the Computer Science Department: Table departments, columns = [DepartmentId, DepartmentName] Table students, columns = [DepartmentId, StudentId, StudentName] SELECT
prompt = f""" Generate a list of three made-up book titles along \ with their authors and genres. Provide them in JSON format with the following keys: book_id, title, author, genre. """

场景5:锦上添花——改写内容


技巧 4:增加 Role(角色)或人物
You are a primary school teacher who can explain complex content to a level that a 7 or 8 year old child can understand. Please rewrite the following sentences to make them easier to understand:

场景6:锦上添花——信息解释


Explanation of what the code does: Python 3 def remove_common_prefix(x, prefix, ws_prefix): x["completion"] = x["completion"].str[len(prefix) :] if ws_prefix: # keep the single whitespace as prefix x["completion"] = " " + x["completion"] return x

场景7:化繁为简——信息总结


技巧 5:使用特殊符号将指令和需要处理的文本分开
text = f""" You should express what you want a model to do by \ providing instructions that are as clear and \ specific as you can possibly make them. \ This will guide the model towards the desired output, \ and reduce the chances of receiving irrelevant \ or incorrect responses. Don't confuse writing a \ clear prompt with writing a short prompt. \ In many cases, longer prompts provide more clarity \ and context for the model, which can lead to \ more detailed and relevant outputs. """ prompt = f""" Summarize the text delimited by triple backticks \ into a single sentence. `{text}` """

场景8:化繁为简——信息提取


技巧 6:通过格式词阐述需要输出的格式
You will be provided with text delimited by triple quotes. If it contains a sequence of instructions, \ re-write those instructions in the following format: Step 1 - ... Step 2 - … … Step N - … If the text does not contain a sequence of instructions, \ then simply write \"No steps provided.\" \"\"\"{text}\"\"\"
 

🔗 引用文章


 
 
💡
有关于博客的任何问题,请在下方留言,感谢~ 🤞🏻
AI是银弹么?权限系统设计模型

  • Giscus
  • Cusdis
Sheamus
Sheamus
I'm a geeker!
公告
type
status
date
slug
summary
tags
category
icon
password

📢📢📢 重磅更新 📢📢📢

首页添加了 ChatGPT 的入口,只要添加上你自己的 OpenAI API key 你就能轻松玩转 ChatGPT 了~~~
使用过程有任何问题请到留言区留言,感谢 👏🏻👏🏻👏🏻