One-shot & few-shot
Name1_1_ 电影分类 Goal将电影评论分类为正面、中性或负面。
模型gemini-pro
| 温度 | n`x0np | 令牌限制 | 5 |
|---|---|---|---|
| Top-K | N/A | Top-P | 1 |
| 提示词 | ClassifymoviereviewsasPOSITIVE,NEUTRALorNEGATIVE. |
Review: "Her" is a disturbing study revealing the direction humanity is headed if AI is allowed to keep evolving, unchecked. I wish there were more movies like this masterpiece.
Sentiment:
输出积极
表 1. 零样本提示示例
当零样本提示无效时,可在提示中提供示范或示例,即 “ 单样本 ” 与 “ 少样本 ” 提示技术。通用提示 / 零样本
单样本与少样本
为 AI 模型设计提示时,提供示例有助于模型理解需求。当需要引导模型输出特定结构或模式时,示例尤为有效。
单样本提示会提供 single~ 个示例,因此得名。其核心是让模型通过模仿示例来完成任务。
少样本提示会向模型提供 multiple~ 个示例。该方法通过展示待遵循的模式,原理与单样本类似,但多示例能提升模型遵循目标模式的概率。
小样本提示所需的示例数量取决于几个因素,包括任务的复杂性、示例质量以及所用生成式 AI 模型的能力。一般而言,建议至少使用三到五个示例进行小样本提示。但对于更复杂的任务,可能需要更多示例;若受模型输入长度限制,则可能需要减少示例数量。
表 2 展示了一个小样本提示示例,我们将沿用之前的 gemini‑pro 模型配置设置,仅提高 token 限额以适应生成长响应需求。
Goal将披萨订单解析为 JSON
模型gemini-pro 温度n`x0np令牌限制250
Top‑K 采样Top‑P 采样
N/A1 提示词Parse a customer's pizza order into valid JSON:
EXAMPLE:
I want a small pizza with cheese, tomato sauce, and pepperoni.
JSON Response:
``` { "size": "small", "type": "normal", "ingredients": [["cheese", "tomato sauce", "peperoni"]] } ``` 转下页 ...
提示EXAMPLE:
Can I get a large pizza with tomato sauce, basil and mozzarella
{ "size": "large", "type": "normal", "ingredients": [["tomato sauce", "bazel", "mozzarella"]] }
Now, I would like a large pizza, with the first half cheese and mozzarella. And the other tomato sauce, ham and pineapple.
JSON Response:
输出``` { "size": "large", "type": "half-half", "ingredients": [["cheese", "mozzarella"], ["tomato sauce", "ham", "pineapple"]] } ```
Table 2. An example of few-shot prompting
为提示词选择示例时,应选用与目标任务相关的案例。示例需具备多样性、高质量且表述严谨。
细微差错可能导致模型混淆,产生不理想的输出结果。
如果你试图生成对各种输入都具有鲁棒性的输出,那么在示例中包含边缘案例就非常重要。边缘案例是指那些不寻常或意外的输入,但模型仍应能够处理。
全站分卷索引 · 34 卷
- 1Introduction
- 2Prompt engineering
- 3LLM output configuration
- 4Sampling controls
- 5Top-K and top-P
- 6Putting it all together
- 7Prompting techniques
- 8One-shot & few-shot
- 9System, contextual and role prompting
- 10System prompting
- 11Role prompting
- 12Contextual prompting
- 13Step-back prompting
- 14Chain of Thought (CoT)
- 15Self-consistency
- 16Tree of Thoughts (ToT)
- 17ReAct (reason & act)
- 18Automatic Prompt Engineering
- 19Code prompting
- 20Prompts for explaining code
- 21Prompts for translating code
- 22Prompts for debugging and reviewing code
- 23What about multimodal prompting?
- 24Design with simplicity
- 25Be specific about the output
- 26Control the max token length
- 27Experiment with input formats and writing styles
- 28Adapt to model updates
- 29JSON Repair
- 30Working with Schemas
- 31Experiment together with other prompt engineers
- 32CoT Best practices
- 33Summary
- 34Endnotes