
Microsoft guidanceã§Plan-and-Solveããã³ãããå®è£ ããŠã¿ã
ChatGPT Pluginã®Link Readerã¯ä¿¡ããããªãã»ã©äŸ¿å©ã§ãå šãŠã®å ¥åæ å ±ã¯Link Readerãçè§£ã§ãããããªæžåŒã«ãªã£ãŠããã¹ãã ãšæããŠããŸãã»ã©ã§ãã
Link Readerã䜿ãã°ãarXivã§å ¬éãããŠããè«æã®å 容ãã€ã³ãããã«ãç°¡åãªå®è£ ãChatGPTã«äœæããŠãããããšã容æã§ããããã°ã©ããšããŠã¯é·ã ãšæç« ãæžããããããããšããããã³ãŒãã®åœ¢ã«ãªã£ãŠããæ¹ãçè§£ã容æãªã®ã§ãç°¡æçã§ãã£ãŠãã³ãŒãã®åœ¢ã«èœãšããŠãããã®ã¯å©ãããŸãã
ããã§ä»åã¯ã¿ã€ãã«ã«ããPlan-and-Solveããã³ããè«æãäŸã«ç°¡æã³ãŒããçæããç°¡æã³ãŒããå ã«Microsoft guidanceã®ããã³ãããäœæããŠå®è¡ããŠã¿ãããšæããŸãã
Plan-and-Solveãšã¯CoTïŒChain-of-ThoughtïŒã®ããã«æåããã¹ããããã€ã¹ãããã§èããã®ã§ã¯ãªããã¿ã¹ã¯ãå°ããåå²ããèšç»ãç«ãŠãŠããã¿ã¹ã¯ãå®è¡ãçããå°ãåºãææ³ã®ããšã§ãè€æ°ã®ã¿ã¹ã¯ã«ãããŠCoTãããåžžã«é«ãæ§èœãçºæ®ããããšã確èªãããŠããŸãã
è«æããç°¡æã³ãŒããçæãã
ãã®è«æã«ãããšãPlan-and-Solve (PS) Promptingã¯ãLarge Language Models (LLMs)ããŒãã·ã§ããã§é£éçãªæèãæ¹åããããã®ææ³ã§ãããã®ææ³ã¯ã以äžã®2ã€ã®ã¹ãããã§æ§æãããŠããŸãã
1. åé¡çè§£ãšèšç»äœæ: ãŸããå šäœã®ã¿ã¹ã¯ãããå°ããªãµãã¿ã¹ã¯ã«åå²ããèšç»ãç«ãŠãŸãããã®ã¹ãããã§ã¯ãLLMsã«ãåé¡ãçè§£ããåé¡ã解決ããããã®èšç»ãç«ãŠãããšããæç€ºãäžããŸãã
2. èšç»ã®å®è¡ãšåé¡è§£æ±º: 次ã«ãèšç»ã«åŸã£ãŠãµãã¿ã¹ã¯ãå®è¡ããŸãããã®ã¹ãããã§ã¯ãLLMsã«ãèšç»ãå®è¡ããåé¡ãã¹ããããã€ã¹ãããã§è§£æ±ºããããšããæç€ºãäžããŸãã
ããã«ãèšç®ãšã©ãŒãæšè«ã¹ãããã®çæåè³ªãæ¹åããããã«ãPS Promptingãæ¡åŒµããPS+ Promptingãææ¡ãããŠããŸããPS+ Promptingã§ã¯ããé¢é£ãã倿°ãšãããã«å¯Ÿå¿ããæ°å€ãæœåºãããããã³ãäžéçµæãèšç®ããïŒèšç®ãšåžžèã«æ³šæãæãïŒããšããè©³çŽ°ãªæç€ºã远å ãããŸãã
以äžã«ããããã®èŠä»¶ãåºã«ããPythonã³ãŒãã®å®è£ äŸã瀺ããŸãããã ããLLMsã®å ·äœçãªå®è£ ã¯OpenAIã®GPT-3ãªã©ã®APIã䜿çšãããããããã§ã¯ç©ºã®é¢æ°ãšããŠè¡šçŸããŸãã
def llm(prompt: str) -> str:
# This function should use a Large Language Model to generate a response based on the given prompt
# For the sake of this example, it's represented as an empty function
pass
def understand_problem_and_devise_plan(problem: str) -> str:
prompt = f"次ã®åé¡ãçè§£ããããã解決ããããã®èšç»ãç«ãŠãŠãã ãã: {problem}"
plan = llm(prompt)
return plan
def execute_plan_and_solve_problem(plan: str) -> str:
prompt = f"次ã®èšç»ãå®è¡ããåé¡ãã¹ããããã€ã¹ãããã§è§£æ±ºããŠãã ãã: {plan}"
solution = llm(prompt)
return solution
def extract_variables_and_numerals(problem: str) -> str:
prompt = f"次ã®åé¡ããé¢é£ãã倿°ãšãããã«å¯Ÿå¿ããæ°å€ãæœåºããŠãã ãã: {problem}"
variables_and_numerals = llm(prompt)
return variables_and_numerals
def calculate_intermediate_results(problem: str, variables_and_numerals: str) -> str:
prompt = f"次ã®åé¡ã«ã€ããŠäžéçµæãèšç®ããŠãã ãããèšç®ãšåžžèã«æ³šæãæããæ¬¡ã®å€æ°ãšæ°å€ã䜿çšããŠãã ãã: {variables_and_numerals}"
intermediate_results = llm(prompt)
return intermediate_results
def solve_problem_with_ps_prompting(problem: str) -> str:
plan = understand_problem_and_devise_plan(problem)
solution = execute_plan_and_solve_problem(plan)
return solution
def solve_problem_with_ps_plus_prompting(problem: str) -> str:
variables_and_numerals = extract_variables_and_numerals(problem)
intermediate_results = calculate_intermediate_results(problem, variables_and_numerals)
plan = understand_problem_and_devise_plan(problem)
solution = execute_plan_and_solve_problem(plan)
return solutionç°¡æã³ãŒããåèã«guidanceã®ããã³ãããèµ·ãã
æ¬æ¥ã§ããã°ãããguidanceã®ããã¥ã¡ã³ããLink Readerã«é£ãããããšã§giudanceããã³ãããèªåçæããããšããã§ãããçŸåšã®READMEãåç §ããŠããã£ãŠããã¡ãããšããAPIããã¥ã¡ã³ãããªããšçæã§ããŸããããšå°ãé¡ããããŠããŸããŸããããããã®ã©ã€ãã©ãªããã¥ã¡ã³ãã¯åžžã«ChatGPTãçè§£ã§ãããããªå 容ã§ããããšãæ±ããããŠããããã§ãã
ãšããããã§äººéã®æã§çæããŠã¿ãçµæã以äžã®éãã§ãã
{{#system~}}
Assistant is a large language model trained by OpenAI.
Assistant is designed to be able to assist with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics. As a language model, Assistant is able to generate human-like text based on the input it receives, allowing it to engage in natural-sounding conversations and provide responses that are coherent and relevant to the topic at hand.
Assistant is constantly learning and improving, and its capabilities are constantly evolving. It is able to process and understand large amounts of text, and can use this knowledge to provide accurate and informative responses to a wide range of questions. Additionally, Assistant is able to generate its own text based on the input it receives, allowing it to engage in discussions and provide explanations and descriptions on a wide range of topics.
Overall, Assistant is a powerful system that can help with a wide range of tasks and provide valuable insights and information on a wide range of topics. Whether you need help with a specific question or just want to have a conversation about a particular topic, Assistant is here to assist.
{{~/system}}
{{#user~}}
{{! 次ã®{åé¡}ããé¢é£ãã倿°ãšãããã«å¯Ÿå¿ããæ°å€ãæœåºããŠãã ãã: }}
Extract relevant variables and their corresponding numerals from the following {problem}.
{problem}: """
{{problem}}
"""
{{~/user}}
{{#assistant~}}
{{gen 'variables_and_numerals' temperature=0 max_tokens=800}}
{{~/assistant}}
{{#user~}}
{{! {åé¡}ã«ã€ããŠäžéçµæãèšç®ããŠãã ãããèšç®ãšåžžèã«æ³šæãæããæ¬¡ã®{倿°ãšæ°å€}ã䜿çšããŠãã ãã: }}
Calculate intermediate results for the following problem, paying attention to calculations and common sense, and using the following {variables and numerals}.
{variables_and_numerals}: """
{{variables_and_numerals}}
"""
{{~/user}}
{{#assistant~}}
{{gen 'intermediate_results' temperature=0 max_tokens=800}}
{{~/assistant}}
{{#user~}}
{{! {åé¡}ãçè§£ããããã解決ããããã®èšç»ãç«ãŠãŠãã ãã: }}
Understand the {problem} and devise a plan to solve it.
{{~/user}}
{{#assistant~}}
{{gen 'plan' temperature=0 max_tokens=800}}
{{~/assistant}}
{{#user~}}
{{! 次ã®èšç»ãå®è¡ããåé¡ãã¹ããããã€ã¹ãããã§è§£æ±ºããŠãã ãã: }}
Execute the following {plan} and solve the {problem} step by step.
{plan}: """
{{plan}}
"""
{{~/user}}
{{#assistant~}}
{{gen 'solution' temperature=0 max_tokens=800}}
{{~/assistant}}
{{#user~}}
æçµçãªçãã«ã€ããŠç°¡æœã«æ¥æ¬èªã§çããŠãã ããã
{{~/user}}
{{#assistant~}}
{{gen 'final_answer' temperature=0 max_tokens=800}}
{{~/assistant}}ãã®ããã³ãããplan_and_solve.handlebarsãšããŠä¿åãã以äžã®ã³ãŒãã§å®è¡ããŸãã
import guidance
with open('plan_and_solve.handlebars', 'r') as f:
prompt = f.read()
gpt3_5 = guidance.llms.OpenAI('gpt-3.5-turbo')
guidance.llm = gpt3_5
plan_and_solve = guidance(prompt)
problem = "ããäŒæ¥ã®å¹Žé売äžã¯100ååã§ããã®ãã¡40%ã人件費ã30%ãåææè²»ã10%ãåºåè²»ã«äœ¿ãããæ®ããå©çã§ãããã®äŒæ¥ã®å¹Žéå©çã¯ãããã§ããïŒ"
out = plan_and_solve(problem=problem)ãããšä»¥äžã®çµæãåŸãããŸãïŒ
ïŒâ»ã·ã¹ãã ã¡ãã»ãŒãžã®è¡šç€ºã¯çç¥ããŸãïŒ





以äžãŸã§ãguidanceãJupyter Notebookã§å®è¡ããéã«åºåããã衚瀺ã§ãããæçµçãªçãã ããåŸããå Žåã¯ä»¥äžã®ãããªã³ãŒãã§ååŸããããšãã§ããŸãã
print(out["final_answer"])ãã®äŒæ¥ã®å¹Žéå©çã¯20ååã§ãã
ChatGPTã§ãã®ãŸãŸåé¡ãè§£ããŠããã£ããã©ããªãïŒ
以äžã®çµæã«ãªããŸããã
ããäŒæ¥ã®å¹Žé売äžã¯100ååã§ããã®ãã¡40%ã人件費ã30%ãåææè²»ã10%ãåºåè²»ã«äœ¿ãããæ®ããå©çã§ãããã®äŒæ¥ã®å¹Žéå©çã¯ãããã§ããïŒ
äŒæ¥ã®å¹Žé売äžã¯100ååã§ããã人件費ã40%ãåææè²»ã30%ãåºåè²»ã10%ãšãããŠããŸãããããã®è²»çšãå·®ãåŒããæ®ããå©çãšãªããŸãã
人件費ã®å²åã¯40%ãªã®ã§ã100ååã®40%ãèšç®ããŸãã
人件費 = 100åå à 0.4 = 40åå
åæ§ã«ãåææè²»ãšåºåè²»ãèšç®ããŸãã
åææè²» = 100åå Ã 0.3 = 30åå
åºåè²» = 100åå à 0.1 = 10åå
å©çã¯æ®ãã®éé¡ã§ãã®ã§ã売äžãã人件費ãåææè²»ãåºåè²»ãå·®ãåŒããŸãã
å©ç = 100åå - 40åå - 30åå - 10åå = 20åå
ãããã£ãŠããã®äŒæ¥ã®å¹Žéå©çã¯20ååãšãªããŸãã
ã¹ããããã€ã¹ããããšããæç€ºããªãã®ã«ã¹ããããã€ã¹ãããã§åŠçããŠãããšãããèŠããšããããŸã§é«è©äŸ¡ã ã£ã匷ååŠç¿ããŒã¿ã«ã¹ããããã€ã¹ãããã§åŠçããäŒè©±ããã¹ãã倧éã«å«ãŸããŠããã®ããªãšæšæž¬ããŸããã€ã³ã¹ãã©ã¯ã·ã§ã³ãã¥ãŒãã³ã°ã匷åãããŠãããšããããŸãåã£ãæç€ºãããªããŠãããããªãã®åçãè¿ããŠãããããã«ãªãããã§ããã
ææ
è«æãã€ã³ãããã«ç°¡æã³ãŒããçæããŠããããçè§£ãæ·±ããææ³ã¯ãšãŠããªã¹ã¹ã¡ã§ããShow Meãªã©ã§ãã£ãŒããæžããŠããã£ãæ¹ãè¯ããšãã声ããããŸãããå人çã«ã¯ç䌌ã³ãŒãã§ãè¯ãããã³ãŒãã®æ¹ãåããããããã§ããããã»ã»ã»ã
ãå®å šã«å®è¡å¯èœãªã³ãŒããçæããŠãã ããããšãªãŒããŒãããšããšããããä»®ã§ãåã圢ã®ã³ãŒããçæããŠãããã®ã§ãããããAPI飿ºç³»ã®é¢æ°ãã¢ãã¯ã§å®çŸ©ã ãæž¡ããã¿ãããªããšãç¹°ãè¿ããŠãããšç²Ÿç·»åã§ããŸããäŸãã°ä»¥äžã®ãããªåœ¢ã§ãã
ããã³ãããåŒæ°ãšããŠãçæãããæååãè¿ã颿°ã llm(prompt: str) -> str ãšå®çŸ©ããŸãããã®é¢æ°ãå©çšããŠãäžèšã®å®è£ ãã§ãããšãããŸã§è©³çްåããªããã
åãã€ããŠãããšãã粟床é«ãçè§£ããŠãããã®ã§ãåãå¯èœãªéãã€ããŠããã®ãè¯ãã§ããã
çŸå Žããã¯ä»¥äžã§ãã