← 返回目录

One-shot & few-shot

第 8 / 34 卷日期:

Name1_1_ 电影分类 Goal将电影评论分类为正面、中性或负面。

模型gemini-pro

温度n`x0np令牌限制5
Top-KN/ATop-P1
提示词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 卷
  1. 1Introduction
  2. 2Prompt engineering
  3. 3LLM output configuration
  4. 4Sampling controls
  5. 5Top-K and top-P
  6. 6Putting it all together
  7. 7Prompting techniques
  8. 8One-shot & few-shot
  9. 9System, contextual and role prompting
  10. 10System prompting
  11. 11Role prompting
  12. 12Contextual prompting
  13. 13Step-back prompting
  14. 14Chain of Thought (CoT)
  15. 15Self-consistency
  16. 16Tree of Thoughts (ToT)
  17. 17ReAct (reason & act)
  18. 18Automatic Prompt Engineering
  19. 19Code prompting
  20. 20Prompts for explaining code
  21. 21Prompts for translating code
  22. 22Prompts for debugging and reviewing code
  23. 23What about multimodal prompting?
  24. 24Design with simplicity
  25. 25Be specific about the output
  26. 26Control the max token length
  27. 27Experiment with input formats and writing styles
  28. 28Adapt to model updates
  29. 29JSON Repair
  30. 30Working with Schemas
  31. 31Experiment together with other prompt engineers
  32. 32CoT Best practices
  33. 33Summary
  34. 34Endnotes