AI Wiki
ChatGPT 教程MidJourney 教程Sora 教程
  • 👏Welcome
  • AI Wiki 知识百科
    • 🔎什么是人工智能 (AI)-Google
    • 🔎人工智能-百度百科
    • 🔎人工智能-Wikipedia
    • 📖Artificial Intelligence Wiki (English)
    • 📖机器之心人工智能专业词汇库
    • 📖人工智能专业术语表
      • A
      • B
      • C
      • D
      • E
      • F
      • G
      • H
      • I
      • J
      • K
      • L
      • M
      • N
      • O
      • P
      • Q
      • R
      • S
      • T
      • U
      • V
      • W
      • X
      • Y
      • Z
    • 📖机器学习课程术语表
  • Prompt Engineering 教程
    • 🔔Prompt Engineering 是什么?​
    • 📘Learn Prompting (多语言)
    • 📒Learning Prompt (中文)
    • 📗Learn Prompt (English)
    • 📕Deep Learning (English)
  • ChatGPT 教程
    • 🚩基础篇
      • 如何注册ChatGPT账号
      • Prompt简介
      • 基础用法
      • 基本原则 & 建议
      • 基本使用场景 & 使用技巧
        • 场景1:问答问题
        • 场景2:基于示例回答
        • 场景3:推理
        • 场景4:无中生有——写代码
        • 场景5:锦上添花——改写内容
        • 场景6:锦上添花——信息解释
        • 场景7:化繁为简——信息总结
        • 场景8:化繁为简——信息提取
    • 🏳️‍🌈高级篇
      • ChatGPT Prompt Framework
      • Zero-Shot Prompts
      • Few-Shot Prompting
      • Self-Consistency
      • PAL Models
      • OpenAI Playground 使用方法
      • 搭建基于知识库内容的机器人
    • 🏴‍☠️技巧篇
      • 技巧1:To Do and Not To Do
      • 技巧2:增加示例
      • 技巧3:使用引导词,引导模型输出特定内容
      • 技巧4:增加 Role(角色)或人物
      • 技巧5:使用特殊符号指令和需要处理的文本分开
      • 技巧6:通过格式词阐述需要输出的格式
      • 技巧7:Zero-Shot Chain of Thought
      • 技巧8:Few-Shot Chain of Thought
      • 技巧9:其他
    • 🪧Awesome ChatGPT Prompts (English)
  • Midjourney 教程
    • 🚩基础篇
      • 如何使用 Midjourney?
      • Midjourney Prompt 基本结构
      • Midjourney Prompt 常用参数
      • Midjourney 基础设置
      • 订阅 Midjourney 会员
    • 🏳️‍🌈高级篇
      • Midjourney Prompt 高级参数
      • Midjourney 各版本差异
      • Midjourney 官方 FAQ
    • 🏴‍☠️技巧篇
      • 技巧一:临摹
      • 技巧二:多实验
      • 技巧三:善用 Image2Image 功能
      • 技巧四:增加风格——艺术运动
      • 技巧五:增加风格——艺术家
      • 技巧六:善用 no 参数,去掉不想要的元素
      • 技巧七:多参数同时使用
      • 技巧八:使用 Seed 参数对图进行二次修改
      • 技巧九:神秘的 blend 功能
      • 技巧十:控制变量法渐进优化
      • 技巧十一:增加风格——国家
      • 技巧十二:增加权重
      • 技巧十三:善用灯光
      • 技巧十四:增加风格——年份
      • 技巧十五:如何让 Midjourney 生成的人更具有多样性?
      • 技巧十六:改变相机与镜头
      • 技巧十七:看到别人的图,想知道它的 prompt 是啥
    • 📋Text Prompt 篇
      • 撰写 Text Prompt 注意事项
      • 场景1:Stock Photo
      • 场景2:品牌 Logo
      • 场景3:App & 徽章 Logo
      • 场景4:插画
      • 场景5:头像
      • 场景6:游戏
      • 场景7:实物
      • 场景8:人物
      • 场景9:风景
      • 场景10:动漫
      • 场景11:其他
      • 框架总结
    • 🧮Big List
      • Midjourney 完整参数列表
      • Artist List
      • Photographers List
      • Lighting List
      • Anime List
      • Camera and Lens List
  • Sora 教程
    • 🚩基础篇
      • Sora 基础介绍(中文)
      • Sora 官网介绍(English)
      • 如何申请使用 Sora
      • Sora Prompt提示词合集
      • Sora 学习手册汇总
      • 💰Sora 赚钱方法
    • 🏳️‍🌈高级篇
    • 🏴‍☠️技巧篇
  • 返回Aig123.com
由 GitBook 提供支持
在本页
  1. ChatGPT 教程
  2. 技巧篇

技巧7:Zero-Shot Chain of Thought

上一页技巧6:通过格式词阐述需要输出的格式下一页技巧8:Few-Shot Chain of Thought

最后更新于1年前

基于上述的第三点缺点,研究人员就找到了一个叫 Chain of Thought 的技巧。

这个技巧使用起来非常简单,只需要在问题的结尾里放一句 Let‘s think step by step (让我们一步步地思考),模型输出的答案会更加准确。

这个技巧来自于 Kojima 等人 2022 年的论文 。在论文里提到,当我们向模型提一个逻辑推理问题时,模型返回了一个错误的答案,但如果我们在问题最后加入 Let‘s think step by step 这句话之后,模型就生成了正确的答案:

ZeroShotChainOfThought001.png

论文里有讲到原因,感兴趣的朋友可以去看看,我简单解释下为什么(🆘 如果你有更好的解释,不妨反馈给我):

  1. 首先各位要清楚像 ChatGPT 这类产品,它是一个统计语言模型,本质上是基于过去看到过的所有数据,用统计学意义上的预测结果进行下一步的输出(这也就是为什么你在使用 ChatGPT 的时候,它的答案是一个字一个字地吐出来,而不是直接给你的原因,因为答案是一个字一个字算出来的)。

  2. 当它拿到的数据里有逻辑,它就会通过统计学的方法将这些逻辑找出来,并将这些逻辑呈现给你,让你感觉到它的回答很有逻辑。

  3. 在计算的过程中,模型会进行很多假设运算(不过暂时不知道它是怎么算的)。比如解决某个问题是从 A 到 B 再到 C,中间有很多假设。

  4. 它第一次算出来的答案错误的原因,只是因为它在中间跳过了一些步骤(B)。而让模型一步步地思考,则有助于其按照完整的逻辑链(A > B > C)去运算,而不会跳过某些假设,最后算出正确的答案。

按照论文里的解释,零样本思维链涉及两个补全结果,左侧气泡表示基于提示输出的第一次的结果,右侧气泡表示其收到了第一次结果后,将最开始的提示一起拿去运算,最后得出了正确的答案:

这个技巧,用于解复杂问题有用外,还适合生成一些连贯主题的内容,比如写长篇文章、电影剧本等。

但需要注意其缺点,连贯不代表它就一定不会算错,如果其中某一步骤算错了,错误会因为逻辑链,逐步将错误积累,导致生成的文本可能出现与预期不符的内容。


Let's work this out in a step by step way to be sure we have the right answer.

prompt_2 = f"""
Your task is to perform the following actions:
1 - Summarize the following text delimited by
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text: <{text}>
"""

简单解释下这个代码:

  1. 开头是让 AI 按照 1 ~ 4 步运行

  2. 然后再让 AI 根据特定格式输出内容

最后 AI 的输出是这样的:

Summary: Jack and Jill go on a quest to fetch water, but misfortune strikes and they tumble down the hill, returning home slightly battered but with their adventurous spirits undimmed.
Translation: Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.
Names: Jack, Jill
Output JSON: {"french_summary": "Jack et Jill partent en quête d'eau, mais la malchance frappe et ils dégringolent la colline, rentrant chez eux légèrement meurtris mais avec leurs esprits aventureux intacts.", "num_names": 2}

上述的案例只是将任务拆解,能让 AI 生成的结果更加符合要求,这个方法同样能提升 AI 的回答准确性,比如这个案例:

Determine if the student's solution is correct or not.

Question:
I'm building a solar power installation and I need help working out the financials.

Land costs $100 / square foot

I can buy solar panels for $250 / square foot

I negotiated a contract for maintenance that will cost \
me a flat $100k per year, and an additional $10 / square foot
What is the total cost for the first year of operations
as a function of the number of square feet.

Student's Solution:
Let x be the size of the installation in square feet.
Costs:

Land cost: 100x

Solar panel cost: 250x

Maintenance cost: 100,000 + 100x
Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

AI 的回答是「The student's solution is correct」。但其实学生的答案是错误的,应该 360x + 100,000,我们将 prompt 调整成这样:

prompt = f"""
Your task is to determine if the student's solution \
is correct or not.
To solve the problem do the following:
- First, work out your own solution to the problem.
- Then compare your solution to the student's solution \
and evaluate if the student's solution is correct or not.
Don't decide if the student's solution is correct until
you have done the problem yourself.
Use the following format:
Question:
###
question here
###
Student's solution:
###
student's solution here
###
Actual solution:
###
steps to work out the solution and your solution here
###
Is the student's solution the same as actual solution \
just calculated:
###
yes or no
###
Student grade:
###
correct or incorrect
###
Question:
###
I'm building a solar power installation and I need help \
working out the financials.
- Land costs $100 / square foot
- I can buy solar panels for $250 / square foot
- I negotiated a contract for maintenance that will cost \
  me a flat $100k per year, and an additional $10 / square \
  foot
  What is the total cost for the first year of operations \
  as a function of the number of square feet.
###
Student's solution:
###
Let x be the size of the installation in square feet.
Costs:
1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 100x
   Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000
###
Actual solution:
"""

本质上,也是将任务分拆成多步,这次 AI 输出的结果是这样的(结果就是正确的了):

Let x be the size of the installation in square feet.

Costs:

1. Land cost: 100x
2. Solar panel cost: 250x
3. Maintenance cost: 100,000 + 10x

Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000

Is the student's solution the same as actual solution just calculated:
No

Student grade:
Incorrect

ZeroShotChainOfThought002.png

另外,根据 Wei 等人在 表明,还有它仅在大于等于 100B 参数的模型中使用才会有效。如果你使用的是小样本模型,这个方法不会生效。

2023-04-12 更新(感谢分享): 根据 Yongchao Zhou 等人的,更好的 prompt 是:

在吴恩达的 ChatGPT Prompt Engineering 中,有提到一个这个技巧的另一种用法,不仅仅只是让 AI 按步骤行事,还会告知 AI 每一步要做什么。比如这个案例(注意这个是 python 代码):

🏴‍☠️
2022 年的论文
qq-740943515
最新论文
课程
Large Language Models are Zero-Shot Reasoners