零样本与少样本提示
掌握无需示例(零样本)或仅需少量示例(少样本)即可引导模型产生预期行为的提示技术。
零样本与少样本提示 是 CoddyKit 上的免费 Prompt Engineering & LLM Optimization for Developers 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Prompt Engineering & LLM Optimization for Developers 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Prompt Engineering & LLM Optimization for Developers 课程共包含 4 节课。
本课时的部分内容尚未翻译,以英文显示。
Guiding LLMs with Examples
LLMs often need guidance. With zero-shot you give the task and no examples; with few-shot you include a few examples to show what you expect.
Zero-shot: Relying on Knowledge
Zero-shot prompting gives a task with no examples - the model leans entirely on its pre-trained knowledge. Efficient, and great for common, straightforward tasks.
Zero-shot in Action: Summarization
Here's a zero-shot summarization prompt: no example summaries, just the task. The model relies on its general grasp of summarizing.
Summarize the following text in one sentence:
"The quick brown fox jumped over the lazy dog. This action demonstrated the fox's agility and the dog's relaxed nature. It was a sunny afternoon, perfect for such playful antics."Zero-shot: Sentiment Analysis
Zero-shot shines for sentiment analysis too - just name the task and the model classifies it. Perfect for quick checks without specialized categories.
Classify the sentiment of the following product review as Positive, Negative, or Neutral:
"The battery life is terrible, but the camera is surprisingly good."When Zero-shot Falls Short
Zero-shot has limits: custom output formats, multi-step reasoning, ambiguous tasks, and consistency across queries can all trip it up. That's where few-shot helps.
Few-shot: Learning from Examples
Few-shot prompting includes a few input-output examples right in the prompt. They demonstrate the pattern, style, or format, boosting accuracy on tricky tasks.
Structuring Few-shot Prompts
A few-shot prompt is: instruction, a couple of input/output examples, then your new input. Keep examples clear, concise, and representative.
Instruction:
Input: Example 1 Input
Output: Example 1 Output
Input: Example 2 Input
Output: Example 2 Output
Input: Your New Input
Output:Few-shot in Action: Structured Output
Want JSON output? Few-shot nails it - the examples below pin down the exact structure for sentiment and confidence, so the model copies the shape.
Classify the sentiment of the following reviews and output as JSON:
Review: "This movie was fantastic!"
Output: {"sentiment": "Positive", "confidence": "High"}
Review: "I didn't like it at all."
Output: {"sentiment": "Negative", "confidence": "High"}
Review: "It was okay, nothing special."
Output: {"sentiment": "Neutral", "confidence": "Medium"}
Review: "The product worked sometimes, but often failed."
Output:Few-shot: Consistent Tone & Style
Few-shot is ideal for tone and style: hard to describe "quirky," easy to show. These examples teach the model a short, punchy headline voice.
Rephrase the following sentences into a short, catchy, and slightly quirky headline:
Original: "A group of scientists discovered a new species of glowing mushroom in the Amazon rainforest."
Headline: "Amazon Glow-Shroom Shines!"
Original: "The city council decided to ban plastic bags to protect the environment."
Headline: "Bag the Bags: City Goes Green!"
Original: "A new study suggests that eating chocolate can improve your mood."
Headline:Zero-shot vs. Few-shot: Choosing Your Tool
Choosing: zero-shot for simple, common tasks and lower cost; few-shot for specific formats, niche knowledge, and when consistency really matters.
Quick Check on Prompting
You need an LLM to extract specific data from customer reviews (e.g., product name, issue type, suggested improvement) and output it as a structured JSON object. Which prompting technique would be most effective?
Recap: Master Your Prompts!
Recap: zero-shot is quick and efficient for general tasks; few-shot uses examples to lift accuracy and consistency on complex ones. Match the tool to the job.
常见问题解答
「零样本与少样本提示」课时是免费的吗?
是的 — 「零样本与少样本提示」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Prompt Engineering & LLM Optimization for Developers 课程的其余内容,请升级到 CoddyKit PRO。 Prompt Engineering & LLM Optimization for Developers 课程共包含 4 节课。
「零样本与少样本提示」这节课中我会学到什么?
掌握无需示例(零样本)或仅需少量示例(少样本)即可引导模型产生预期行为的提示技术。 你通过在浏览器中直接运行的动手代码来练习 Prompt Engineering & LLM Optimization for Developers,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 Prompt Engineering & LLM Optimization for Developers 需要有经验吗?
无需任何先前经验。CoddyKit 上的 Prompt Engineering & LLM Optimization for Developers 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。
「零样本与少样本提示」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 Prompt Engineering & LLM Optimization for Developers 课中编写并运行代码吗?
能。每节 Prompt Engineering & LLM Optimization for Developers 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。
此课程中的所有课时
- LLM 与提示词简介
- 提示词的基本结构
- 零样本与少样本提示
- 常见的提示词问题及其规避方法