少样本提示

term_id: few_shot_prompting

Category: application_paradigms

Definition

这种方法利用大型语言模型的上下文学习能力,直接在提示词中提供几个说明性示例。与需要更新模型权重的微调不同,少样本提示通过展示期望的输出格式或逻辑,让模型在不重新训练的情况下适应新任务。

Summary

少样本提示是一种技术,通过在提示词中提供少量输入-输出示例来引导大型语言模型的行为。

Key Concepts

  • 上下文学习
  • 提示工程
  • 基于示例的引导
  • 零样本对比

Use Cases

  • 情感分析格式化
  • 代码风格适配
  • 结构化数据提取

Code Example

1
2
3
4
5
6
response = llm.generate(
    prompt="Translate English to French:\n"
           "Hello -> Bonjour\n"
           "World -> Monde\n"
           "Cat -> ?"
)