Show me a simple example of using Automatic Prompt
Engineering (APE) together with self-consistency prompting.
Assistant
Certainly! Below is a simple example demonstrating how Automatic Prompt Engineering (APE) can be combined with Self-Consistency Prompting to improve the reliability of an LLM's responses.
Example Scenario
Task: Answer a math word problem with high accuracy.
Problem:"A train travels 300 miles in 5 hours. What is its average speed?"
User
Does the LLM find the answer? Did the LLM make the selection?
Assistant
Great question! Let me clarify the roles of the LLM and the user/system in this process.
Who Does What?
Automatic Prompt Engineering (APE) – LLM’s Role:
Step 1: Automatic Prompt Engineering (APE)
APE involves generating and selecting the best prompt variations to improve performance. Here, we generate multiple prompts and pick the most effective one.
Generated Prompt Variations:
"Calculate the average speed of a train that travels 300 miles in 5 hours."
"If a train covers 300 miles in 5 hours, what is its speed in miles per hour?"
"Determine the average speed: distance = 300 miles, time = 5 hours."
"A train moves 300 miles in 5 hours. Compute its speed."
Selected Best Prompt (via APE):
"A train travels 300 miles in 5 hours. What is its average speed in miles per hour?"
(This version is clear and directly asks for the required unit.)
Step 2: Self-Consistency Prompting
Instead of generating just one answer, we generate multiple responses and select the most consistent one.
Multiple Responses (from the same prompt):
"The average speed is 60 mph."
"The train's speed is 60 miles per hour."
"300 miles / 5 hours = 60 mph."
"The average speed is 60 mph."
Consensus Answer:
All responses agree on 60 mph, so we can be confident in the answer.
Final Output:
Prompt Used:"A train travels 300 miles in 5 hours. What is its average speed in miles per hour?"
Answer:"The average speed is 60 mph."
Why This Works:
APE helps find the most effective phrasing of the prompt.
Self-Consistency reduces errors by checking multiple responses for agreement.
This approach is particularly useful for tasks requiring precision, such as math problems, logical reasoning, or factual questions.
Would you like a more complex example or a different use case?
The LLM can generate multiple prompt variations (e.g., rephrasing the question in different ways).
However, selecting the best prompt is typically done by:
A human evaluator (manually checking which prompt works best).
An automated metric (e.g., measuring response accuracy on a validation set).
A meta-LLM (a separate model that evaluates prompt quality).
Self-Consistency – LLM’s Role:
The LLM generates multiple responses to the same prompt (possibly with slight variations in reasoning).
The selection of the most consistent answer can be done by:
The LLM itself (if instructed to compare responses).
A voting mechanism (e.g., majority agreement).
A human reviewer (for critical tasks).
Revised Example with Clarity on Roles
Step 1: APE (Prompt Generation & Selection)
LLM generates prompt variations:
"Calculate the average speed of a train that travels 300 miles in 5 hours."
"What is the speed in mph if a train goes 300 miles in 5 hours?"
"A train covers 300 miles in 5 hours. Find its average speed."
Selection (not done by the LLM unless instructed):
A human or automated system picks the best-performing prompt (e.g., based on correctness in test cases).