Prompt Engineering

详解LLM中各个参数的意义

https://qianfan.cloud.baidu.com/qianfandev/topic/268819

https://www.promptingguide.ai/zh

从简单开始

指令

指令:"写入"、"分类"、"总结"、"翻译"、"排序"

以不同的关键词(keywords),上下文(contexts)和数据(data)试验不同的指令(instruction)

有些人建议将指令放在提示的开头。另有人则建议是使用像"###"这样的清晰分隔符来分隔指令和上下文。

指令 ###将以下文本翻译成西班牙语:文本:"hello!"

具体性

避免不明确

解释提示工程的概念。保持解释简短,只有几句话,不要过于描述。

具体、简洁并且切中要点的:使用 2-3 句话向高中学生解释提示工程的概念。

做什么还是不做什么?

避免说不要做什么,而应该说要做什么

不要改为应该避免

提示词示例

文本概括

Explain antibiotics

A:

"A:" 是一种在问答中使用的显式提示格式,你在这里使用它是为了告诉模型接下来你期望有一个答案。

Explain the above in one sentence:

用一句话解释上面的信息:

信息提取

Mention the large language model based product mentioned in the paragraph above:

问答

一个提示可以结合指令、上下文、输入和输出指示(output indicators)来获得更好的结果。

指令:Answer the question based on the context below. Keep the answer short and concise.

输出指示:Respond "Unsure about answer" if not sure about the answer.

上下文:Context: Teplizumab traces its roots to a New Jersey drug company called Ortho Pharmaceutical. There, scientists generated an early version of the antibody, dubbed OKT3. Originally sourced from mice, the molecule was able to bind to the surface of T cells and limit their cell-killing potential. In 1986, it was approved to help prevent organ rejection after kidney transplants, making it the first therapeutic antibody allowed for human use.

输入指示:Question: What was OKT3 originally sourced from?

Answer:

文本分类

提供的其他元素包括输入数据示例

Classify the text into neutral, negative or positive.

Text: I think the vacation is okay.

Sentiment: neutral

Text: I think the food was okay.

Sentiment:

对话

角色提示(Role Prompting)

The following is a conversation with an AI research assistant. The assistant tone is technical and scientific.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of blackholes?

AI:

给出更易于理解的回答。

The following is a conversation with an AI research assistant. The assistant answers should be easy to understand even by primary school students.

Human: Hello, who are you?

AI: Greeting! I am an AI research assistant. How can I help you today?

Human: Can you tell me about the creation of black holes?

AI:

代码生成

推理

提示技术

少样本提示

"whatpu"是坦桑尼亚的一种小型毛茸茸的动物。一个使用whatpu这个词的句子的例子是:我们在非洲旅行时看到了这些非常可爱的whatpus。

"farduddle"是指快速跳上跳下。一个使用farduddle这个词的句子的例子是:

这太棒了!// Negative

这太糟糕了!// Positive

哇,那部电影太棒了!// Positive

多么可怕的节目!//

链式思考(CoT)提示

少样本提示

这组数中的奇数加起来是偶数:4、8、9、15、12、2、1。

A:将所有奇数相加(9、15、1)得到25。答案为False。

这组数中的奇数加起来是偶数:17、10、19、4、8、12、24。

A:将所有奇数相加(17、19)得到36。答案为True。

这组数中的奇数加起来是偶数:16、11、14、4、8、13、24。

A:将所有奇数相加(11、13)得到24。答案为True。

这组数中的奇数加起来是偶数:17、9、10、12、13、4、2。

A:将所有奇数相加(17、9、13)得到39。答案为False。

这组数中的奇数加起来是偶数:15、32、5、13、82、7、1。

A:

请记住,作者声称这是足够大的语言模型才会出现的新兴能力。

零样本 COT 提示

我去市场买了10个苹果。我给了邻居2个苹果和修理工2个苹果。然后我去买了5个苹果并吃了1个。我还剩下多少苹果?

让我们逐步思考。

自动思维链(Auto-CoT)

当使用思维链提示时,这个过程需要手工制作有效且多样化的例子。这种手动工作可能会导致次优解决方案。Zhang et al. (2022)(opens in a new tab) 提出了一种消除人工的方法,即利用 LLMs "让我们一步一步地思考" 提示来生成一个接一个的推理链。这种自动过程仍然可能在生成的链中出现错误。为了减轻错误的影响,演示的多样性很重要。

Auto-CoT 主要由两个阶段组成:

  • 阶段1:问题聚类:将给定问题划分为几个聚类
  • 阶段2:演示抽样:从每组数组中选择一个具有代表性的问题,并使用带有简单启发式的 Zero-Shot-CoT 生成其推理链
相关推荐
garmin Chen37 分钟前
Prompt工程入门:让AI按你的要求工作(3)--Prompt工程与提示词安全评测概述
java·人工智能·python·安全·prompt
2501_940041741 小时前
全栈开发提速指南:可以直接用的项目生成提示词
前端·prompt
键盘侠伍十七18 小时前
Gandalf Lakera AI Prompt Injection 靶场深度教程:从 Level 1 到 Level 8 全面攻防解析
人工智能·prompt·ai安全
Rauser Mack1 天前
不懂编程,但是vibe coding一个扫雷游戏
人工智能·python·游戏·html·prompt
格图素书1 天前
AI安全攻防深度解析|Prompt注入与越狱攻击全拆解、供应链投毒风险深挖,助力大模型应用加固、RAG风控、全链路安全防控落地
人工智能·安全·prompt
小二·1 天前
Prompt Engineering 实战
网络·windows·prompt
暗夜猎手-大魔王1 天前
hermes源码学习4-Prompt 组装
人工智能·prompt
_Aaron___1 天前
RAG 多租户知识库:权限隔离不能只靠 Prompt
prompt
花月C1 天前
Agent上下文三级压缩
python·prompt·ai编程
Bruce_Liuxiaowei1 天前
Prompt注入_我的AI编码助手被策反了
人工智能·ai·prompt·提示词·智能体