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 生成其推理链
相关推荐
Yolanda944 小时前
【人工智能】《从零搭建AI问答助手项目(九):Prompt优化》
人工智能·prompt
TheRouter19 小时前
AI Agent 的Prompt Injection 防御实战:从EchoLeak 零点击外泄到6层防护栈(含可运行代码与对比表)
人工智能·ai·prompt
Nayxxu19 小时前
Claude Prompt Caching 详解:缓存写入、缓存读取与成本计算
缓存·prompt
AI布道师-wang19 小时前
第 6 章:Prompt 工程——和模型高效沟通
人工智能·机器学习·prompt
meilindehuzi_a19 小时前
Vibe Coding 实战:我用一条 Prompt 指挥 AI “盲盒式”生成 3D 积木物理世界
3d·prompt
霍格沃兹测试学院-小舟畅学2 天前
Anthropic 开源 Skills:Agent 工程化,开始从 Prompt 走向能力封装
prompt
玄米乌龙茶1232 天前
LLM 应用开发学习笔记:System Prompt 设计、注入风险与成本优化
笔记·学习·prompt
一条泥憨鱼2 天前
全面解析 AI 大模型中的 Prompt
人工智能·ai·prompt
sugar__salt2 天前
从Prompt到3D世界:用大模型精准构建你的迷你村庄
3d·ai·prompt·ai编程
闵孚龙2 天前
Claude Code 驾驭工程原则全解析:AI Agent、上下文工程、Prompt Cache、权限安全、A/B测试、长期记忆与多智能体架构底层方法论
人工智能·安全·prompt