Zubnet AI学习Wiki › Few-Shot 学习ing
Using AI

Few-Shot 学习ing

Few-Shot Prompting, One-Shot, In-Context 学习ing
在你的 prompt 里提供几对 input-output 示例,教模型一个模式、格式或行为。“Zero-shot”意思是没有例子(只有指令)。“One-shot”是一个例子。“Few-shot”通常是 2–10 个例子。模型从你的例子里学到模式,应用到实际输入上,不需要任何训练或 fine-tuning。

为什么重要

Few-shot prompting 是定制模型行为最快、最便宜的办法。要一致的 JSON 输出?给三个例子。要特定写作风格?包含两个样本。它有效是因为 LLM 是超凡的模式匹配器 — 它们从例子里推断规则并泛化。这常被叫做“in-context learning”,是规模化带来的最令人惊讶的能力之一。

Deep Dive

The original GPT-3 paper (Brown et al., 2020) demonstrated that large language models could perform tasks they were never explicitly trained on, simply by being shown a few examples in the prompt. A model trained only to predict text could suddenly do translation, arithmetic, and classification with just 3–5 examples. This was the finding that launched the modern era of prompt engineering.

How Many Examples?

The optimal number of examples depends on the task complexity and the model. For simple formatting tasks (convert name to "Last, First"), 2–3 examples usually suffice. For nuanced classification with edge cases, 5–10 examples may be needed. Beyond ~10 examples, you're often better off fine-tuning. More examples also consume context window, so there's a practical trade-off between example quality and available space for the actual input.

Example Selection Matters

The examples you choose affect performance dramatically. Diverse examples that cover edge cases outperform repetitive ones. Examples that are similar to the target input outperform generic ones. The order of examples can matter too — models sometimes show recency bias, paying more attention to the last example. When building few-shot systems in production, dynamically selecting the most relevant examples for each input (using embedding similarity) outperforms static example sets.

相关概念

← 所有术语
← Feedforward Network Fine-tuning →