六、Prompt工程——进阶迭代


这些都是业界总结出来的一些方法论,大家主要是学习其理念和方法。当我们要使用大模型去完成比较复杂任务的时候,可能提示词要复杂的多,我们要做的就是尝试各种办法让大模型返回我们想要的结果。提示词优化的过程就是不断迭代的过程。

一、Prompt样本提示

零样本提示(Zero-shot Prompting)

零样本提示(Zero-shot Prompting),也就是不需要微调,不需要提供任何示例样本也可以直接通过提问来让模型解决相应的任务。这是因为模型本身就通过了大量数据进行了训练。

在这里插入图片描述

少量样本提示(Few-shot Prompting)

虽然模型只通过 zero-shot 零样本的能力就已经很强大了,但如果你的任务需求比较复杂,直接使用 Zero-shot不一定能满足需求。这时候就应该使用 few-shot 少量样本提示,相当于在 Prompt 中给问题提供一个 Context上下文,在上下文里面给模型提供示例,这个示例的作用并不是让模型去学习,因为光靠几个示例是完全不够学习的。这几个示例的作用实际上是引导,引导模型找到对应的回答方式,从而生成更准确的响应。
在这里插入图片描述
few-shot 虽然解决了 zero-shot 的问题,能够适用于分类等许多基本任务,但如果遇到了需要推理的复杂任务时,few-shot 就无能为力了。因为模型无法从少量样本中学习到完整的推理过程。这时候就要引申出另外一个概念思维链提示CoT (Chain-of- Thought Prompting)。
通常涉及到推理的复杂任务,并不是可以一步直接得到答案的,中间会有很多的计算和推理过程。当我们让ChatGPT 回答这些推理问题时,并没有给模型足够的思考空间,他没有草稿纸去进行计算。所以我们在给到模型提供示例时,不要只给一个答案,而是要把解题思路也给到模型,这样的话模型学习到的效果会更好。
在这里插入图片描述类似这类逻辑题,如果ChatGPT没有回答对,可以加上“请一步步分析”,在某些场景有奇效,有时英文效果更好“Let’s think step by step”,“Analyze step by step”

在这里插入图片描述

自洽性/自一致性(Self-Consistency)

如果你发现这样还是不能解决问题。那还可以更进一步的对 Prompt 进行优化 ,这些优化的方法是 CoT 变种。比如可以让 ChatGPT 产生多个思维链,也就是多个推理路径,最终选择一个一致性最高的答案。这种方法叫做 Self-Consitency 自洽性。为一个问题,提供3个解决方案,最终结合3个解决方案给出与问题一致性最高的答案。
在这里插入图片描述
在这里插入图片描述

Prompt生成知识提示

生成知识提示(Generate Knowledge Prompting)

还有很小的情况下,无论如何模型都没法解决我们的问题。因为模型本身可能本身缺少解决问题的背景知识,或者模型想不到要用什么背景知识。

如果是前者,那只能是我们主动通过上下文 Context 的方式把背景知识直接添加到 Prompt 中再让模型去回答。而如果是后者,则可以先给模型一些示例来让模型自己去生成对应问题的背景知识,这个技巧叫做 Generate Knowledge Prompting生成知识提示,这样有了背景知识后,再把生成后得到的背景知识添加到 Context 中向模型提问,这样模型因为有了背景知识自然就能准确回答我们的问题。

在这里插入图片描述在这里插入图片描述在这里插入图片描述

更多知识可以参考:https://learnprompting.org/zh-Hans/docs/intro

### Prompt Engineering Iteration Methods and Processes In the context of developing prompts for AI systems, an iterative method is essential to refine and optimize interactions. The process involves continuous improvement through cycles of design, testing, evaluation, and modification. #### Designing Initial Prompts The initial stage focuses on crafting clear, concise, and effective instructions that guide the model towards desired outputs[^3]. This includes specifying parameters such as tone, style, length, and content type expected from responses. #### Testing with Real Users Once designed, these prompts should be tested using real user scenarios where possible feedback loops are established between developers and end-users. Gathering qualitative data about how well models interpret given commands helps identify areas needing adjustment[^2]. #### Evaluating Performance Metrics Performance metrics play a crucial role during this phase by quantifying success rates against predefined criteria like accuracy, relevance, coherence etc., allowing teams to measure progress objectively over time[^1]. #### Refining Based on Feedback Feedback collected informs subsequent iterations aimed at addressing shortcomings identified earlier while preserving successful elements within existing designs. Adjustments may involve altering wording choices, adding contextual information, or even restructuring entire sequences depending upon observed outcomes. ```python def evaluate_prompt_effectiveness(prompt): """ Function simulates evaluating effectiveness of generated prompt. Args: prompt (str): Input string representing crafted instruction Returns: float: Score indicating quality level ranging 0 - 1.0 """ score = random.uniform(0, 1) return round(score, 2) # Example usage demonstrating hypothetical scoring mechanism applied post iteration cycle completion print(f"Prompt Effectiveness Rating: {evaluate_prompt_effectiveness('Write me a short story.')}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

偷学技术的梁胖胖yo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值