当前位置: 首页 > article >正文

大模型Prompt提示设计简介(2):有效的建议

本文将介绍在设计Prompt时可以采用的一些常规设计策略。虽然Prompt设计方法没有正确或错误一说,但可以使用常见的策略来影响模型的回答。严格地测试和评估对于优化模型性能仍然至关重要。

大语言模型 (LLM) 使用大量文本数据进行训练,以学习语言单元之间的模式和关系。在获得一些文本(Prompt)后,语言模型可以预测接下的内容,就像一个复杂的自动补全工具。因此,在设计Prompt时,请考虑可能影响模型预测结果的不同因素。

提供清晰而具体的说明

通过向模型提供关于要做什么的指令,可以有效且高效地自定义模型行为。确保提供的指令清晰而具体。指令可以很简单,比如是一个分步说明列表;也可以很复杂,例如反映用户的思考过程和思维模式。

划重点:

  • 明确向模型提供有关要做什么的指令。
  • 说明应清晰而具体。
  • 明确指定限制条件或格式要求。

定义要执行的任务

详细描述希望模型执行的任务。以下提示告诉模型提取一段文本的摘要:

Summarize this text.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.

模型结果:

Quantum computers utilize quantum mechanical phenomena to perform computations significantly faster
than traditional computers. By exploiting the particle-wave duality of matter at tiny scales,
quantum computers leverage specialized hardware to solve problems beyond classical physics.
Potential applications include breaking encryption, developing better weather forecasting, and more.
However, current quantum computers are still largely experimental and impractical.

指定限制条件

明确指定有关读取Prompt或生成回答的限制条件。可以告诉模型要做什么和不应该做什么。在上一个示例中,摘要比原始文本短,但您可能想要更短的摘要。在这种情况下,可以在Prompt中指定一个限制条件,以限制摘要长度(只输出两句话):

Summarize this text in two sentences.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.

模型结果:

Quantum computers use quantum mechanical phenomena to perform calculations much faster than
traditional computers. They have the potential to revolutionize various fields, but current quantum
computers are still experimental and impractical.

定义回答格式

可以提供指定回答格式的说明。例如,可以要求将回答格式设置为表格、项目符号列表、电梯间推销、关键字、句子或段落。以下Prompt指示模型使用项目符号列出文本中的关键信息:

Summarize this text as bullets points of key information.T
ext: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.

模型结果:

- Quantum computers leverage quantum mechanical phenomena for exponentially faster calculations than
traditional computers.
- Quantum devices utilize specialized hardware to exploit tiny-scale matter behavior as both
particles and waves.
- Their operating principles transcend classical physics.
- Potential applications include cybersecurity, weather forecasting, and more.
- Current quantum computers are largely experimental and impractical.

指定格式在实际项目中是非常有用的操作,这样可以便于我们对结果进行提取和加工,满足下一步的业务需求。

添加少样本示例

可以在Prompt中添加示例,以向模型示范想要的结果。模型会尝试识别示例中的模式和关系,并在生成回答时应用它们。包含少量示例的提示称为少样本提示,而不提供示例的提示称为零样本提示。少样本提示通常用于规定模型回答的格式、措辞、范围界定或一般模式。使用具体而多样的示例来帮助模型缩小其重点并生成更准确的结果。

建议始终在Prompt中包含少样本示例。不含少样本示例的Prompt可能效果不大,因为它们向模型展示了如何应用指令。事实上,如果示例足够清晰地显示当前任务,则可以从提示中移除指令。

划重点:

  • 在Prompt中包含提示回答示例有助于模型学习如何回答。
  • 向模型提供要遵循的模式示例,而不是应避免的模式示例。
  • 尝试在提示中添加不同数量的示例。具体取决于模型,示例太少会导致无法有效改变模型行为,示例太多会导致模型过拟合。
  • 在各个示例之间使用一致的格式

零样本提示与少样本提示

以下零样本提示要求模型选择最佳解释。

Please choose the best explanation to the question:

Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:

模型结果:

Explanation1

如果您的用例要求模型生成简洁的回答,您可以在提示中添加偏好简洁回答的示例。

以下提示提供了两个偏好较短解释的示例。在回答中,您可以看到这些示例引导模型选择较短的解释(解释 2),而不是像之前那样较长的解释(解释 1)。

Please choose the best explanation to the question:

Question: Why is sky blue?
Explanation1: The sky appears blue because of Rayleigh scattering, which causes shorter blue
wavelengths of light to be scattered more easily than longer red wavelengths, making the sky look
blue.
Explanation2: Due to Rayleigh scattering effect.
Answer: Explanation2

Question: What is the cause of earthquakes?
Explanation1: Sudden release of energy in the Earth's crust.
Explanation2: Earthquakes happen when tectonic plates suddenly slip or break apart, causing a
release of energy that creates seismic waves that can shake the ground and cause damage.
Answer: Explanation1

Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:

模型结果:

Explanation2

找到最佳示例数量

您可以改变提示中提供的示例数量来进行实验,以获得最想要的结果。PaLM 和 Gemini 等模型通常可以通过少量示例来学习模式,但您可能需要进行多次实验,以找到可产生所需结果的示例数量。对于 BERT 等较简单的模型,您可能需要更多示例。但是,如果您添加太多示例,模型的回答可能会与示例过拟合。

使用示例肯定模式而不是否定模式

使用示例向模型展示要遵循的模式比使用示例向模型展示要避免的否定模式更有效。

否定模式

Don't end haikus with a question:
Haiku are fun
A short and simple poem
Don't you enjoy them?

肯定模式

Always end haikus with an assertion:
Haiku are fun
A short and simple poem
A joy to write

在Prompt中,我们使用肯定语句的效果比否定语句更好,应该告诉模型做什么,而不是要求他不要做什么。

在各个示例之间使用一致的格式

确保少样本示例的结构和格式相同,以避免回答具有不需要的格式。在Prompt中添加少样本示例的主要目标之一是向模型展示回答格式。因此,必须确保在所有示例中使用一致的格式,尤其是注意 XML 标记、空格、换行符和示例分隔符。

添加上下文信息

可以在Prompt中添加指令和模型解决问题所需的信息,而不是假设模型具备所有必要信息。这些上下文信息可帮助模型了解您要求其执行的操作的限制和详细信息。

划重点:

  • 在希望模型在生成回答时使用的Prompt中添加信息(上下文)。
  • 为模型提供有关如何使用上下文信息的指令。

以下示例要求模型提供路由器的问题排查指导:

What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and
blinking slowly.

模型结果:

1. **Check the Cables:**
- Make sure that all cables are securely connected to your Google Wifi router and modem.
- Try replacing the cables with new ones to ensure they are not faulty.

2. **Reboot the Router:**
- Unplug your Google Wifi router and modem from the power outlet.
- Wait for at least 30 seconds.
- Plug the modem and router back in and wait for them to start up.

3. **Factory Reset the Router:**
- Resetting the router will restore it to its default settings.
- Find the small reset button on the back of the router.
- Press and hold the reset button with a paper clip or similar object for 10 seconds.
- Release the button and wait for the router to restart.
- If you've tried the above steps and the issue persists, contact Google support for further assistance.

这个回答看起来是通用的问题排查信息,并非特定于路由器或 LED 指示灯的状态。

如需针对特定路由器自定义回答,可以在Prompt中添加该路由器的问题排查指南作为上下文,供模型在回答时参考。

Answer the question using the text below. Respond with only the text provided.
Question: What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and blinking slowly.

Text:
Color: Slowly pulsing yellow
What it means: There is a network error.
What to do:
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.

Color: Fast blinking yellow
What it means: You are holding down the reset button and are factory resetting this device.
What to do:
If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button.

Color: Solid yellow
What it means: Router is factory resetting.
What to do:
This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup.

Color: Solid red
What it means: Something is wrong.
What to do:
Critical failure. Factory reset the router. If the light stays red, contact Wifi customer support.
响应:

模型回答:

Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.

由于大模型的能力限制,使用上下文是目前比较火的应用领域,可以用来加入领域知识回答专有领域的问题;也可以加入上下文,限制回答的范围等。

添加前缀

前缀是添加到Prompt内容中的字词或短语,有多种用途,具体取决于前缀的位置:

  • 输入前缀:为输入添加前缀可向模型指示输入中在语义上有意义的部分。例如,前缀“英语:”和“法语:”区分两种不同的语言。
  • 输出前缀:虽然输出由模型生成,也可以在Prompt中为输出添加前缀。输出前缀可为模型提供有关预期回答的信息。例如,输出前缀“JSON:”告诉模型输出应采用 JSON 格式。
  • 示例前缀:在少样本Prompt中,为示例添加前缀提供了模型在生成输出时可以使用的标签,使解析输出内容变得更加容易。

在以下示例中,“Text:”是输入前缀,“The answer is:”是输出前缀。
在这里插入图片描述

模型回答:

large

使用前缀可以明确的告诉模型,后面内容块作用,在实践中尽量要提供出来。

内容比较多,本篇文章介绍到这,下篇文章我们继续。

如何学习大模型

现在社会上大模型越来越普及了,已经有很多人都想往这里面扎,但是却找不到适合的方法去学习。

作为一名资深码农,初入大模型时也吃了很多亏,踩了无数坑。现在我想把我的经验和知识分享给你们,帮助你们学习AI大模型,能够解决你们学习中的困难。

我已将重要的AI大模型资料包括市面上AI大模型各大白皮书、AGI大模型系统学习路线、AI大模型视频教程、实战学习,等录播视频免费分享出来,需要的小伙伴可以扫取。

一、AGI大模型系统学习路线

很多人学习大模型的时候没有方向,东学一点西学一点,像只无头苍蝇乱撞,我下面分享的这个学习路线希望能够帮助到你们学习AI大模型。

在这里插入图片描述

二、AI大模型视频教程

在这里插入图片描述

三、AI大模型各大学习书籍

在这里插入图片描述

四、AI大模型各大场景实战案例

在这里插入图片描述

五、结束语

学习AI大模型是当前科技发展的趋势,它不仅能够为我们提供更多的机会和挑战,还能够让我们更好地理解和应用人工智能技术。通过学习AI大模型,我们可以深入了解深度学习、神经网络等核心概念,并将其应用于自然语言处理、计算机视觉、语音识别等领域。同时,掌握AI大模型还能够为我们的职业发展增添竞争力,成为未来技术领域的领导者。

再者,学习AI大模型也能为我们自己创造更多的价值,提供更多的岗位以及副业创收,让自己的生活更上一层楼。

因此,学习AI大模型是一项有前景且值得投入的时间和精力的重要选择。


http://www.kler.cn/a/282614.html

相关文章:

  • awk(常用)
  • Excel模板下载\数据导出
  • 【知识科普】微内核架构与宏内核架构
  • MFC程序崩溃时生成dmp文件
  • 11. 观光景点组合得分问题 |豆包MarsCode AI刷题
  • Go开发指南- Goroutine
  • 在C语言中使用POSIX线程库(pthread)实现多线程编程
  • Redis多线程特性
  • CSS中禁用DOM事件
  • OpenCV绘图函数(12)绘制直线函数 line()的使用
  • 数学基础 -- 线性代数之向量基本概念
  • Flask+LayUI开发手记(五):树型表格实现数据展示与编辑
  • 开源 AI 智能名片 O2O 商城小程序在社交私域中的圈层价值
  • 数据库:笔记03SQL
  • geodatatool(地图资源工具)下载高德数据及数据共享
  • 设计模式之工厂模式和策略模式的区别
  • MFC工控项目实例之八选择下拉菜单添加打钩图标
  • 提高 Web 应用程序安全性的标准
  • Scrapy添加代理IP池:自动化爬虫的秘密武器
  • 大数据技术之Flume 参数调优(12)
  • selenium滚动到页面底部
  • 企业数据治理之主数据---供应商主数据
  • 关于测试工程师在性能测试工具jmeter的熟悉和精通
  • echarts 柱状图_堆叠柱状图_数据分区_常用图表配置_数据可视化
  • Oracle(94)如何创建角色?
  • 海思SD3403/SS928V100开发(16)Tsensor驱动开发