返回文章列表

【ai】关于提示词工程


Zero-shot

零样本学习,不给例子直接干。

假设模型对某个新东西完全不认识,但可以在已知训练数据中提取相关特性。经典的例子是只告诉模型把下面评论分类为好评/差评,却不教它什么叫好评,什么叫差评。模型靠预训练中学到的"分类任务"模式直接执行——这就是 Zero-shot。

这个概念通常用于表达大模型相较于传统机器学习的核心优势。因为大模型语料足够多,人类所见的种种任务形式基本它都了解,并学到了常见任务的处理模式,所以可以无需额外训练,直接输出较完善的结果。

但复杂推理、格式精准控制、领域知识很深的场景,往往需要 few-shot 甚至 fine-tuning。

Few-shot

少样本学习。通过提示词给几个例子,让模型照猫画虎

通常用在格式要求精细的任务,比如输出精确格式的json。

也可以用在任务定义模糊的场景,比如让大模型总结文章,它不知道你想要的“总结”具体指什么。你可以通过附带一些例子来教它。例子在精不在多,3个左右就够。例子的多样性大于数量。

Fine-tuning

前两者是提示词工程范畴,Fine-tuning则是指用准备的数据再训练一轮,更新模型参数,从而提高大模型在某些领域的性能。指令微调的数据量通常在500-5000。

一般用于格式/风格控制极严或者领域知识很窄很深的场景。

也可用于降低模型推理成本——微调后的小模型替代大模型调用,成本降低 10-100x。


Zero-shot

Zero-shot learning — give it a task with no examples and let it go.

The model doesn't need to be retrained for every specific task, because it has already learned the patterns of countless task formats from its pretraining corpus. The classic example: you tell the model "classify this review as positive or negative" without teaching it what "positive" or "negative" even means. The model draws on classification patterns it learned during pretraining and executes directly — that's Zero-shot.

This is the core advantage LLMs hold over traditional machine learning. With enough pretraining data, the model has seen virtually every task format humans can describe and has internalized common task patterns, so it can deliver solid results with zero additional training.

That said, complex reasoning, strict format control, and deep domain knowledge often require Few-shot or even Fine-tuning.

Few-shot

Few-shot learning — give the model a handful of examples via the prompt and let it follow the pattern.

Commonly used for tasks demanding precise output formatting, like producing exact JSON schemas.

Also useful when the task definition is ambiguous. If you ask the model to "summarize an article," it has no idea what kind of summary you want. A few examples teach it. Examples should be quality over quantity — around three is usually enough. Diversity among examples matters more than raw count.

Fine-tuning

Zero-shot and Few-shot fall under prompt engineering. Fine-tuning is different: you take a prepared dataset and run another round of training, actually updating the model's parameters to boost performance in specific domains. For instruction fine-tuning, datasets typically range from 500 to 5,000 examples.

Fine-tuning is generally reserved for situations demanding extremely tight format or style control, or domains with deep, narrow expertise.

It's also used to slash inference costs — swapping a large model call for a fine-tuned small model can cut costs by 10 to 100 times.