微信扫码
与创始人交个朋友
我要投稿
本文将介绍在设计Prompt时可以采用的一些常规设计策略。虽然Prompt设计方法没有正确或错误一说,但可以使用常见的策略来影响模型的回答。严格地测试和评估对于优化模型性能仍然至关重要。
大语言模型 (LLM) 使用大量文本数据进行训练,以学习语言单元之间的模式和关系。在获得一些文本(Prompt)后,语言模型可以预测接下的内容,就像一个复杂的自动补全工具。因此,在设计Prompt时,请考虑可能影响模型预测结果的不同因素。
提供清晰而具体的说明
详细描述希望模型执行的任务。以下提示告诉模型提取一段文本的摘要:
Summarize this text.Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentiallyfaster than any modern traditional computer. At very tiny scales, physical matter acts as bothparticles 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 deployedat scale, quantum computers could be used in a wide variety of applications such as: incybersecurity to break existing encryption methods while helping researchers create new ones, inmeteorology to develop better weather forecasting etc. However, the current state of the art quantumcomputers are still largely experimental and impractical.
模型结果:
Quantum computers utilize quantum mechanical phenomena to perform computations significantly fasterthan 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.
Summarize this text in two sentences.Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentiallyfaster than any modern traditional computer. At very tiny scales, physical matter acts as bothparticles 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 deployedat scale, quantum computers could be used in a wide variety of applications such as: incybersecurity to break existing encryption methods while helping researchers create new ones, inmeteorology to develop better weather forecasting etc. However, the current state of the art quantumcomputers are still largely experimental and impractical.
模型结果:
Quantum computers use quantum mechanical phenomena to perform calculations much faster thantraditional computers. They have the potential to revolutionize various fields, but current quantumcomputers are still experimental and impractical.
可以提供指定回答格式的说明。例如,可以要求将回答格式设置为表格、项目符号列表、电梯间推销、关键字、句子或段落。以下Prompt指示模型使用项目符号列出文本中的关键信息:
Summarize this text as bullets points of key information.Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentiallyfaster than any modern traditional computer. At very tiny scales, physical matter acts as bothparticles 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 deployedat scale, quantum computers could be used in a wide variety of applications such as: incybersecurity to break existing encryption methods while helping researchers create new ones, inmeteorology to develop better weather forecasting etc. However, the current state of the art quantumcomputers are still largely experimental and impractical.
模型结果:
- Quantum computers leverage quantum mechanical phenomena for exponentially faster calculations thantraditional computers.- Quantum devices utilize specialized hardware to exploit tiny-scale matter behavior as bothparticles 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中包含提示回答示例有助于模型学习如何回答。
向模型提供要遵循的模式示例,而不是应避免的模式示例。
尝试在提示中添加不同数量的示例。具体取决于模型,示例太少会导致无法有效改变模型行为,示例太多会导致模型过拟合。
在各个示例之间使用一致的格式
以下零样本提示要求模型选择最佳解释。
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 funA short and simple poemDon't you enjoy them?
肯定模式
Always end haikus with an assertion:Haiku are funA short and simple poemA 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 andblinking 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.
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:”是输出前缀。
Classify the text as one of the following categories.- large- smallText: RhinoThe answer is: largeText: MouseThe answer is: smallText: SnailThe answer is: smallText: ElephantThe answer is:
模型回答:
large
使用前缀可以明确的告诉模型,后面内容块作用,在实践中尽量要提供出来。
53AI,企业落地应用大模型首选服务商
产品:大模型应用平台+智能体定制开发+落地咨询服务
承诺:先做场景POC验证,看到效果再签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2024-09-18
2024-07-02
2024-07-18
2024-07-09
2024-07-15
2024-08-14
2024-07-26
2024-07-10
2024-07-10
2024-06-22
2024-11-20
2024-11-13
2024-10-31
2024-10-29
2024-10-16
2024-09-19
2024-08-28
2024-08-24