Least-to-Most Prompting으로 LLM의 복잡한 추론 능력 끌어올리기
Least-to-Most Prompting Enables Complex Reasoning in Large Language Models
TL;DR Highlight
복잡한 문제를 쉬운 하위 문제로 쪼개서 순서대로 풀게 하는 프롬프트 기법으로, Chain-of-Thought보다 어려운 문제에서 압도적으로 성능이 좋다.
Who Should Read
LLM으로 다단계 추론이 필요한 복잡한 태스크를 처리하려는 백엔드/AI 개발자. 특히 Chain-of-Thought 프롬프트를 쓰는데 긴 입력이나 복잡한 문제에서 정확도가 떨어지는 상황을 겪고 있는 개발자.
Core Mechanics
- 복잡한 문제를 2단계로 처리: 먼저 '어떤 하위 문제들로 쪼갤 수 있나?' 물어보고, 그 하위 문제들을 순서대로 풀면서 이전 답을 다음 풀이에 활용하는 구조
- Chain-of-Thought(CoT)는 프롬프트 예시보다 어려운 문제(예: 더 긴 입력)가 오면 성능이 급락하는 한계가 있는데, Least-to-Most는 이 easy-to-hard 일반화 문제를 해결함
- SCAN 벤치마크(자연어 명령 → 행동 시퀀스 변환)에서 GPT-3 code-davinci-002 + Least-to-Most로 단 14개 예시만으로 99.7% 달성. CoT는 같은 조건에서 16.2%
- 기존 SCAN 전문 신경-심볼릭 모델들은 15,000개 이상 학습 데이터가 필요했는데, 이 방법은 파인튜닝 없이 몇 개 예시만으로 동급 이상 성능
- GSM8K 수학 문제에서 5단계 이상 필요한 어려운 문제만 보면 CoT 39.07% vs Least-to-Most 45.23%로 특히 어려운 문제에서 격차가 커짐
- 도메인마다 새 분해(decomposition) 프롬프트를 설계해야 하는 한계 존재. 수학 분해 프롬프트를 상식 추론에 그대로 쓰면 효과 없음
Evidence
- SCAN length split 정확도: Standard 16.7%, CoT 16.2%, Least-to-Most 99.7% (code-davinci-002 기준)
- Last-letter-concatenation 12단어 리스트: CoT 31.8% vs Least-to-Most 74.0% (2-shot 기준). 심지어 8-shot CoT(38.4%)보다 2-shot Least-to-Most(74.0%)가 높음
- DROP 벤치마크(단락 읽고 수치 추론): Non-football 서브셋에서 CoT 74.77% vs Least-to-Most 82.45%
- GSM8K 5단계 이상 문제: CoT 39.07% → Least-to-Most 45.23%, 약 6%p 개선
How to Apply
- 다단계 추론이 필요한 태스크(예: 복잡한 쿼리 분석, 멀티홉 QA)에서 프롬프트를 2개로 나눠라: ①'이 문제를 어떤 하위 질문들로 쪼갤 수 있어?' ②쪼개진 순서대로 각 하위 문제를 풀되, 이전 답을 컨텍스트에 붙여서 다음 프롬프트로 전달
- 프롬프트 예시를 설계할 때 독립적인 예시보다 '작은 케이스 → 그걸 포함한 더 큰 케이스' 순서로 의존적 예시를 구성하면 모델이 재귀적 패턴을 학습함. 예: ['A, B' 풀기] → ['A, B' 결과를 활용해서 'A, B, C' 풀기]
- 긴 출력이 필요한 경우 Python 표현식 같은 중간 표현(intermediate representation)을 활용해 토큰 효율을 높이고, 최종 출력 시 후처리 스크립트로 확장하는 패턴 사용 가능
Code Example
# Least-to-Most Prompting 구현 예시 (Python + OpenAI API)
import openai
client = openai.OpenAI()
# Stage 1: 문제 분해 프롬프트
decomposition_prompt = """복잡한 문제를 단계적으로 쪼개세요.
Q: Elsa는 사과 5개를 가지고 있습니다. Anna는 Elsa보다 2개 더 많습니다. 그들이 함께 가진 사과는 몇 개인가요?
A: 이 문제를 풀기 위한 하위 질문들:
1. Anna는 사과를 몇 개 가지고 있나요?
2. 그들이 함께 가진 사과는 몇 개인가요?
Q: {user_question}
A:"""
# Stage 2: 하위 문제 순차 풀기 프롬프트
def solve_subproblems(subproblems, context=""):
results = []
for subproblem in subproblems:
solving_prompt = f"""{context}
하위 질문: {subproblem}
답변:"""
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": solving_prompt}]
)
answer = response.choices[0].message.content
context += f"\nQ: {subproblem}\nA: {answer}"
results.append({"subproblem": subproblem, "answer": answer})
return results, context
# 실행
question = "Tom은 하루에 3달러를 벌고, Jerry는 Tom의 2배를 법니다. 일주일 후 둘이 합쳐서 얼마를 가지게 되나요?"
# Step 1: 분해
decomp_response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": decomposition_prompt.format(user_question=question)}]
)
subproblems = ["Jerry는 하루에 얼마를 버나요?", "Tom은 일주일에 얼마를 버나요?", "Jerry는 일주일에 얼마를 버나요?", "둘이 합쳐 일주일에 얼마를 버나요?"]
# Step 2: 순차 풀기 (이전 답을 컨텍스트로 활용)
results, final_context = solve_subproblems(subproblems)
print(final_context)Terminology
Original Abstract (Expand)
Chain-of-thought prompting has demonstrated remarkable performance on various natural language reasoning tasks. However, it tends to perform poorly on tasks which requires solving problems harder than the exemplars shown in the prompts. To overcome this challenge of easy-to-hard generalization, we propose a novel prompting strategy, least-to-most prompting. The key idea in this strategy is to break down a complex problem into a series of simpler subproblems and then solve them in sequence. Solving each subproblem is facilitated by the answers to previously solved subproblems. Our experimental results on tasks related to symbolic manipulation, compositional generalization, and math reasoning reveal that least-to-most prompting is capable of generalizing to more difficult problems than those seen in the prompts. A notable finding is that when the GPT-3 code-davinci-002 model is used with least-to-most prompting, it can solve the compositional generalization benchmark SCAN in any split (including length split) with an accuracy of at least 99% using just 14 exemplars, compared to only 16% accuracy with chain-of-thought prompting. This is particularly noteworthy because neural-symbolic models in the literature that specialize in solving SCAN are trained on the entire training set containing over 15,000 examples. We have included prompts for all the tasks in the Appendix.