[AI Paper] ๐ Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
๐ Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
๐ ๋ฉํ ์ ๋ณด
| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| ์ ์ | Jason Wei, Xuezhi Wang, Dale Schuurmans, Maarten Bosma, Brian Ichter, Fei Xia, Ed Chi, Quoc V. Le, Denny Zhou |
| ์์ | Google Brain (ํ Google DeepMind) |
| ๋ฐํ์ฒ | NeurIPS 2022 (Advances in Neural Information Processing Systems 35) |
| ๋ฐํ ์ฐ๋ | 2022 |
| arXiv | arXiv:2201.11903 |
| NeurIPS | Proceedings |
| ์ธ์ฉ์ | 10,000+ (2024๋ ๊ธฐ์ค, ํ๋กฌํํ ๋ถ์ผ ์ต๋ค ์ธ์ฉ ๋ ผ๋ฌธ ์ค ํ๋) |
๐ฏ ํ์ค ์์ฝ
๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ(LLM)์ ์ค๊ฐ ์ถ๋ก ๋จ๊ณ(chain of thought)๋ฅผ ํฌํจํ few-shot ์์๋ฅผ ์ ๊ณตํ๋ฉด, ๋ณต์กํ ์ฐ์ , ์์, ๊ธฐํธ ์ถ๋ก ๊ณผ์ ์์ ์ฑ๋ฅ์ด ๋น์ฝ์ ์ผ๋ก ํฅ์๋๋ค๋ ๊ฒ์ ์ต์ด๋ก ์ฒด๊ณ์ ์ผ๋ก ์ ์ฆํ ํ๊ธฐ์ ์ฐ๊ตฌ.
๐ ์ฐ๊ตฌ ๋ฐฐ๊ฒฝ ๋ฐ ๋๊ธฐ
๊ธฐ์กด ๋ฌธ์ ์
- ์ค์ผ์ผ๋ง์ ํ๊ณ: ์ธ์ด ๋ชจ๋ธ์ ํฌ๊ธฐ๋ฅผ ํค์๋ ์ฐ์ ์ถ๋ก , ์์ ์ถ๋ก , ๊ธฐํธ ์ถ๋ก ๊ฐ์ ๋ณต์กํ ๋ค๋จ๊ณ ์ถ๋ก (multi-step reasoning) ๊ณผ์ ์์๋ ์ฑ๋ฅ ํฅ์์ด ๋ฏธ๋ฏธํ์
-
ํ์ค ํ๋กฌํํ ์ ์ ์ฝ: ๊ธฐ์กด์ few-shot ํ๋กฌํํ ์ ์ ๋ ฅ-์ถ๋ ฅ ์๋ง ์ ๊ณตํ์ฌ, ๋ชจ๋ธ์ด ์ค๊ฐ ์ถ๋ก ๊ณผ์ ์์ด ๋ฐ๋ก ๋ต์ ์์ฑํ๋๋ก ์ ๋
-
Flat Scaling Curve ๋ฌธ์ : ๋ง์ ์ถ๋ก ๊ณผ์ ์์ ๋ชจ๋ธ ํฌ๊ธฐ๋ฅผ ํค์๋ ์ฑ๋ฅ์ด ๊ฑฐ์ ํฅ์๋์ง ์๋ ํ์์ด ์ง์
-
Fine-tuning์ ๋น์ฉ: ์ถ๋ก ๋ฅ๋ ฅ ํฅ์์ ์ํ ๋๊ท๋ชจ ๋ฐ์ดํฐ์ ๊ตฌ์ถ๊ณผ ํ์ธํ๋์ ๋ง๋ํ ๋น์ฉ๊ณผ ์๊ฐ์ด ์์
์ฐ๊ตฌ ๋๊ธฐ
- ์ธ๊ฐ์ ๋ณต์กํ ๋ฌธ์ ๋ฅผ ํ ๋ ๋จ๊ณ๋ณ๋ก ์ฌ๊ณ ๋ฅผ ๋ถํดํ์ฌ ํด๊ฒฐํจ
- ์ด๋ฌํ ์ธ๊ฐ์ ์ฌ๊ณ ๊ณผ์ ์ LLM์๋ ์ ์ฉํ ์ ์์ง ์์๊น?
- ํต์ฌ ์ง๋ฌธ: “ํ๋กฌํํธ์ ์ถ๋ก ๋จ๊ณ๋ฅผ ํฌํจ์ํค๋ฉด ๋ชจ๋ธ์ ์ถ๋ก ๋ฅ๋ ฅ์ด ํฅ์๋ ์ ์์๊น?”
๐ก ํต์ฌ ์์ด๋์ด
Chain-of-Thought (CoT)์ ์ ์
Chain-of-Thought(์ฌ๊ณ ์ ์ฐ์)๋ ์ต์ข ๋ต์ ๋๋ฌํ๊ธฐ๊น์ง์ ์ผ๋ จ์ ์ค๊ฐ ์ถ๋ก ๋จ๊ณ(intermediate reasoning steps)๋ฅผ ์๋ฏธํ๋ค.
๋ฌธ์ โ ์ถ๋ก ๋จ๊ณ 1 โ ์ถ๋ก ๋จ๊ณ 2 โ ... โ ์ถ๋ก ๋จ๊ณ n โ ์ต์ข
๋ต
ํ์ค ํ๋กฌํํ vs CoT ํ๋กฌํํ
ํ์ค ํ๋กฌํํ (Standard Prompting):
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls.
Each can has 3 tennis balls. How many tennis balls does he have now?
A: The answer is 11.
Chain-of-Thought ํ๋กฌํํ :
Q: Roger has 5 tennis balls. He buys 2 more cans of tennis balls.
Each can has 3 tennis balls. How many tennis balls does he have now?
A: Roger started with 5 balls. 2 cans of 3 tennis balls each is 6 tennis balls.
5 + 6 = 11. The answer is 11.
CoT์ ์ธ ๊ฐ์ง ํต์ฌ ํน์ฑ
- ๋ณต์กํ ๋ฌธ์ ๋ถํด: ๋ค๋จ๊ณ ๋ฌธ์ ๋ฅผ ์ค๊ฐ ๋จ๊ณ๋ค๋ก ๋ถํดํ์ฌ, ๊ฐ ๋จ๊ณ์ ๋ ๋ง์ ๊ณ์ฐ ์์ ํ ๋น ๊ฐ๋ฅ
-
ํด์ ๊ฐ๋ฅํ ์ถ๋ก ๊ณผ์ : ๋ชจ๋ธ์ด ํน์ ๋ต์ ๋๋ฌํ ๊ณผ์ ์ ๊ด์ฐฐํ ์ ์์ด ๋๋ฒ๊น ๊ณผ ํด์์ด ์ฉ์ด
-
๋ฒ์ฉ์ ์ ์ฉ ๊ฐ๋ฅ์ฑ: ์ํ, ์์, ๊ธฐํธ ์ถ๋ก ๋ฑ ์ธ๊ฐ์ด ์ธ์ด๋ก ํ ์ ์๋ ๋ชจ๋ ํ์คํฌ์ ์ ์ฉ ๊ฐ๋ฅ
CoT๊ฐ ํจ๊ณผ์ ์ธ ์ด์
| ์์ธ | ์ค๋ช |
|---|---|
| ์ค๊ฐ ๊ณ์ฐ ๊ณต๊ฐ | ๋ชจ๋ธ์ด ์ค๊ฐ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ๊ณ ํ์ฉํ ์ ์์ |
| ๋ฌธ์ ๋ถํด | ๋ณต์กํ ๋ฌธ์ ๋ฅผ ๊ด๋ฆฌ ๊ฐ๋ฅํ ํ์ ๋ฌธ์ ๋ก ๋ถํด |
| ์ธ๊ฐ ์ฌ๊ณ ๋ชจ๋ฐฉ | ์ธ๊ฐ์ ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ์๊ณผ ์ ์ฌํ ์ ๊ทผ |
| ์ค๋ฅ ์ถ์ ๊ฐ๋ฅ | ์ถ๋ก ๊ฒฝ๋ก๋ฅผ ํตํด ์ค๋ฅ ์์ธ ํ์ ๊ฐ๋ฅ |
๐๏ธ ๋ฐฉ๋ฒ๋ก
์คํ ์ค์
์ฌ์ฉ๋ ์ธ์ด ๋ชจ๋ธ
| ๋ชจ๋ธ | ํ๋ผ๋ฏธํฐ ํฌ๊ธฐ | ๋น๊ณ |
|---|---|---|
| GPT-3 (InstructGPT) | 350M, 1.3B, 6.7B, 175B | OpenAI |
| LaMDA | 422M, 2B, 8B, 68B, 137B | |
| PaLM | 8B, 62B, 540B | Google (์ฃผ์ ์คํ) |
| UL2 | 20B | |
| Codex | code-davinci-002 | OpenAI |
ํ๋กฌํํธ ๊ตฌ์ฑ ๋ฐฉ๋ฒ
[Few-shot exemplars with chain-of-thought] (๋ณดํต 8๊ฐ)
+ [Test question]
โ [Model generates chain-of-thought + answer]
CoT ํ๋กฌํํธ ๊ตฌ์กฐ
def chain_of_thought_prompting(question, cot_exemplars, model):
"""
Chain-of-Thought ํ๋กฌํํ
์๊ณ ๋ฆฌ์ฆ
Args:
question: ํ์ด์ผ ํ ๋ฌธ์
cot_exemplars: CoT๊ฐ ํฌํจ๋ few-shot ์์๋ค (8๊ฐ ์ฌ์ฉ)
model: ๋๊ท๋ชจ ์ธ์ด ๋ชจ๋ธ
Returns:
answer: ์ต์ข
๋ต๋ณ
reasoning_chain: ์ถ๋ก ๊ณผ์
"""
# 1. ํ๋กฌํํธ ๊ตฌ์ฑ
prompt = ""
for exemplar in cot_exemplars:
prompt += f"Q: {exemplar.question}\n"
prompt += f"A: {exemplar.chain_of_thought}. "
prompt += f"The answer is {exemplar.answer}.\n\n"
prompt += f"Q: {question}\nA:"
# 2. ๋ชจ๋ธ ์ถ๋ก (greedy decoding)
output = model.generate(prompt, temperature=0)
# 3. ๋ต๋ณ ์ถ์ถ
reasoning_chain = extract_reasoning(output)
answer = extract_final_answer(output)
return answer, reasoning_chain
๊ตฌ์ฒด์ ์ธ ์์๋ค
1. ์ฐ์ ์ถ๋ก ์์ (GSM8K)
Q: John has 10 apples. He gives away 4 and then receives 5 more.
How many apples does he have?
A: John starts with 10 apples. He gives away 4, so 10 - 4 = 6.
He then receives 5 more apples, so 6 + 5 = 11.
The answer is 11.
2. ์์ ์ถ๋ก ์์ (StrategyQA)
Q: Would a pear sink in water?
A: A pear has a density of about 0.59 g/cmยณ, which is less than
the density of water (1 g/cmยณ). Objects with density less
than water float. The answer is no.
3. ๊ธฐํธ ์ถ๋ก ์์ (Last Letter Concatenation)
Q: Take the last letters of the words in "Elon Musk" and
concatenate them.
A: The last letter of "Elon" is "n". The last letter of "Musk"
is "k". Concatenating them is "nk". The answer is nk.
Ablation Study์์ ๋น๊ตํ ๋ณํ๋ค
| ๋ณํ | ์ค๋ช | ํจ๊ณผ |
|---|---|---|
| Equation only | ์์ฐ์ด ์์ด ์ํ ๋ฐฉ์ ์๋ง | ํจ๊ณผ ์ ํ์ |
| Variable compute | “…”์ผ๋ก ํ ํฐ ์๋ง ์ฆ๊ฐ | ํจ๊ณผ ์์ |
| CoT after answer | ๋ต ๋จผ์ , ์ถ๋ก ๋์ค | ํจ๊ณผ ์์ |
๊ฒฐ๋ก : ์์ฐ์ด๋ก ๋ ์ค๊ฐ ์ถ๋ก ๋จ๊ณ๊ฐ ํต์ฌ์ด๋ฉฐ, ๋จ์ํ ํ ํฐ ์๋ฅผ ๋๋ฆฌ๊ฑฐ๋ ์์๋ฅผ ๋ฐ๊พธ๋ ๊ฒ์ ํจ๊ณผ๊ฐ ์์
๐ ์คํ ๋ฐ ๊ฒฐ๊ณผ
ํ๊ฐ ๋ฐ์ดํฐ์
1. ์ฐ์ ์ถ๋ก (Arithmetic Reasoning)
- GSM8K: ์ด๋ฑํ๊ต ์์ค ์ํ ์๋ ๋ฌธ์ (8.5K ๋ฌธ์ )
- SVAMP: ๋ค์ํ ์ํ ์๋ ๋ฌธ์
- ASDiv: ๋ค์ํ ๋์ด๋์ ์ํ ๋ฌธ์
- AQuA: ๋์ํ ๋ฌธ์
- MAWPS: ์ํ ์๋ ๋ฌธ์ ๋ชจ์ (SingleOp, SingleEq, AddSub, MultiArith)
2. ์์ ์ถ๋ก (Commonsense Reasoning)
- CommonsenseQA (CSQA): ์์ ๊ธฐ๋ฐ ๊ฐ๊ด์ ๋ฌธ์
- StrategyQA: ๋ค๋จ๊ณ ์ ๋ต์ ์ถ๋ก ์ด ํ์ํ ์/์๋์ค ๋ฌธ์
- Date Understanding: ๋ ์ง ๊ด๋ จ ์ถ๋ก (BIG-bench)
- Sports Understanding: ์คํฌ์ธ ๊ด๋ จ ์ถ๋ก (BIG-bench)
- SayCan: ๋ก๋ด ์ก์ ๋งคํ
3. ๊ธฐํธ ์ถ๋ก (Symbolic Reasoning)
- Last Letter Concatenation: ๋จ์ด๋ค์ ๋ง์ง๋ง ๊ธ์ ์ฐ๊ฒฐ
- Coin Flip: ๋์ ๋ค์ง๊ธฐ ์ํ ์ถ์
์ฃผ์ ์คํ ๊ฒฐ๊ณผ
1. ์ฐ์ ์ถ๋ก ๋ฒค์น๋งํฌ (PaLM 540B)
| ๋ฒค์น๋งํฌ | ํ์ค ํ๋กฌํํ | CoT ํ๋กฌํํ | ํฅ์ํญ |
|---|---|---|---|
| GSM8K | 17.9% | 56.9% | +39.0%p |
| SVAMP | 79.0% | 86.6% | +7.6%p |
| ASDiv | 73.9% | 82.0% | +8.1%p |
| MAWPS | 91.4% | 94.1% | +2.7%p |
ํต์ฌ ๋ฐ๊ฒฌ: GSM8K์์ CoT + PaLM 540B๊ฐ 56.9%๋ฅผ ๋ฌ์ฑํ์ฌ, fine-tuned GPT-3 + verifier (55%)๋ฅผ ๋ฅ๊ฐํ๋ฉฐ SOTA ๋ฌ์ฑ
2. ์์ ์ถ๋ก ๋ฒค์น๋งํฌ
| ๋ฒค์น๋งํฌ | ํ์ค ํ๋กฌํํ | CoT ํ๋กฌํํ | ๋น๊ณ |
|---|---|---|---|
| StrategyQA | ~65% | 75.6% | ๊ธฐ์กด SOTA 69.4% ๋ฅ๊ฐ |
| Sports Understanding | 84% | 95% | ์ธ๊ฐ ์ ๋ฌธ๊ฐ(84%) ๋ฅ๊ฐ |
| Date Understanding | – | 67.5% | ๋ณต์กํ ๋ ์ง ์ถ๋ก |
| CommonsenseQA | ~80% | ~80% | ๋ฏธ๋ฏธํ ํฅ์ |
3. ๊ธฐํธ ์ถ๋ก ๋ฒค์น๋งํฌ
| ๊ณผ์ | ํ์ค ํ๋กฌํํ | CoT ํ๋กฌํํ |
|---|---|---|
| Last Letter Concat (4 words) | ~0% | 58.0% |
| Coin Flip (4 flips) | ~0% | 91.4% |
์ค์ ๋ฐ๊ฒฌ: CoT๋ OOD(Out-of-Distribution) ๊ธธ์ด ์ผ๋ฐํ ๋ฅ๋ ฅ๋ ๋ณด์ฌ์ค (์: 2-word ์์๋ก 4-word ๋ฌธ์ ํด๊ฒฐ)
๋ชจ๋ธ ํฌ๊ธฐ๋ณ ์ฑ๋ฅ (Emergent Ability)
๋ชจ๋ธ ํฌ๊ธฐ | ํ์ค ํ๋กฌํํ
| CoT ํ๋กฌํํ
| ํจ๊ณผ
----------------|-------------|--------------|------
~1B ํ๋ผ๋ฏธํฐ | ๋ฎ์ | ๋ฎ์/๋ ๋ฎ์ | ์ญํจ๊ณผ ๊ฐ๋ฅ
~10B ํ๋ผ๋ฏธํฐ | ์ค๊ฐ | ์ค๊ฐ | ๋ฏธ๋ฏธํจ
~100B+ ํ๋ผ๋ฏธํฐ | ์ค๊ฐ | ๋์ โฌ๏ธ | ํฐ ํจ๊ณผ
ํต์ฌ ๋ฐ๊ฒฌ: CoT๋ ์ฝ 100B ํ๋ผ๋ฏธํฐ ์ด์์ ๋ชจ๋ธ์์๋ง ํจ๊ณผ๊ฐ ๋ํ๋๋ ์ฐฝ๋ฐ์ ๋ฅ๋ ฅ(emergent ability)
Self-Consistency์ ๊ฒฐํฉ ์ ๊ฒฐ๊ณผ
| ๋ฒค์น๋งํฌ | CoT๋ง | CoT + Self-Consistency | ์ถ๊ฐ ํฅ์ |
|---|---|---|---|
| GSM8K | 56.9% | 74.4% | +17.5%p |
| SVAMP | 86.6% | 93.0% | +6.4%p |
| StrategyQA | 75.6% | 82.0% | +6.4%p |
์ค๋ฅ ๋ถ์ (PaLM 62B, GSM8K)
| ์ค๋ฅ ์ ํ | ๋น์จ | ์ค๋ช |
|---|---|---|
| ๊ฑฐ์ ์ ํ | 46% | ์ฌ์ํ ๊ณ์ฐ ์ค์ |
| ์๋ฏธ ์ดํด ์ค๋ฅ | 27% | ๋ฌธ์ ์ดํด ์คํจ |
| ์ผ๊ด์ฑ ์ค๋ฅ | 27% | ์ถ๋ก ์ค ๋ ผ๋ฆฌ์ ๋ถ์ผ์น |
540B๋ก ์ค์ผ์ผ์ ์ 62B์ “ํ ๋จ๊ณ ๋๋ฝ”๊ณผ “์๋ฏธ ์ดํด” ์ค๋ฅ ๋๋ถ๋ถ ํด๊ฒฐ๋จ
๐ช ๊ฐ์ ๋ฐ ๊ธฐ์ฌ
1. ๋ฐฉ๋ฒ๋ก ์ ๋จ์์ฑ
- ํ์ธํ๋ ๋ถํ์: ๊ธฐ์กด ๋ชจ๋ธ์ ๊ทธ๋๋ก ์ฌ์ฉํ๋ฉฐ ํ๋กฌํํธ๋ง ๋ณ๊ฒฝ
- ์ต์ํ์ ์์: ๋จ 8๊ฐ์ CoT ์์๋ง์ผ๋ก SOTA ๋ฌ์ฑ
- ์ถ๊ฐ ํ์ต ๋ฐ์ดํฐ ๋ถํ์: ๋๊ท๋ชจ rationale ๋ฐ์ดํฐ์ ๊ตฌ์ถ ์์ด ์ ์ฉ ๊ฐ๋ฅ
2. ๋ฐ์ด๋ ์ฑ๋ฅ ํฅ์
- GSM8K์์ 3๋ฐฐ ์ด์ ์ฑ๋ฅ ํฅ์ (17.9% โ 56.9%)
- ๊ธฐ์กด ํ์ธํ๋ + verifier ๋ฐฉ์์ SOTA (55%)๋ฅผ ๋ฅ๊ฐ
- ์ฌ๋ฌ ๋ฒค์น๋งํฌ์์ ์๋ก์ด SOTA ๋ฌ์ฑ
3. ํด์ ๊ฐ๋ฅ์ฑ ํฅ์
- ๋ชจ๋ธ์ ์ถ๋ก ๊ณผ์ ์ ํฌ๋ช ํ๊ฒ ๊ด์ฐฐ ๊ฐ๋ฅ
- ์ค๋ฅ ๋๋ฒ๊น ๋ฐ ๊ฐ์ ๋ฐฉํฅ ๋์ถ ์ฉ์ด
- ๋ธ๋๋ฐ์ค ๋ฌธ์ ์ผ๋ถ ํด์
4. ๋ฒ์ฉ์ ์ ์ฉ์ฑ
- ์ฐ์ , ์์, ๊ธฐํธ ์ถ๋ก ๋ฑ ๋ค์ํ ํ์คํฌ์ ์ ์ฉ ๊ฐ๋ฅ
- ์ธ๊ฐ์ด ์ธ์ด๋ก ํด๊ฒฐํ ์ ์๋ ๋ชจ๋ ๋ฌธ์ ์ ํ์ฅ ๊ฐ๋ฅ
- ๋ค์ํ ๋๋ฉ์ธ์ ์ผ๋ฐํ
5. ํ์ ์ ๊ธฐ์ฌ
- ์๋ก์ด ํ๋กฌํํ ํจ๋ฌ๋ค์ ์ ์
- Emergent Ability ๋ฐ๊ฒฌ: ๋ชจ๋ธ ๊ท๋ชจ์ ๋ฐ๋ฅธ ์ถ๋ก ๋ฅ๋ ฅ์ ์ฐฝ๋ฐ์ ์ถํ ์ ์ฆ
- ํ์ ์ฐ๊ตฌ์ ๊ธฐ๋ฐ: Zero-shot CoT, Self-Consistency, Tree-of-Thoughts ๋ฑ ์ด๋ฐ
- Scaling Law ํ์ฅ: ๋จ์ ์ค์ผ์ผ๋ง์ด ์๋ ํ๋กฌํํ ๋ฐฉ์์ ์ค์์ฑ ๊ฐ์กฐ
โ ๏ธ ํ๊ณ์ ๋ฐ ํฅํ ์ฐ๊ตฌ
์ฃผ์ ํ๊ณ์
1. ๋๊ท๋ชจ ๋ชจ๋ธ ์์กด์ฑ
- 100B+ ํ๋ผ๋ฏธํฐ ๋ชจ๋ธ์์๋ง ํจ๊ณผ ๋ฐํ
- ์ํ ๋ชจ๋ธ์ ์ ์ฐฝํ์ง๋ง ๋ ผ๋ฆฌ์ ์ด์ง ์์ ์ถ๋ก ์ฒด์ธ ์์ฑ
- ์ํ ๋ชจ๋ธ์์๋ ์คํ๋ ค ์ฑ๋ฅ ์ ํ ๊ฐ๋ฅ
2. ์ถ๋ก ์ ์ ํ์ฑ ๋ฏธ๋ณด์ฅ
- CoT๊ฐ ํญ์ ์ฌ๋ฐ๋ฅธ ์ถ๋ก ์ ์์ฑํ์ง ์์
- ๊ทธ๋ด๋ฏํด ๋ณด์ด์ง๋ง ํ๋ฆฐ ์ถ๋ก ๊ฒฝ๋ก ๊ฐ๋ฅ
- Faithfulness ๋ฌธ์ : ์ต์ข ๋ต์ด ์ถ๋ก ๊ณผ์ ๊ณผ ๋ถ์ผ์นํ ์ ์์
3. ๊ณ์ฐ ๋น์ฉ ์ฆ๊ฐ
- ๋๊ท๋ชจ ๋ชจ๋ธ ํ์๋ก ์ธํ ๋์ ์ถ๋ก ๋น์ฉ
- ๊ธด ์ถ๋ ฅ ์์ฑ์ผ๋ก ์ธํ ์ง์ฐ ์๊ฐ ์ฆ๊ฐ
- ํ ํฐ ๋น์ฉ ์ฆ๊ฐ
4. ์๋ ์์ ์์ฑ ํ์
- Few-shot ์์๋ฅผ ์๋์ผ๋ก ์์ฑํด์ผ ํจ
- ๊ณผ์ ๋ณ ์ต์ ์ ์์ ์ ์ ์ด ์ด๋ ค์
- ์ด๋ ธํ ์ด์ ๋น์ฉ (๋๊ท๋ชจ ์ ์ฉ ์)
5. ๊ทผ๋ณธ์ ์ง๋ฌธ
- ๋ชจ๋ธ์ด ์ง์ ์ผ๋ก “์ถ๋ก ”ํ๋์ง, ํจํด ๋งค์นญ์ธ์ง ๋ ผ์ ์ค
- CoT๊ฐ ์ธ๊ฐ์ ์ฌ๊ณ ๋ฅผ ๋ชจ๋ฐฉํ์ง๋ง, ์ค์ “์ดํด”์ธ์ง ๋ถ๋ช ํ
์ด๋ฆฐ ์ง๋ฌธ๋ค
- ๋ชจ๋ธ ๊ท๋ชจ ์ฆ๊ฐ์ ๋ฐ๋ผ ์ถ๋ก ๋ฅ๋ ฅ์ด ์ผ๋ง๋ ๋ ํฅ์๋ ์ ์์๊น?
- ์ด๋ค ํ๋กฌํํ ๋ฐฉ๋ฒ์ด LLM์ด ํด๊ฒฐํ ์ ์๋ ํ์คํฌ ๋ฒ์๋ฅผ ํ์ฅํ ์ ์์๊น?
- CoT๋ฅผ ์ํ ๋ชจ๋ธ์์๋ ํจ๊ณผ์ ์ผ๋ก ๋ง๋ค ์ ์์๊น?
๐ ๊ด๋ จ ๋ ผ๋ฌธ
์ ํ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ํต์ฌ ๋ด์ฉ |
|---|---|
| Scratchpad (Nye et al., 2021) | ์ค๊ฐ ๊ณ์ฐ์ ์ํ ์คํฌ๋์นํจ๋ ๊ฐ๋ |
| Rationale-Augmented Training | ์ถ๋ก ๊ณผ์ ์ ํฌํจํ ํ์ต ๋ฐ์ดํฐ ํ์ฉ |
ํต์ฌ ํ์ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ํต์ฌ ๋ด์ฉ | ์ฐ๋ |
|---|---|---|
| Zero-shot CoT (Kojima et al.) | “Let’s think step by step” ํ ๋ฌธ์ฅ์ผ๋ก CoT ์ ๋ | 2022 |
| Self-Consistency (Wang et al.) | ๋ค์ํ ์ถ๋ก ๊ฒฝ๋ก ์ํ๋ง ํ ๋ค์๊ฒฐ ํฌํ | 2022 |
| Auto-CoT (Zhang et al.) | LLM์ผ๋ก CoT ์์ ์๋ ์์ฑ | 2022 |
| Least-to-Most Prompting | ๋ฌธ์ ๋ฅผ ํ์ ๋ฌธ์ ๋ก ๋ถํดํ์ฌ ํด๊ฒฐ | 2022 |
ํ์ฅ ์ฐ๊ตฌ๋ค
| ๋ ผ๋ฌธ | ํต์ฌ ๋ด์ฉ |
|---|---|
| Tree of Thoughts (ToT) | ์ฌ๋ฌ ์ถ๋ก ๊ฒฝ๋ก๋ฅผ ํธ๋ฆฌ ๊ตฌ์กฐ๋ก ํ์ |
| Graph of Thoughts (GoT) | ๊ทธ๋ํ ๊ตฌ์กฐ๋ก ์ถ๋ก ํ์ฅ |
| ReAct | ์ถ๋ก (Reasoning)๊ณผ ํ๋(Acting)์ ๊ฒฐํฉ |
| Reflexion | ์๊ธฐ ๋ฐ์ฑ์ ํตํ ์ถ๋ก ๊ฐ์ |
| PAL (Program-Aided LM) | ์ฝ๋ ์์ฑ์ ํตํ ์ถ๋ก |
๊ด๋ จ ๊ฐ๋
- Few-shot Learning: ์์์ ์์๋ก ์ ๊ณผ์ ์ํ
- Prompt Engineering: ์ต์ ์ ํ๋กฌํํธ ์ค๊ณ
- In-context Learning: ์ปจํ ์คํธ ๋ด ํ์ต
- Emergent Abilities: LLM์ ์ฐฝ๋ฐ์ ๋ฅ๋ ฅ
๐ป ์ค๋ฌด ์ ์ฉ ํฌ์ธํธ
์ธ์ CoT๋ฅผ ์ฌ์ฉํด์ผ ํ๋๊ฐ?
| ์กฐ๊ฑด | ๊ถ์ฅ ์ฌํญ |
|---|---|
| ๋ค๋จ๊ณ ์ถ๋ก ํ์ | CoT ์ ๊ทน ํ์ฉ |
| ๋๊ท๋ชจ ๋ชจ๋ธ (100B+) ์ฌ์ฉ | CoT ํจ๊ณผ์ |
| ์ํ/๋ ผ๋ฆฌ ๋ฌธ์ | CoT ๊ฐ๋ ฅ ์ถ์ฒ |
| ๋จ์ ํ๋ ๋จ๊ณ ๋ฌธ์ | ํ์ค ํ๋กฌํํ ์ผ๋ก ์ถฉ๋ถ |
| ์๊ท๋ชจ ๋ชจ๋ธ | CoT ํจ๊ณผ ์ ํ์ |
CoT ํ๋กฌํํธ ์์ฑ ๊ฐ์ด๋
1. ๊ธฐ๋ณธ ๊ตฌ์กฐ
๋น์ ์ ๋ฌธ์ ๋ฅผ ๋จ๊ณ๋ณ๋ก ํ์ด๋๊ฐ๋ ์ ๋ฌธ๊ฐ์
๋๋ค.
์์ 1:
Q: [์ง๋ฌธ]
A: [๋จ๊ณ 1]. [๋จ๊ณ 2]. [๋จ๊ณ 3]. ๋ฐ๋ผ์ ๋ต์ [๋ต]์
๋๋ค.
์์ 2:
Q: [์ง๋ฌธ]
A: [๋จ๊ณ 1]. [๋จ๊ณ 2]. ๋ฐ๋ผ์ ๋ต์ [๋ต]์
๋๋ค.
์ค์ ๋ฌธ์ :
Q: [์๋ก์ด ์ง๋ฌธ]
A:
2. ํจ๊ณผ์ ์ธ CoT ์์ ์์ฑ ํ
| ์์น | ์ค๋ช |
|---|---|
| ๋ช ํํ ๋จ๊ณ | ๊ฐ ์ถ๋ก ๋จ๊ณ๋ฅผ ๋ช ํํ ๊ตฌ๋ถ |
| ์์ฐ์ค๋ฌ์ด ์ธ์ด | ๊ธฐ๊ณ์ ์ด์ง ์์ ์์ฐ์ค๋ฌ์ด ์ค๋ช |
| ์ค๊ฐ ๊ณ์ฐ ํฌํจ | ์ซ์ ๋ฌธ์ ์ ๊ฒฝ์ฐ ๊ณ์ฐ ๊ณผ์ ๋ช ์ |
| ๋ค์ํ ์์ | ๋ค์ํ ์ ํ์ ๋ฌธ์ ํฌํจ |
| ์ ์ ํ ๊ธธ์ด | ๋๋ฌด ๊ธธ๊ฑฐ๋ ์งง์ง ์๊ฒ |
3. Python ๊ตฌํ ์์
import openai
def create_cot_prompt(question: str) -> str:
"""Chain-of-Thought ํ๋กฌํํธ ์์ฑ"""
exemplars = """
Q: Jason had 20 lollipops. He gave Denny some lollipops. Now Jason has 12 lollipops.
How many lollipops did Jason give to Denny?
A: Jason started with 20 lollipops. He now has 12 lollipops.
So he gave away 20 - 12 = 8 lollipops. The answer is 8.
Q: There are 15 trees in the grove. Grove workers will plant trees today.
After they are done, there will be 21 trees. How many trees did the workers plant?
A: There were 15 trees originally. After planting there are 21 trees.
So the workers planted 21 - 15 = 6 trees. The answer is 6.
Q: Shawn has five toys. For Christmas, he got two toys each from his mom and dad.
How many toys does he have now?
A: Shawn started with 5 toys. He got 2 toys from mom and 2 from dad,
which is 2 + 2 = 4 toys. So now he has 5 + 4 = 9 toys. The answer is 9.
"""
prompt = f"{exemplars}\nQ: {question}\nA:"
return prompt
def solve_with_cot(question: str, model: str = "gpt-4") -> dict:
"""CoT๋ฅผ ํ์ฉํ ๋ฌธ์ ํด๊ฒฐ"""
prompt = create_cot_prompt(question)
response = openai.ChatCompletion.create(
model=model,
messages=[{"role": "user", "content": prompt}],
temperature=0, # Greedy decoding
max_tokens=256
)
output = response.choices[0].message.content
# ๋ต๋ณ ํ์ฑ
reasoning = output.rsplit("The answer is", 1)[0].strip()
answer = output.rsplit("The answer is", 1)[-1].strip().rstrip(".")
return {
"question": question,
"reasoning": reasoning,
"answer": answer,
"full_output": output
}
4. Zero-shot CoT ๊ตฌํ
def zero_shot_cot(question: str) -> str:
"""Zero-shot CoT - ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ"""
return f"{question}\n\nLet's think step by step."
# ํ๊ตญ์ด ๋ฒ์
def zero_shot_cot_kr(question: str) -> str:
return f"{question}\n\n๋จ๊ณ๋ณ๋ก ์๊ฐํด๋ด
์๋ค."
5. Self-Consistency ๊ตฌํ
import collections
def self_consistency(question: str, n_samples: int = 5) -> str:
"""Self-Consistency๋ฅผ ํตํ ๋ต๋ณ ์ ๋ขฐ๋ ํฅ์"""
answers = []
for _ in range(n_samples):
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "user", "content": create_cot_prompt(question)}],
temperature=0.7, # ๋ค์์ฑ์ ์ํ temperature
max_tokens=256
)
output = response.choices[0].message.content
answer = extract_answer(output)
answers.append(answer)
# ๋ค์๊ฒฐ๋ก ์ต์ข
๋ต ์ ํ
counter = collections.Counter(answers)
final_answer = counter.most_common(1)[0][0]
return final_answer
ํ๊ตญ์ด CoT ์์
์ง๋ฌธ: ์ฒ ์๋ ์ฌ๊ณผ 5๊ฐ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ํฌ์๊ฒ 2๊ฐ๋ฅผ ์ฃผ๊ณ ,
์ด๋จธ๋๊ป 3๊ฐ๋ฅผ ๋ ๋ฐ์์ต๋๋ค. ์ฒ ์๊ฐ ๊ฐ์ง ์ฌ๊ณผ๋ ๋ช ๊ฐ์ผ๊น์?
ํ์ด: ์ฒ ์๋ ์ฒ์์ ์ฌ๊ณผ 5๊ฐ๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.
์ํฌ์๊ฒ 2๊ฐ๋ฅผ ์ฃผ์์ผ๋ฏ๋ก 5 - 2 = 3๊ฐ๊ฐ ๋จ์ต๋๋ค.
์ด๋จธ๋๊ป 3๊ฐ๋ฅผ ๋ ๋ฐ์์ผ๋ฏ๋ก 3 + 3 = 6๊ฐ๊ฐ ๋ฉ๋๋ค.
๋ฐ๋ผ์ ๋ต์ 6๊ฐ์
๋๋ค.
์ค๋ฌด ์ ์ฉ ์ ์ฃผ์์ฌํญ
- ๋ชจ๋ธ ํฌ๊ธฐ ๊ณ ๋ ค: GPT-4, Claude, Gemini ๋ฑ ๋๊ท๋ชจ ๋ชจ๋ธ์์ ํจ๊ณผ์
- ํ ํฐ ๋น์ฉ ๊ด๋ฆฌ: ์ถ๋ก ๋จ๊ณ๋ก ์ธํ ์ถ๋ ฅ ํ ํฐ ์ฆ๊ฐ ๊ณ ๋ ค
- ๋๋ฉ์ธ๋ณ ์์ ์ค๋น: ํ์คํฌ์ ๋ง๋ ๊ณ ํ์ง CoT ์์ ์ค๋น
- Self-Consistency ํ์ฉ: ์ค์ํ ๊ฒฐ์ ์๋ ๋ค์ค ์ํ๋ง ๊ณ ๋ ค
- ์ถ๋ ฅ ํ์ฑ: “The answer is” ๊ฐ์ ๋ง์ปค๋ก ์ต์ข ๋ต ์ถ์ถ
๐ท๏ธ Tags
#ChainOfThought #CoT #Prompting #Reasoning #LLM #NeurIPS2022 #GoogleBrain #EmergentAbility #ArithmeticReasoning #CommonsenseReasoning #SymbolicReasoning #PromptEngineering #FewShotLearning #InContextLearning #GSM8K #PaLM #GPT3 #SelfConsistency #ZeroShotCoT #AIAgent