Gemini : ガイド : プロンプト設計ストラテジー (1)
作成 : クラスキャット セールスインフォメーション
作成日時 : 04/21/2024
* 本ページは、ai.google.dev の以下のページを独自に翻訳して、適宜、補足説明したものです :
* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。
- 人工知能研究開発支援
- 人工知能研修サービス(経営者層向けオンサイト研修)
- テクニカルコンサルティングサービス
- 実証実験(プロトタイプ構築)
- アプリケーションへの実装
- 人工知能研修サービス
- PoC(概念実証)を失敗させないための支援
- お住まいの地域に関係なく Web ブラウザからご参加頂けます。事前登録 が必要ですのでご注意ください。
◆ お問合せ : 本件に関するお問い合わせ先は下記までお願いいたします。
- クラスキャット セールス・マーケティング本部 セールス・インフォメーション
- sales-info@classcat.com ; Website: www.classcat.com ; ClassCatJP
Gemini : ガイド : プロンプト設計ストラテジー (1)
このページは、プロンプトを設計するときに採用できる、幾つかの一般的なプロンプト設計ストラテジーを説明します。プロンプトを設計する正しい、または間違っている方法はありませんが、モデルの応答に影響を与えるために使用できる一般的なストラテジーはあります。モデル性能を最適化するためには厳しいテストと評価は依然として重要です。
大規模言語モデル (LLM) は言語のユニット間のパターンや関係性を学習するために膨大なテキストデータで訓練されます。あるテキスト (プロンプト) が与えられたとき、言語モデルは、洗練された自動コンプリートツールのように、次に何が来る尤度が高いかを予測することができます。従って、プロンプトを設計するとき、モデルが次に何がくるかを予測するのに影響を与える可能性がある様々な要因を考慮してください。
1. 明瞭で具体的な指示を与える
モデルに何を行なうべきかの指示を与えることはモデル動作をカスタマイズするための効果的で効率的な方法です。与える指示は明瞭で具体的であることを確実にしてください。指示はステップ毎の指示のリストのように単純であったり、ユーザの体験と考え方 (mindset) を精密に示すような複雑である可能性があります。
実行するタスクの定義
モデルに実行して欲しいタスクを詳細に記述します。タスクはステップ毎の指示のリストのように単純であったり、ユーザの体験と考え方 (mindset) を精密に示すような複雑である可能性があります。次のプロンプトはモデルにテキストブロックを要約するように伝えています :
プロンプト :
Summarize this text.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
応答 :
Quantum computers utilize quantum mechanical phenomena to perform computations significantly faster
than traditional computers. By exploiting the particle-wave duality of matter at tiny scales,
quantum computers leverage specialized hardware to solve problems beyond classical physics.
Potential applications include breaking encryption, developing better weather forecasting, and more.
However, current quantum computers are still largely experimental and impractical.
任意の制約の指定
プロンプトを読んだり応答を生成する際の制約を指定します。モデルに何をすべきか、何をするべきでないかを指示することができます。前の例から、要約は元のテキストより短いですが、多分要約は更に短いものを望むでしょう。この場合、要約がどのくらいの長さであることを望むかの制約をプロンプトで指定できます :
プロンプト :
Summarize this text in two sentences.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
応答 :
Quantum computers use quantum mechanical phenomena to perform calculations much faster than
traditional computers. They have the potential to revolutionize various fields, but current quantum
computers are still experimental and impractical.
応答の形式を定義する
応答の形式を指定する指示を与えることもできます。例えば、表、箇条書き、エレベーターピッチ、キーワード、センテンス、あるいは段落としてフォーマットされた応答を求めることができます。次のプロンプトはモデルにテキストの主要な情報の箇条書きを与えるように指示しています :
プロンプト :
Summarize this text as bullets points of key information.
Text: A quantum computer exploits quantum mechanical phenomena to perform calculations exponentially
faster than any modern traditional computer. At very tiny scales, physical matter acts as both
particles and as waves, and quantum computing uses specialized hardware to leverage this behavior.
The operating principles of quantum devices is beyond the scope of classical physics. When deployed
at scale, quantum computers could be used in a wide variety of applications such as: in
cybersecurity to break existing encryption methods while helping researchers create new ones, in
meteorology to develop better weather forecasting etc. However, the current state of the art quantum
computers are still largely experimental and impractical.
応答 :
- Quantum computers leverage quantum mechanical phenomena for exponentially faster calculations than
traditional computers.
- Quantum devices utilize specialized hardware to exploit tiny-scale matter behavior as both
particles and waves.
- Their operating principles transcend classical physics.
- Potential applications include cybersecurity, weather forecasting, and more.
- Current quantum computers are largely experimental and impractical.
要約
- モデルに何をするべきか指示を与える。
- 指示は明瞭に具体的に。
- 出力についての制約やフォーマット要件を指定する。
2. few-ショットサンプルを含める
正しいものはどのようなものかモデルに示すサンプルをプロンプトに含めることができます。モデルはサンプルからパターンと関係性を識別しようとし、応答を生成する際にそれらを適用します。少数のサンプルを含むプロンプトは few-ショットプロンプトと呼ばれ、サンプルを提供しないプロンプトをゼロショットプロンプトと呼びます。few-ショットプロンプトはモデル応答のフォーマット、フレーズ、範囲、あるいは一般的なパターンを規定するために使用される場合が多いです。具体的で多様なサンプルを使用して、モデルがそのフォーカスを絞ったりより正確な結果を生成するのに役立てます。
プロンプトに常に few-ショットサンプルを含めることを勧めます。few-ショットサンプルなしのプロンプトは効果的でない傾向にあります、何故ならばそれらはモデルに指示を適用する方法を示すからです。実際、サンプルが手元のタスクを示すのに十分に明瞭である場合、プロンプトから指示を取り除くことができます。
ゼロショット vs few-ショット・プロンプト
次のゼロショット・プロンプトはモデルにベストな説明を選択することを求めています。
プロンプト :
Please choose the best explanation to the question:
Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:
応答 :
Explanation1
ユースケースがモデルに簡潔な応答を生成することを要求する場合、プロンプトに簡潔な応答を優先するサンプルを含めることができます。
次のプロンプトは短い説明への優先を示す 2 つのサンプルを提供しています。応答では、サンプルが、前に行ったような長い説明 (Explanation1) ではなく、短い説明 (Explanation2) を選択するようにモデルを誘導したことがわかります。
プロンプト :
Please choose the best explanation to the question:
Question: Why is sky blue?
Explanation1: The sky appears blue because of Rayleigh scattering, which causes shorter blue
wavelengths of light to be scattered more easily than longer red wavelengths, making the sky look
blue.
Explanation2: Due to Rayleigh scattering effect.
Answer: Explanation2
Question: What is the cause of earthquakes?
Explanation1: Sudden release of energy in the Earth's crust.
Explanation2: Earthquakes happen when tectonic plates suddenly slip or break apart, causing a
release of energy that creates seismic waves that can shake the ground and cause damage.
Answer: Explanation1
Question: How is snow formed?
Explanation1: Snow is formed when water vapor in the air freezes into ice crystals in the
atmosphere, which can combine and grow into snowflakes as they fall through the atmosphere and
accumulate on the ground.
Explanation2: Water vapor freezes into ice crystals forming snow.
Answer:
応答 :
Explanation2
最適なサンプル数を見つける
最も望ましい結果のためにプロンプトで提供するサンプル数を実験できます。PaLM や Gemini のようなモデルは少数のサンプルを使用してパターンに気づける場合が多いですが、幾つのサンプルが望ましい結果に繋がるかは実験する必要があるかもしれません。BERT のようなより単純なモデルについては、より多くのサンプルが必要かもしれません。同時に、多すぎるサンプルを含める場合、モデルはサンプルへの応答に 過剰適合 し始める可能性があります。
サンプルを使用してアンチパターンの代わりにパターンを示す
モデルに従うべきパターンを示すためにサンプルを使用することは、モデルに回避すべきアンチパターンを示すためにサンプルを使用するよりも効果的です。
⛔ ネガティブパターン :
サンプル :
Don't end haikus with a question:
Haiku are fun
A short and simple poem
Don't you enjoy them?
✅ ポジティブパターン :
プロンプト :
Always end haikus with an assertion:
Haiku are fun
A short and simple poem
A joy to write
サンプル全体で一貫した形式を使用する
望まない形式の応答を避けるため、few-ショットサンプルの構造と形式は同じであることを確実にしてください。プロンプトで few-ショットサンプルを追加することの主要な目的の一つは、モデルに応答形式を示すことです。そのため、すべてのサンプル全体で一貫した形式を保証することは重要です、特に XML タグ、ホワイトスペース、改行、そしてサンプルのスプリッターには注意を払ってください。
要約
- プロンプトにプロンプト-応答のサンプルを含めることはモデルが応答する方法を学習するのに役立ちます。
- 避けるべきパターンの例の代わりに従うべきパターンの例をモデルに与えます。
- 含めるプロンプト数で実験してください。モデルに依存して、少なすぎるサンプルはモデルの動作を変化させるには効果的ではありません。多すぎるサンプルはモデルの過剰適合を引き起こします。
- サンプル全体で一貫した形式を使用してください。
3. コンテキスト情報の追加
モデルが必要な情報のすべてを持つと仮定するのではなく、モデルが問題を解くために必要な指示や情報をプロンプトに含めることができます。このコンテキスト情報は、モデルに実行を要求しているものの制約や詳細をモデルが理解するのに役立ちます。
次のサンプルは、モデルにルータについてのトラブルシューティングのガイダンスを提供することを要求しています :
プロンプト :
What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and
blinking slowly.
応答 :
1. **Check the Cables:**
- Make sure that all cables are securely connected to your Google Wifi router and modem.
- Try replacing the cables with new ones to ensure they are not faulty.
2. **Reboot the Router:**
- Unplug your Google Wifi router and modem from the power outlet.
- Wait for at least 30 seconds.
- Plug the modem and router back in and wait for them to start up.
3. **Factory Reset the Router:**
- Resetting the router will restore it to its default settings.
- Find the small reset button on the back of the router.
- Press and hold the reset button with a paper clip or similar object for 10 seconds.
- Release the button and wait for the router to restart.
4. **Check Your Internet Connection:**
- Use a wired connection to connect a device directly to your modem.
- If the internet works, the issue may be with your router.
- If the internet still doesn't work, contact your Internet Service Provider (ISP).
5. **Update Router's Firmware:**
- Check if there is a firmware update available for your Google Wifi router.
- Download and install the latest firmware update from the Google Wifi app.
6. **Interference and Obstacles:**
- Make sure the router is not near electronic devices that can cause interference, like microwaves or cordless phones.
- Remove any obstacles between the router and your devices, such as furniture or thick walls.
7. **Change Wi-Fi Channel:**
- In the Google Wifi app, go to Settings > Network & General > Advanced Networking.
- Try changing the Wi-Fi channel to a less congested one.
8. **Contact Google Support:**
- If you've tried the above steps and the issue persists, contact Google support for further assistance.
応答は、ルータや LED インジケータのライトの状態に固有なものではない、一般的なトラブルシューティングの情報のようです。
特定のルータに対して応答をカスタマイズするために、ルーターのトラブルシューティング・ガイドを応答を提供する際の参照コンテキストとしてプロンプトに追加することができます。
プロンプト :
Answer the question using the text below. Respond with only the text provided.
Question: What should I do to fix my disconnected wifi? The light on my Google Wifi router is yellow and blinking slowly.
Text:
Color: Slowly pulsing yellow
What it means: There is a network error.
What to do:
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.
Color: Fast blinking yellow
What it means: You are holding down the reset button and are factory resetting this device.
What to do:
If you keep holding down the reset button, after about 12 seconds, the light will turn solid yellow. Once it is solid yellow, let go of the factory reset button.
Color: Solid yellow
What it means: Router is factory resetting.
What to do:
This can take up to 10 minutes. When it's done, the device will reset itself and start pulsing white, letting you know it's ready for setup.
Color: Solid red
What it means: Something is wrong.
What to do:
Critical failure. Factory reset the router. If the light stays red, contact Wifi customer support.
応答 :
Check that the Ethernet cable is connected to both your router and your modem and both devices are turned on. You might need to unplug and plug in each device again.
要約
- 応答を生成するときにモデルに使用して欲しい情報 (コンテキスト) をプロンプトに含めます。
- コンテキスト情報の使用方法について指示モデルに与えます。
4. プレフィックスの追加
プレフィックスは、どこに追加に依存する、幾つかの目的に役立つことができるプロンプトコンテンツに追加する単語やフレーズです :
- 入力プレフィックス : モデルへの入力の意味的に重要な部分である、入力シグナルにプレフィックスを追加します。例えば、プレフィックス “English: ” と “French: ” は 2 つの異なる言語を識別させます。
- 出力プレフィックス : 出力はモデルにより生成されますが、プロンプトの出力に対してプレフィックスを追加できます。出力プレフィックスは応答として期待されるものについての情報をモデルに与えます。例えば、出力プレフィックス “JSON:” は出力が JSON 形式である必要があることをモデルに伝えます。
- サンプル・プレフィックス : few-ショット・サンプルでは、サンプルへのプレフィックスの追加は、出力を生成するときにモデルが使用できるラベルを提供します、これは出力コンテンツを解析することが簡単になります。
次の例では、”Text: ” は入力プレフィックスで、”The answer is: ” は出力プレフィックスです。
プロンプト :
Classify the text as one of the following categories.
- large
- small
Text: Rhino
The answer is: large
Text: Mouse
The answer is: small
Text: Snail
The answer is: small
Text: Elephant
The answer is:
応答 :
large
以上