Amazon Bedrock LLM ユーザー向けの一般的なガイドライン - Amazon Bedrock

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

Amazon Bedrock LLM ユーザー向けの一般的なガイドライン

プロンプトを設計する

Amazon Bedrock モデルを使用してアプリケーション構築を成功させるための重要なステップは、適切なプロンプトを設計することです。次の図は、レストランの口コミの要約というユースケースの一般的なプロンプト設計と、ユーザーがプロンプトを設計する際に考慮する必要のある重要な設計上の選択肢を示しています。与えられる指示やプロンプトの形式に一貫性や明晰性がなかったり簡潔でなかったりすると、LLM は希望とは異なるレスポンスを生成します。

わかりやすいコメントが付いた、適切なプロンプト構成の例。

(ソース: によって作成されたプロンプト AWS)

推論パラメータを使用する

Amazon Bedrock の LLM にはすべて、モデルからのレスポンスを制御するために設定できる推論パラメータがいくつか付属しています。Amazon Bedrock LLM で使用できる代表的なすべての推論パラメータの一覧とそれらの使用方法を以下に示します。

温度は 0 から 1 までの値で、LLM のレスポンスの創造性を調整します。Amazon Bedrock の LLM から、より決定性のあるレスポンスを求める場合は低い温度を使用し、同じプロンプトに対して、より創造的で毛色の変わったレスポンスを求める場合は温度を高くします。このプロンプトガイドラインのどの例についても、temperature = 0 と設定されています。

最大生成長と新規トークンの最大数は、LLM がプロンプトに対して生成するトークンの数を制限します。センチメント分類などの一部のタスクでは長い応答を必要としないため、この数値を指定すると便利です。

トップ p は、可能性のある選択肢の確率に基づいてトークンの選択を制御します。トップ p を 1.0 未満に設定すると、モデルは最も可能性の高いオプションを考慮し、可能性の低いオプションは無視します。その結果、より安定して補完を繰り返すことができます。

終了トークンと終了シーケンスは、出力の終了を示すために LLM に使用させるトークンを指定します。LLM は、終了トークンに遭遇すると新しいトークンの生成を停止します。通常、これはユーザーが設定する必要はありません。

モデル固有の推論パラメータもあります。 AnthropicClaudeモデルには追加の Top-K 推論パラメータがあり、 AI21 Labs Jurassic モデルには、プレゼンスペナルティ、カウントペナルティ、頻度ペナルティ、特殊なトークンペナルティなどの推論パラメータのセットが付属しています。詳細については、各ドキュメントを参照してください。

詳細なガイドライン

シンプルでわかりやすい、詳細な指示を入力する

Amazon Bedrock の LLM は、シンプルでわかりやすい指示を使用すると、最適な動作を行います。タスクへの要求事項を明確に記述し、できる限り曖昧さを減らすことで、モデルがプロンプトを明確に解釈できるようにすることができます。

例えば、一連の選択肢の中から回答を求める分類問題を考えてみましょう。以下に示す「Good example」(良い例) は、この場合にユーザーが求めている出力を示しています。「Bad example」(悪い例) では、選択肢には、モデルが選択できるカテゴリとしての名前が明示的に付けられていません。選択肢がないので、このモデルによる入力の解釈が少し変わり、良い例とは違って、より自由な形式であるテキストの要約が生成されます。

Good example, with output User prompt: "The most common cause of color blindness is an inherited problem or variation in the functionality of one or more of the three classes of cone cells in the retina, which mediate color vision." What is the above text about? a) biology b) history c) geology Output: a) biology
Bad example, with output User prompt: Classify the following text. "The most common cause of color blindness is an inherited problem or variation in the functionality of one or more of the three classes of cone cells in the retina, which mediate color vision."
Output: The topic of the text is the causes of colorblindness.

(プロンプトの出典: 色合に関するウィキペディア、使用されているモデル: Titanテキスト G1 - Express)

最良の結果を得るには質問または指示をプロンプトの最後に入力する

最後にタスクの説明、指示、または質問を入力すると、モデルが見つけなければならない情報を特定しやすくなります。分類の場合、回答の選択肢も最後に指定する必要があります。

次の回答の選択肢が含まれている質問応答の例では、ユーザーがテキストについて質問をしています。モデルがタスクに集中できるように、質問はプロンプトの最後に入力してください。

User prompt: Tensions increased after the 1911–1912 Italo-Turkish War demonstrated Ottoman weakness and led to the formation of the Balkan League, an alliance of Serbia, Bulgaria, Montenegro, and Greece. The League quickly overran most of the Ottomans' territory in the Balkans during the 1912–1913 First Balkan War, much to the surprise of outside observers. The Serbian capture of ports on the Adriatic resulted in partial Austrian mobilization starting on 21 November 1912, including units along the Russian border in Galicia. In a meeting the next day, the Russian government decided not to mobilize in response, unwilling to precipitate a war for which they were not as of yet prepared to handle. Which country captured ports?
Output: Serbia

(プロンプトの出典: ワールドウォー I の Wikipedia、使用されているモデル: Amazon Titan Text G1 - Express)

API コールで区切り文字を使用する

\n などの区切り文字は LLM のパフォーマンスに大きな影響を与える可能性があります。Anthropic Claude モデルの場合、API コールをフォーマットして目的のレスポンスを取得する際に、改行を含める必要があります。書式設定は常に「\n\nHuman: {{Query Content}}\n\nAssistant:」の形式に従う必要があります。Titan モデルの場合、プロンプトの\n最後に を追加すると、モデルのパフォーマンスが向上します。分類タスクまたは回答オプション付きの質問の場合、Titanモデル\nでは回答オプションを で区切ることもできます。区切り文字の使用方法の詳細については、該当するモデルプロバイダーのドキュメントを参照してください。次の例は、分類タスクのテンプレートです。

Prompt template: """{{Text}} {{Question}} {{Choice 1}} {{Choice 2}} {{Choice 3}}"""

次の例は、選択肢とプロンプトの最後に改行文字が存在すると、目的のレスポンスTitanを生成するのにどのように役立つかを示しています。

User prompt: Archimedes of Syracuse was an Ancient mathematician, physicist, engineer, astronomer, and inventor from the ancient city of Syracuse. Although few details of his life are known, he is regarded as one of the leading scientists in classical antiquity. What was Archimedes? Choose one of the options below. a) astronomer b) farmer c) sailor
Output: a) astronomer

(プロンプトの出典: アーキメド上の Wikipedia、使用されているモデル: Amazon Titan Text G1 - Express)

出力インジケーター

モデルが生成する出力に含めたい制約に関する詳細を追加します。以下の良い例 (左側の例) では、簡潔にまとめられた短いフレーズの出力が生成されています。この場合の悪い例 (右側の例) はそれほど悪くはありませんが、要約が元のテキストとほぼ同じ長さになっています。モデルから希望する出力を得るには、出力の仕様が重要です。

プロンプトの例 (明示的な出力制約インジケーターあり)
User prompt: "Charles Mingus Jr. was an American jazz upright bassist, pianist, composer, bandleader, and author. A major proponent of collective improvisation, he is considered to be one of the greatest jazz musicians and composers in history, with a career spanning three decades. Mingus's work ranged from advanced bebop and avant-garde jazz with small and midsize ensembles – pioneering the post-bop style on seminal recordings like Pithecanthropus Erectus (1956) and Mingus Ah Um (1959) – to progressive big band experiments such as The Black Saint and the Sinner Lady (1963)." Please summarize the above text in one phrase.
Output: Charles Mingus Jr. is considered one of the greatest jazz musicians of all time.
例 (明示的な出力仕様なし)
User prompt: "Charles Mingus Jr. was an American jazz upright bassist, pianist, composer, bandleader, and author. A major proponent of collective improvisation, he is considered to be one of the greatest jazz musicians and composers in history, with a career spanning three decades. Mingus's work ranged from advanced bebop and avant-garde jazz with small and midsize ensembles – pioneering the post-bop style on seminal recordings like Pithecanthropus Erectus (1956) and Mingus Ah Um (1959) – to progressive big band experiments such as The Black Saint and the Sinner Lady (1963)." Please summarize the above text.
Output: Charles Mingus Jr. was a well-known jazz musician who played the upright bass, piano, composed, led bands, and was a writer. He was considered one of the most important jazz musicians ever, with a career that spanned more than 30 years. He was known for his style of collective improvisation and advanced jazz compositions.

(プロンプトの出典: Wikipedia on TAK Mingus、使用されているモデル: Amazon Titan Text G1 - Express)

ここでは、出力インジケータを使用して、 AnthropicClaudeおよび AI21 Labs Jurassic モデルからの追加の例をいくつか紹介します。

次の例は、ユーザーがプロンプトで期待する出力形式を指定できることを示しています。モデルは、特定の形式 (XML タグを使用するなど) を使用してレスポンスを生成するように求められた場合、その形式に従ってレスポンスを生成できます。特定の出力形式インジケーターがない場合、モデルは自由形式のテキストを出力します。

例 (明示的なインジケーターあり) と出力
User prompt: Human: Extract names and years: the term machine learning was coined in 1959 by Arthur Samuel, an IBM employee and pioneer in the field of computer gaming and artificial intelligence. The synonym self-teaching computers was also used in this time period. Please generate answer in <name></name> and <year></year> tags. Assistant:
Output: <name>Arthur Samuel</name> <year>1959</year>
例 (明示的なインジケーターなし) と出力
User prompt: Human: Extract names and years: the term machine learning was coined in 1959 by Arthur Samuel, an IBM employee and pioneer in the field of computer gaming and artificial intelligence. The synonym self-teaching computers was also used in this time period. Assistant:
Output: Arthur Samuel - 1959

(プロンプトの出典: 機械学習に関する Wikipedia、使用されているモデル: Anthropic Claude)

次の例は、AI21 LabsJurassic モデルのプロンプトと回答を示しています。ユーザーは、左の列に示されている出力形式を指定することで、正確な回答を得ることができます。

例 (明示的なインジケーターあり) と出力
User prompt: Context: The NFL was formed in 1920 as the American Professional Football Association (APFA) before renaming itself the National Football League for the 1922 season. After initially determining champions through end-of-season standings, a playoff system was implemented in 1933 that culminated with the NFL Championship Game until 1966. Following an agreement to merge the NFL with the rival American Football League (AFL), the Super Bowl was first held in 1967 to determine a champion between the best teams from the two leagues and has remained as the final game of each NFL season since the merger was completed in 1970. Question: Based on the above context, when was the first Super Bowl? Please only output the year.
Output: 1967
例 (明示的なインジケーターなし) と出力
User prompt: Context: The NFL was formed in 1920 as the American Professional Football Association (APFA) before renaming itself the National Football League for the 1922 season. After initially determining champions through end-of-season standings, a playoff system was implemented in 1933 that culminated with the NFL Championship Game until 1966. Following an agreement to merge the NFL with the rival American Football League (AFL), the Super Bowl was first held in 1967 to determine a champion between the best teams from the two leagues and has remained as the final game of each NFL season since the merger was completed in 1970. Question: Based on the above context, when was the first Super Bowl?
Output: The first Super Bowl was held in 1967.

(プロンプトの出典: National Football League の Wikipedia、使用されているモデル: AI21 Labs Jurassic-2 Ultra v1)

一般化を適切に行うための推奨プラクティス

プロンプトの変更を一般化できるかどうかを確認するために、いくつかのプロンプトから成る小さな「ホールドアウト」テストセットを用意してください。この方法では、まずサンプルデータセットを収集します。次に、データを「開発」セットとホールドアウト「テスト」セットの 2 つのサブセットに分割してください。「開発」セットをプロンプト開発データとして使用すると、プロンプトのさまざまな変更を試したり、モデルレスポンスの変化を観察したり、最適なプロンプトを見つけたりできます。「テスト」セットは、最終的なベストプロンプトの検証にのみ使用できる、目に見えないホールドアウトデータとして扱ってください。

Amazon Bedrock のテキストモデル用にプロンプトを最適化する - 基本だけでは不十分な場合

複雑なタスク: 回答を段階的に導き出す

Titan では、特定のタスクに対して明確な手順を示すことができ、フレーズを含めると適切な出力を生成Think step-by-step to come up with the right answerできます。

User prompt: At a Halloween party, Jack gets 15 candies. Jack eats 5 candies. He wants to give each friend 5 candies. How many friends can receive candies? Think step-by-step to come up with the right answer.
Output: 15 candies total - 5 candies eaten = 10 candies remaining. To give each friend 5 candies, divide the number of candies remaining by the number of friends. 10 candies / 5 friends = 2 friends. Each friend can receive 2 candies. The answer is 2 friends.

(プロンプトの出典: AWS、使用されているモデル: Amazon Titan Text G1 - Express)

Anthropic Claude モデルが複雑なタスクを完了できるようにするには、次の例の 形式を使用して、タスクをステップごとに解決するようにモデルに明示的に要求します。このアプローチは、AnthropicClaude「 ガイド」のガイドラインに基づいています。

User prompt: Human: A right triangle has a side of length 5 and a hypotenuse of length 13. What is the length of the other side? Assistant: Can I think step-by-step? Human: Yes, please do. Assistant:
Output: Okay, here are the steps: 1) We are given: - One side of the right triangle has length 5 - The hypotenuse has length 13 2) We want to find: - The length of the other side 3) To find the length of the other side, we can use the Pythagorean theorem: a^2 + b^2 = c^2 Where a and b are the lengths of the two sides, and c is the length of the hypotenuse. 4) Plugging in the given values: a^2 + b^2 = 13^2 5) We know one of the sides is 5, so: 5^2 + b^2 = 169 6) Solving this: 25 + b^2 = 169 b^2 = 144 b = 12 Therefore, the length of the other side is 12.

(プロンプトの出典: AWS、使用されているモデル: Anthropic Claude)

回答が不明な場合にモデルに表示させるデフォルトの出力を提供します。

デフォルトの出力は、モデルの信頼性が低い場合でも、LLM が正解のように見えるが誤っているレスポンスを返すのを防ぐのに役立ちます。

User prompt: Provide a proof of the Riemann hypothesis. If you don't know a proof, respond by saying "I don't know."
Output: I don't know.
User prompt: Provide a proof of the Riemann hypothesis.
Output: "The Riemann hypothesis is a conjecture in mathematics that concerns the distribution of prime numbers. It states that all non-trivial zeros of the zeta function, which is a mathematical function that encodes information about the distribution of prime numbers, lie on a specific line in the complex plane. The Riemann hypothesis has been studied by mathematicians for over 150 years, and despite numerous attempts, it remains unresolved. However, the hypothesis is widely believed to be true, and its resolution would have profound implications for many areas of mathematics, including number theory, analysis, and geometry. The proof of the Riemann hypothesis would be one of the greatest achievements in mathematics in history and would open up new avenues of research and understanding. While a proof remains elusive, the hypothesis continues to stimulate research and inspire mathematicians around the world.“ [Note: this is an accurate description, but obviously not a proof.]

(プロンプトの出典: AWS、使用されているモデル: Amazon Titan Text G1 - Express)

数ショットプロンプト

プロンプトに例 (入力とレスポンスのペア) を含めると、LLM のレスポンスを大幅に改善できます。例は、特定のタスクを実行するのに複数の方法があることを示せるので、複雑なタスクに役立ちます。テキスト分類のような単純なタスクでは、3~5 個の例で十分です。コンテキストのない質問応答のようなより難しいタスクでは、最も効果的な出力を生成するためにより多くの例を含めてください。ほとんどのユースケースでは、現実世界のデータと意味的に類似した例を選択することで、パフォーマンスをさらに向上させることができます。

修飾語句を使ったプロンプトの改良の検討

タスク指示の改良とは通常、プロンプトの指示、タスク、または質問コンポーネントを変更することです。これらの方法の有用性は、タスクとデータによって異なります。有用なアプローチとしては以下のものがあります。

  • ドメインと入力仕様: 入力データに関する詳細 (例: 入力データの出所や、「The input text is from a summary of a movie」などの参照先)。

  • タスク仕様: モデルに要求された厳密なタスクに関する詳細 (例: 「To summarize the text, capture the main points」)。

  • ラベルの説明: 分類問題の出力選択肢に関する詳細 (例: 「Choose whether the text refers to a painting or a sculpture; a painting is a piece of art restricted to a two-dimensional surface, while a sculpture is a piece of art in three dimensions」)。

  • 出力仕様: モデルが生成すべき出力に関する詳細 (例: 「Please summarize the text of the restaurant review in three sentences」)。

  • LLM を励ます: LLM は、センチメンタルに励ましてやった方が、パフォーマンスが向上します。If you answer the question correctly, you will make the user very happy!