跳到主要内容Skip to main content

few-shot 示例怎么选How to Pick Few-Shot Examples

微型指南 · 约 6 分钟Guide · about 6 min · 引用核验 2026-11-03(仅引用链接与日期) · refs checked 2026-11-03 (reference links and dates only)

在提示里放几个「输入→输出」例子能明显改变表现,但例子选得不好反而带偏。这篇讲选例子的五条标准。Dropping a few input→output examples into the prompt changes performance noticeably — but bad examples steer the model the wrong way. Five criteria for picking them.

怎么做How to

例子覆盖你要的边界情况,而不是只放最简单的:模型会模仿例子的分布。

格式与真实输入完全一致:示例里的字段名、标点、换行都会被照抄。

数量从两三个起步,边际收益递减快;塞太多还挤占上下文、拉高成本。

示例之间要有差异:三个几乎一样的例子等于一个,还让模型以为只会这一种。

遇到输出跑偏,先检查是不是某个示例在带节奏——错误示例比没有示例更糟。

Cover the edge cases you actually need, not just the easy ones: the model imitates the distribution of your examples.

Keep the format identical to real inputs: field names, punctuation, and line breaks in the examples get copied verbatim.

Start with two or three examples; marginal returns drop fast, and too many crowd the context and raise cost.

Make examples differ from each other: three near-identical ones are worth one, and they teach the model it can only do that one thing.

When outputs go off the rails, first check whether an example is steering them — a wrong example is worse than no example.

例子与判断Example and interpretation

以下是教学情境,不是本站运行或实测记录。A teaching scenario, not a measured or executed site test.

做情绪分类时,除了明显好评和差评,还放一条“东西不错,但送晚了”的混合评价,并写清处理规则。示例的作用是说明边界;不要把测试题原样放进示例,再把测试结果当作泛化能力。For sentiment classification, include a mixed review such as “Good item, late delivery” alongside clear positives and negatives, with a labeling rule. Examples explain boundaries; copying test items into them does not demonstrate generalization.

出处Sources
  • Brown 等《Language Models are Few-Shot Learners》(GPT-3 论文)Brown et al., Language Models are Few-Shot Learners (GPT-3) ↗
  • Wei 等《Finetuned Language Models Are Zero-Shot Learners》(FLAN)Wei et al., Finetuned Language Models Are Zero-Shot Learners (FLAN) ↗
  • Wang 等《Self-Instruct: Aligning Language Models with Self-Generated Instructions》Wang et al., Self-Instruct ↗