マルチステップ・プロンプティング

OpenAI API によるプロンプトエンジニアリング

Fouad Trad

Machine Learning Engineer

マルチステップ・プロンプティング

  • 最終目標を一連のステップに分解する
  • モデルは各ステップを順に処理して最終出力を生成します
  • マルチステップ・プロンプトは、次のようなタスクに使用されます:
    • 順序立てて行うタスク
    • 認知的なタスク

Diagram showing that a multi-step prompt is a prompt that gives the model a series of sequential steps to perform.

OpenAI API によるプロンプトエンジニアリング

マルチステップ・プロンプトは宝の地図のようなもの

Image representing a treasure map along with some clues to find the treasure.

OpenAI API によるプロンプトエンジニアリング

シングルステップ・プロンプト:ブログを書く

prompt = "Compose a travel blog"
print(get_response(prompt))
Title: Exploring the Enchanting Landscapes of Iceland

Introduction: Welcome to my travel blog! Today, I am thrilled to share my unforgettable journey through 
the mesmerizing landscapes of Iceland. 

Day 1: Reykjavik - The Charming Capital [...]
Day 2: Golden Circle - Nature's Wonders [...]
Day 3: South Coast - A Journey of Ice and Fire [...]
Day 4: Glacier Lagoon - A Frozen Wonderland [...]
Day 5: Blue Lagoon - A Relaxing Finale [...]
OpenAI API によるプロンプトエンジニアリング

マルチステップ・プロンプト:ブログ記事を書く

prompt = """Compose a travel blog as follows:
Step 1: Introduce the destination.
Step 2: Share personal adventures during the trip.
Step 3: Summarize the journey.
"""
print(get_response(prompt))
OpenAI API によるプロンプトエンジニアリング

旅行ブログ記事の執筆

Title: Exploring the Enchanting Streets of Barcelona

Step 1: Introduce the destination. Welcome to Barcelona, a vibrant city nestled along the stunning Mediterranean coast of Spain [...]
Step 2: Share personal adventures during the trip. Exploring the narrow, winding streets of the Gothic Quarter, I stumbled upon hidden gems at every turn. [...]
Step 3: Summarize the journey. As my journey through Barcelona came to an end, I couldn't help but feel grateful for the incredible experiences and memories I had made [...]
OpenAI API によるプロンプトエンジニアリング

解答の正しさを分析する

  • 解答の正しさを確認するには、複数のステップが必要です
  • 例:
    • 計算関数のPythonコード

Image of a calculator

OpenAI API によるプロンプトエンジニアリング

解答の正しさを分析する

確認対象となる典型的な解答

calculator = """
def add(a, b):
    return a + b
def subtract(a, b):
    return a - b
def multiply(a, b):
    return a * b
def divide(a, b):
    return a / b
"""
シングルステップ・プロンプト:
prompt = f"""Determine if the code delimited 
by triple backticks is correct or not.
Answer by yes or no.
```{calculator}```"""

print(get_response(prompt))
Yes
OpenAI API によるプロンプトエンジニアリング

解答の正しさを分析するためのマルチステップ・プロンプティング

マルチステップ・プロンプト:
prompt = f"""Determine the correctness of the code delimited by triple backticks 
as follows: 
Step 1: Check the code correctness in each function. 
Step 2: Verify if the divide function handles the case when dividing by 0. 
Code: ```{calculator}```"""

print(get_response(prompt))
The code appears to be correct. It defines four functions: add, subtract, multiply, and 
divide. Each function performs the corresponding mathematical operation and returns the
result. However, it does not handle the case when dividing by 0, which can result in a 
ZeroDivisionError.
OpenAI API によるプロンプトエンジニアリング

マルチステップ・プロンプトとfew-shotプロンプトの比較

手順

  • モデルに何をすべきかを明示的に伝える

Diagram showing how a multi-step prompt breaks down the instruction into a series of steps in the input for the model to go over them one by one.

OpenAI API によるプロンプトエンジニアリング

マルチステップ・プロンプトとfew-shotプロンプトの比較

手順

  • モデルに何をすべきかを明示的に伝える

Diagram showing how a multi-step prompt breaks down the instruction into a series of steps in the input for the model to go over them one by one.

  • モデルが学習に利用する質問と回答

Image showing how a few-shot prompt works, where the input to the model is a set of example questions and answers along with the question we want the model to answer.

OpenAI API によるプロンプトエンジニアリング

練習しましょう!

OpenAI API によるプロンプトエンジニアリング

Preparing Video For Download...