示例提示(Shot Prompting)

使用 OpenAI API

James Chapman

Curriculum Manager, DataCamp

提供示例

一个机器人在查看示例

  • 示例提示(Shot Prompting)
使用 OpenAI API

什么是示例提示?

示例提示(Shot Prompting):用示例引导模型回答

$$

  • 零示例(Zero-shot):仅给指令,无示例
  • 单一示例(One-shot):用1个示例引导回答
  • 少量示例(Few-shot):多个示例提供更多上下文

从零到少量示例的示意

使用 OpenAI API

为什么示例提示很重要?

$$

✅ 示例提示的用途:

  • 📑 文本分类
  • 💬 情感分析
  • 🔍 数据抽取
  • ✨ 等等!

示例提示的用例

使用 OpenAI API

零示例提示(Zero-shot)

prompt = """Classify sentiment as 1-5 (bad-good) in the following statements:
1. Meal was decent, but I've had better.
2. My food was delayed, but drinks were good.
"""

...
1. Meal was decent, but I've had better. - 3 (Neutral)
2. My food was delayed, but drinks were good. - 3 (Neutral)
使用 OpenAI API

单一示例提示(One-shot)

prompt = """Classify sentiment as 1-5 (bad-good) in the following statements:
1. The service was very slow -> 1
2. Meal was decent, but I've had better. ->
3. My food was delayed, but drinks were good. ->
"""
1. The service was very slow -> 1
2. Meal was decent, but I've had better. -> 3
3. My food was delayed, but drinks were good. -> 4
使用 OpenAI API

少量示例提示(Few-shot)

prompt = """Classify sentiment as 1-5 (bad-good) in the following statements:
1. The service was very slow -> 1
2. The steak was awfully good! -> 5
3. It was ok, no massive complaints. -> 3
4. Meal was decent, but I've had better. ->
5. My food was delayed, but drinks were good. ->
"""
1. The service was very slow -> 1
2. The steak was awfully good! -> 5
3. It was ok, no massive complaints. -> 3
4. Meal was decent, but I've had better. -> 4
5. My food was delayed, but drinks were good. -> 3
使用 OpenAI API

通用分类

prompt = """Classify the following animals as Land, Sea, or Both:
1. Blue whale
2. Polar bear
3. Salmon
4. Dog
"""
1. **Blue whale** - Sea
2. **Polar bear** - Both (primarily land but is a marine mammal that lives in sea ice)
3. **Salmon** - Both (spends part of its life in freshwater and part in the ocean)
4. **Dog** - Land
使用 OpenAI API
prompt = """Classify the following animals as Land, Sea, or Both:
1. Zebra = Land
2. Crocodile = Both
3. Blue whale = 
4. Polar bear = 
5. Salmon = 
6. Dog = 
"""
1. Zebra = Land
2. Crocodile = Both
3. Blue whale = Sea
4. Polar bear = Both
5. Salmon = Sea
6. Dog = Land
使用 OpenAI API

Vamos praticar!

使用 OpenAI API

Preparing Video For Download...