🤖

効果的なプロンプトデザイン! ChatGPTを最大限に活用するための秘訣とテクニック集

2023/04/08に公開

この記事を読むとどうなる?

この記事のテクニックを試すことで、より信頼性が高く、パフォーマンスの高いプロンプトを構築することができます。

複雑なタスクの信頼性を向上させる方法

この記事では、複雑なタスクにおける大規模言語モデルの信頼性を向上させるための以下のようなテクニックを紹介しています。

  • より明確な指示を与える
  • 複雑なタスクをよりシンプルなサブタスクに分割する
  • モデルがタスクに集中できるようなインストラクションを構成する
  • 回答する前に、モデルに説明を促す
  • 多くの可能性のある答えに対して正当性を求め、総合的に判断する
  • 多くの出力を生成し、モデルを使って最適なものを選ぶ
  • カスタムモデルを微調整し、パフォーマンスを最大化

複雑なタスクをよりシンプルなタスクに分割する

要約

  • タスクはできるだけシンプルにすること。
  • タスクはできるだけ小さく分割すること。
  • タスクを実行する計画のヒントを与えること。

この三点が大事そうです。こうすることで、モデルが各サブタスクに集中しやすくなりより高精度な回答を導きだすことができるようです。

詳細

このドキュメントは、複雑なタスクをよりシンプルなタスクに分割する方法について説明しています。

例として、多肢選択式の質問を投げかけるとChatGPTは誤った回答をしています。

Use the following clues to answer the following multiple-choice question.
 
Clues:
1. Miss Scarlett was the only person in the lounge.
2. The person with the pipe was in the kitchen.
3. Colonel Mustard was the only person in the observatory.
4. Professor Plum was not in the library nor the billiard room.
5. The person with the candlestick was in the observatory.
 
Question: Was Colonel Mustard in the observatory with the candlestick?
(a) Yes; Colonel Mustard was in the observatory with the candlestick
(b) No; Colonel Mustard was not in the observatory with the candlestick
(c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick
 
Solution:
(c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick

そこで、解く際にヒントを与えると、関連する手がかりを組み合わせて、最終的な答えを導き出すことに成功しています。

Use the following clues to answer the following multiple-choice question, using the following procedure:
(1) First, go through the clues one by one and consider whether the clue is potentially relevant
(2) Second, combine the relevant clues to reason out the answer to the question
(3) Third, map the answer to one of the multiple choice answers: either (a), (b), or (c)
 
Clues:
1. Miss Scarlett was the only person in the lounge.
2. The person with the pipe was in the kitchen.
3. Colonel Mustard was the only person in the observatory.
4. Professor Plum was not in the library nor the billiard room.
5. The person with the candlestick was in the observatory.
 
Question: Was Colonel Mustard in the observatory with the candlestick?
(a) Yes; Colonel Mustard was in the observatory with the candlestick
(b) No; Colonel Mustard was not in the observatory with the candlestick
(c) Unknown; there is not enough information to determine whether Colonel Mustard was in the observatory with the candlestick
 
Solution:
(1) First, go through the clues one by one and consider whether the clue is potentially relevant:
Clue 1: Miss Scarlett was the only person in the lounge. This clue is not relevant.
Clue 2: The person with the pipe was in the kitchen. This clue is not relevant.
Clue 3: Colonel Mustard was the only person in the observatory. This clue is relevant.
Clue 4: Professor Plum was not in the library nor the billiard room. This clue is not relevant.
Clue 5: The person with the candlestick was in the observatory. This clue is relevant.
 
(2) Second, combine the relevant clues to reason out the answer to the question:
Clue 3 and Clue 5 both say that the person with the candlestick was in the observatory. Colonel Mustard was the only person in the observatory, so Colonel Mustard was the person with the candlestick.
 
(3) Third, write the final answer:
(a) Yes; Colonel Mustard was in the observatory with the candlestick

答える前にモデルに説明を促す

答えの信頼性を高めるもう一つの強力なテクニックは、最終的な答えにすぐに飛びつくのではなく、徐々に答えを導き出すようモデルに促すことです。

Zero-shot

この手法のコツ

  • 推論問題かどうかをまず確認すること
  • Let's think step by stepキーワードを含めること
  • タスクの複雑度に応じて、例題を与えるなど命令をカスタマイズすること

まずはLet's think step by stepキーワードを含めることから始めて徐々に命令文をカスタマイズしていくとうまくいきそうです!

詳細

このドキュメントは、小島武 氏らによって発表された、数学データセットにおいてLet's think step by stepというフレーズを使うことで、4倍の精度向上が見られた ことを報告しています。


zero-shot reasoning example
引用: Large Language Models are Zero-Shot Reasoners by Takeshi Kojima et al. (2022).

ただし、このテクニックは推論問題に限定され、単純な計算問題や常識的な問題には効果がないとされています。

また、Let's think step by stepキーワードを含めるのみではなく、例題の形式を与えるなどカスタマイズされた命令の方が、より良いパフォーマンスが得られる可能性があるとされています。

Using the IRS guidance below, answer the following questions using this format:
(1) For each criterion, determine whether it is met by the vehicle purchase
- {Criterion} Let's think step by step. {explanation} {yes or no, or if the question does not apply then N/A}.
(2) After considering each criterion in turn, phrase the final answer as "Because of {reasons}, the answer is likely {yes or no}."

IRS guidance:
"""
You may be eligible for a federal tax credit under Section 30D if you purchased a car or truck that meets the following criteria:
- Does the vehicle have at least four wheels?
- Does the vehicle weigh less than 14,000 pounds?
- Does the vehicle draw energy from a battery with at least 4 kilowatt hours that may be recharged from an external source?
- Was the vehicle purchased in a year before 2022?
  - If so, has the manufacturer sold less than 200,000 qualifying vehicles? (Tesla and GM have sold more than 200,000 qualifying vehicles.)
- Was the vehicle purchased in a year after 2022?
  - If so, is the vehicle present in the following list of North American-assembled vehicles? (The only electric vehicles assembled in North America are the Audi Q5, BMW 330e, BMW X5, Chevrolet Bolt EUV, Chevrolet Bolt EV, Chrysler Pacifica PHEV, Ford Escape PHEV, Ford F Series, Ford Mustang MACH E, Ford Transit Van, GMC Hummer Pickup, GMC Hummer SUV, Jeep Grand Cherokee PHEV, Jeep Wrangler PHEV, Lincoln Aviator PHEV, Lincoln Corsair Plug-in, Lucid Air, Nissan Leaf, Rivian EDV, Rivian R1S, Rivian R1T, Tesla Model 3, Tesla Model S, Tesla Model X, Tesla Model Y, Volvo S60, BMW 330e, Bolt EV, Cadillac Lyriq, Mercedes EQS SUV, and Nissan Leaf.)
"""

Question: Can I claim a federal tax credit for my Toyota Prius Prime bought in 2021?

Solution:

(1) For each criterion, determine whether it is met by the vehicle purchase
- Does the vehicle have at least four wheels? Let's think step by step.

The Toyota Prius Prime has four wheels, so the answer is yes.
- Does the vehicle weigh less than 14,000 pounds? Let's think step by step. The Toyota Prius Prime weighs less than 14,000 pounds, so the answer is yes.
- Does the vehicle draw energy from a battery with at least 4 kilowatt hours that may be recharged from an external source? Let's think step by step. The Toyota Prius Prime has a battery with at least 4 kilowatt hours that may be recharged from an external source, so the answer is yes.
- Was the vehicle purchased in a year before 2022? Let's think step by step. The Toyota Prius Prime was purchased in 2021, which is before 2022, so the answer is yes.
- Was the vehicle purchased in a year after 2022? N/A
- If so, is the vehicle present in the following list of North American-assembled vehicles? N/A

(2) After considering each criterion in turn, phrase the final answer as "Because of {reasons}, the answer is likely {yes or no}."

Because the Toyota Prius Prime meets all of the criteria for a federal tax credit, the answer is likely yes.

引用:Techniques to improve reliability

Few-shot examples

この手法のコツ

  • 答えの種類(ラベル空間)と、出題される文章(入力テキストの分布)をしっかり考えること。
    • それぞれの文章に正しい答えがあるかどうかよりも、全体の答えの種類と文章の種類が大事。
  • フォーマットを整えること。
    • たとえば、ランダムなラベルを使用しても、まったくラベルがないよりはるかに良い結果が得られます。
    • 正しいラベルの分布からランダムに選ぶことが、モデルの性能向上に効果的であることが実験によって示されています。

モデルが最初に正しい方法で推論していなかったり、浅い推論が行われている場合の対処法と考えておくと良さそうですね!

Let's think step by stepキーワードを含める手法と比較した利点

*  最終的な答えにたどり着くまでにモデルに実行させたい推論の形式や長さ、スタイルをより簡単に指定できること。

詳細

GoogleのJason WeiとDenny Zhouらが行った研究によると、数回の思考連鎖を促すことで、モデルに答えを導き出すことができます。
この手法は、数学の問題だけでなく、スポーツの理解やコインフリップの追跡など、さまざまな問題に適用できるとしています。


引用: Chain of Thought Prompting Elicits Reasoning in Large Language Models Jason Wei and Denny Zhou et al. (2022)

Fine-tuned

この手法のコツ

使いこなせていないので知見が溜まったら更新予定・・・

詳細

このドキュメントは、Eric ZelikmanとYuhuai Wuらが発表したSTaRと呼ばれる手順について述べています。この手順は、数発のプロンプトを使用して、モデルの微調整に使える説明のデータセットを生成する方法です。

この手順を使用することで、何千もの説明例を書く必要がなく、finetuningの利点とchain-of-thought promptingの利点を組み合わせることができます。


引用: STaR: Bootstrapping Reasoning With Reasoning by Eric Zelikman and Yujuai Wu et al. (2022)

数発のプロンプトを使用して、微調整用のデータセットを拡張または修正することは、説明文の作成以外にも一般化できるアイデアです。

例えば、大量の非構造化テキストを学習したい場合、プロンプトを使って非構造化テキストから構造化データセットを抽出し、その構造化データセットでカスタムモデルを微調整するなども可能だと言えます。

また、STaRはCommon Sense Q&Aデータセットに適用され、思考連鎖プロンプトのみを使用する場合でも、finetuningのみを使用する場合よりも優れた結果を示しました。

引用: STaR: Bootstrapping Reasoning With Reasoning by Eric Zelikman and Yujuai Wu et al. (2022)

参考

Discussion