Gemini : ガイド : プロンプト設計ストラテジー (2)
作成 : クラスキャット セールスインフォメーション
作成日時 : 04/28/2024
* 本ページは、ai.google.dev の以下のページを独自に翻訳して、適宜、補足説明したものです :
* サンプルコードの動作確認はしておりますが、必要な場合には適宜、追加改変しています。
* ご自由にリンクを張って頂いてかまいませんが、sales-info@classcat.com までご一報いただけると嬉しいです。
- 人工知能研究開発支援
- 人工知能研修サービス(経営者層向けオンサイト研修)
- テクニカルコンサルティングサービス
- 実証実験(プロトタイプ構築)
- アプリケーションへの実装
- 人工知能研修サービス
- PoC(概念実証)を失敗させないための支援
- お住まいの地域に関係なく Web ブラウザからご参加頂けます。事前登録 が必要ですのでご注意ください。
◆ お問合せ : 本件に関するお問い合わせ先は下記までお願いいたします。
- クラスキャット セールス・マーケティング本部 セールス・インフォメーション
- sales-info@classcat.com ; Website: www.classcat.com ; ClassCatJP
Gemini : ガイド : プロンプト設計ストラテジー (2)
5. モデルに部分的な入力を補完させる
生成言語モデルは高度な自動コンプリーション・ツールのように動作します。部分的なコンテンツを提供する場合、モデルは応答としてコンテンツの残り、あるいはそのコンテンツの継続と考えるものを提供することができます。それを行なう際、サンプルやコンテキストを含めれば、モデルはそれらのサンプルやコンテキストを考慮できます。
次のサンプルは指示とエンティティ入力を含むプロンプトを提供しています :
プロンプト :
For the given order, return a JSON object that has the fields cheeseburger, hamburger, fries, or
drink, with the value being the quantity.
Order: A burger and a drink.
応答 :
```
{
"cheeseburger": 0,
"hamburger": 1,
"fries": 0,
"drink": 1
}
```
モデルがプロンプトに従い動作する一方で、指示を自然言語で書き出すことは難しい場合があり、多くをモデルの解釈に委ねることになります。例えば、レストランのメニューが多くのアイテムを含むとします。JSON 応答のサイズを減じるため、注文されていないアイテムを多分省略したいでしょう。この場合、サンプルと応答プレフィックスを与えてモデルにそれを補完させることができます :
プロンプト :
Valid fields are cheeseburger, hamburger, fries, and drink.
Order: Give me a cheeseburger and fries
Output:
```
{
"cheeseburger": 1,
"fries": 1
}
```
Order: I want two burgers, a drink, and fries.
Output:
応答 :
```
{
"hamburger": 2,
"drink": 1,
"fries": 1
}
```
“cheeseburger” は注文の一部ではないので、出力から除外されていることに注意してください。
モデルに応答をフォーマットするようにプロンプトを与える
補完ストラテジーはまた応答をフォーマットするのに役立ちます。次のサンプルはエッセイの概要を作成するようにモデルにプロンプトを与えています :
プロンプト :
Create an outline for an essay about hummingbirds.
応答 :
I. Introduction
A. Hook: Begin with an intriguing fact or description of hummingbirds.
B. Provide some background information on hummingbirds.
1. Mention their small size and long, thin beaks.
2. Highlight their unique ability to hover and fly backward.
II. Body
A. Anatomy and Physiology
1. Elaborate on their tiny size, making comparisons to other animals.
2. Describe their wings and how they enable hovering and swift flight.
3. Discuss their metabolism and energy requirements, emphasizing their caloric needs.
B. Feeding Habits and Diet
1. Explain their primary food source, nectar, and how they extract it from flowers.
2. Describe their ability to feed from a wide variety of flowers.
3. Mention their consumption of insects and the nutritional value they provide.
C. Migration Patterns
1. Discuss the incredible long-distance migrations of some hummingbird species.
2. Explain the phenomenon of seasonal migration and the environmental factors driving it.
3. Describe the routes taken by different species during migration.
D. Conservation and Threats
1. Highlight the importance of hummingbirds in ecosystems as pollinators.
2. Discuss the challenges and threats they face, such as habitat loss, nectar scarcity, and climate change.
3. Mention conservation efforts and ways to support hummingbird populations.
III. Conclusion
A. Summarize the main points covered in the essay.
B. Reinforce the importance of hummingbirds and their ecological role.
C. Provide a final thought or call to action to protect these fascinating creatures.
プロンプトは概要のための形式を指定していませんので、モデルが形式を選択しています。モデルに特定の形式で概要を返させるには、概要の最初を表すテキストを追加して、貴方が始めたパターンに基づいてモデルにそれを補完させます。
プロンプト :
Create an outline for an essay about hummingbirds.
I. Introduction
*
応答 :
I. Introduction
* Capture the reader's attention with an interesting anecdote or fact about hummingbirds.
* Provide a brief background on hummingbirds, including their unique characteristics.
* State the main points that will be covered in the essay.
II. The Unique Characteristics of Hummingbirds
* Discuss the hummingbird's exceptionally rapid wing-beat, allowing them to hover and fly backward.
* Highlight their tiny size, making them the smallest birds in the world.
* Describe their long, slender beaks and tongues, allowing them to reach deep into flowers to extract nectar.
* Explain their iridescent plumage, which creates brilliant and vibrant colors.
III. Hummingbird Migration and Distribution
* Discuss the extensive migration patterns of hummingbirds, covering vast distances across continents.
* Describe the different habitats where hummingbirds can be found, including tropical rainforests, deserts, and urban areas.
* Explain the seasonal changes that influence hummingbird migration and habitat selection.
IV. Hummingbird Diet and Feeding Habits
* Focus on the hummingbird's primary food source, which is nectar from flowers.
* Describe their ability to consume insects, spiders, and other small invertebrates for protein.
* Explain how hummingbirds use their long, slender tongues to extract nectar from flowers.
* Discuss the importance of flowering plants in providing sustenance for hummingbirds.
V. Reproduction and Nesting Behavior
* Describe the mating rituals and courtship behavior of hummingbirds.
* Explain the process of nest-building, including the materials used and the unique characteristics of hummingbird nests.
* Discuss the role of the female hummingbird in laying and incubating eggs.
* Describe the development of hummingbird chicks and the role of both parents in providing care.
VI. Threats to Hummingbirds and Conservation Efforts
* Highlight habitat loss, climate change, and deforestation as significant threats to hummingbird populations.
* Describe the role of habitat conservation initiatives in protecting hummingbird habitats.
* Explain the importance of creating hummingbird-friendly gardens and landscapes.
* Discuss the efforts of organizations and individuals working to conserve hummingbird populations.
VII. Conclusion
* Summarize the main points covered in the essay, emphasizing the unique characteristics, migration patterns, diet, reproduction, and conservation of hummingbirds.
* Provide a closing statement that leaves a lasting impression on the reader and reinforces the significance of these fascinating creatures.
要約
- モデルに部分的な入力を与えた場合、モデルはプロンプト内の利用可能なサンプルやコンテキストに基づいてその入力を補完します。
- モデルに入力を補完させるほうが、タスクを自然言語で記述するよりも簡単な場合があります。
- プロンプトに部分的な答えを追加すると、モデルが望ましいパターンや形式に従うようにガイドすることができます。
6. プロンプトを単純なコンポーネントに分割する
複雑なプロンプトを必要とするユースケースについては、単純なコンポーネントに分割することでこの複雑さをモデルが管理するのに役立てます。
指示を分割する
多くの指示を一つのプロンプトに持たせるかわりに、指示ごとに一つのプロンプトを作成します。ユーザの入力に基づいてどのプロンプトを処理するか選択できます。
プロンプトを連鎖する
複数のシーケンシャルなステップを含む複雑なタスクについては、各ステップをプロンプトにして、プロンプトを一つのシークエンスに連鎖 (chain) します。このプロンプトのシーケンシャルなチェインでは、シークエンスの一つのプロンプトの出力が次のプロンプトの入力になります。シークエンスの最後のプロンプトの出力が最終的な出力になります。
応答を集計する (aggregate)
集計 (aggregation) は、データの様々な部分で異なる並列タスクを実行したい場合に、結果を集計して最終的な出力を生成することです。例えば、モデルに、データの最初の部分上で演算を実行し、残りのデータ上で別の演算を実行し、そして結果を集計するように指示することができます。
要約
- 複雑な指示を各指示に対するプロンプトに分割して、ユーザの入力に基づいてどのプロンプトを適用するか決定します。
- 複数のシーケンシャルステップを別個のプロンプトに分割して、先行するプロンプトの出力が次のプロンプトの入力になるようにそれらを連鎖します。
- 並列タスクを分割して、応答を集計して最終的な出力を生成します。
7. 様々なパラメータ値で実験する
モデルに送信する各呼び出しは、モデルが応答を生成する方法を制御するパラメータ値を含みます。モデルは様々なパラメータ値に対して異なる結果を生成することができます。タスクに対して最良の値を得られるように様々なパラメータ値で実験してください。異なるモデルに対して利用可能なパラメータは異なる可能性があります。最も一般的なパラメータは以下です :
- 最大出力トークン
- Temperature
- Top-K
- Top-P
最大出力トークン
応答で生成できる最大トークン数です。 トークンは約 4 文字です。100 トークンはおよそ 60-80 単語に相当します。
短い応答のためには小さい値を、長い応答に対しては大きい値を指定します。
Temperature (温度)
temperature は応答生成の際のサンプリングのために使用され、これは topP や topK が適用される場合に発生します。temperature はトークン選択におけるランダム性の程度・度合いを制御します。低い temperature はより決定的で自由度や創造性の低い応答を必要とするプロンプトのために適しており、一方で高い temperature はより多様性があり創造的な結果につながります。0 の temperature は決定論的で、最も高い確率の応答が常に選択される ことを意味します。
殆どのユースケースでは、0.2 の temperature から始めてみてください。モデルが一般的過ぎる、短過ぎる応答を返したり、モデルがフォールバック・レスポンスを返したりする場合は、temperature を大きくしてみてください。
Top-K
top-K はモデルが出力用にトークンをどのように選択するかを変更します。1 の top-K は、次の選択されたトークンがモデルの語彙のすべてのトークンの中で最も確率が高い (greedy デコーディングとも呼ばれます) ことを意味し、3 の top-K は、次のトークンが temperature を使用して 3 つの最も確率の高いものの中から選択されることを意味します。
各トークン選択ステップについて、最も高い確率をもつ top-K トークンがサンプリングされます。そしてトークンは更に topP に基づいてフィルタリングされ、最終的なトークンは temperature サンプリングを使用して選択されます。
ランダム性の少ない応答のためには小さい値を、そしてランダムな応答のためには大きい値を指定します。デフォルトの top-K は 40 です。
Top-P
top-P はモデルが出力用トークンを選択する方法を変更します。トークンは、それらの確率の合計が top-P 値に等しくなるまで、最も高い確率のもの (top-K 参照) から低いものへと選択されます。例えば、トークン A, B と C が確率 0.3, 0.2 と 0.1 で topP 値が 0.5 である場合、モデルは temperature を使用して次のトークンとして A か B のいずれかを選択し、C は候補から除外します。
ランダム性の少ない応答のためには小さい値を、そしてランダムな応答のためには大きい値を指定します。デフォルトの top-P 値は 0.95 です。
8. プロンプト反復ストラテジー
プロンプト設計は、望ましい応答を一貫して取得する前に少数の反復を必要とする場合が多い、反復的なプロセスです。このセクションは、プロンプトを繰り返す際に試せることについてのガイダンスを提供します。
異なるフレーズの使用
プロンプトでの異なる単語やフレーズ (句・言い回し) の使用は、それらがすべて同じことを意味する場合でさえも、モデルからの異なる応答を生成することが多いです。プロンプトから期待する結果を得られない場合、それを言い換えてみてください。
Version 1:
How do I bake a pie?
Version 2:
Suggest a recipe for a pie.
Version 3:
What's a good pie recipe?
類似のタスクに切り替える
タスクに対する指示にモデルを従わせることができない場合、同じ結果を達成する類似のタスクに対する指示を与えてみてください。
このプロンプトは、事前定義されたカテゴリーを使用して本を分類するようにモデルに伝えています。
プロンプト :
Which category does The Odyssey belong to:
thriller
sci-fi
mythology
biography
応答 :
The answer: mythology
Explanations:
The Odyssey is an epic poem in ancient Greek literature. It is one of two major ancient Greek epic
poems attributed to Homer. The Odyssey is an epic poem that tells the story of Odysseus, a Greek
hero who fought in the Trojan War and then spent ten years trying to return home to Ithaca. The
Odyssey is a work of mythology.
応答は正しいですが、モデルはオプションの範囲内に収まっていません。完全なセンテンスの代わりに、オプションの一つだけでモデルが応答することも望んでいます。この場合、指示を多肢選択問題として言い換えて、モデルにオプションを選択するように求めることができます。
プロンプト :
Multiple choice problem: Which of the following options describes the book The Odyssey?
Options:
- thriller
- sci-fi
- mythology
- biography
応答 :
The answer is: mythology
プロンプトのコンテンツの順序を変更する
プロンプトのコンテンツの順序は応答に影響を与える場合があります。コンテンツの順序を変更してみて、それが応答にどのように影響するか確認してください。
Version 1:
[examples]
[context]
[input]
Version 2:
[input]
[examples]
[context]
Version 3:
[examples]
[input]
[context]
9. フォールバック・レスポンス
フォールバック・レスポンスは、プロンプトか応答がセーフティ・フィルターをトリガーした場合にモデルから返される応答です。フォールバック・レスポンスの例は、”I’m not able to help with that, as I’m only a language model.” です。
モデルがフォールバック・レスポンスで応答する場合、temperature を大きくしてみてください。
10. 避けるべきこと
- 事実に基づく (factual) 情報を生成するのにモデルに依存することは避けてください。
- 数学や論理の問題では慎重に使用してください。
以上