Capítulo 1: Chain-of-Thought Prompting
🎯 Objetivos de aprendizaje
- Comprender qué es el Chain-of-Thought prompting
- Aplicar CoT a matemáticas, lógica y razonamiento complejo
- Usar "Pensemos paso a paso" y otros disparadores similares
- Saber cuándo CoT es útil y cuándo es innecesario
¿Qué es Chain-of-Thought?
El Chain-of-Thought (CoT) prompting anima a la IA a mostrar su proceso de razonamiento paso a paso, en lugar de saltar directamente a una respuesta.
El problema de las respuestas directas
Standard Prompt:
"If John has 3 apples and gives away half, then buys 5 more,
how many does he have?"
AI might answer: "6.5 apples" (incorrect, rushed calculation)
La solución CoT
CoT Prompt:
"If John has 3 apples and gives away half, then buys 5 more,
how many does he have? Let's think through this step by step."
AI answer:
Step 1: John starts with 3 apples
Step 2: He gives away half: 3 ÷ 2 = 1.5 apples given away
Step 3: He keeps: 3 - 1.5 = 1.5 apples
Step 4: He buys 5 more: 1.5 + 5 = 6.5 apples
Answer: 6.5 apples
Wait, that seems odd. Let me reconsider...
If "gives away half" means half of what he has: 3/2 = 1.5
He keeps 1.5, buys 5 more = 6.5 apples ✓
Disparadores CoT
Disparadores simples
"Let's think step by step."
"Let's work through this carefully."
"Think about this step by step."
"Break this down logically."
"Let's reason through this."
CoT estructurado
"Solve this problem:
1. First, identify what we know
2. Then, determine what we need to find
3. Show each calculation step
4. Verify the answer makes sense"
Cuándo usar CoT
| Usar CoT para | Omitir CoT para |
|---|---|
| Problemas matemáticos | Preguntas fácticas simples |
| Acertijos lógicos | Escritura creativa |
| Razonamiento de varios pasos | Solicitudes de definiciones |
| Análisis complejo | Tareas directas |
| Toma de decisiones | Resúmenes rápidos |
Ejemplos de CoT
Problema matemático
Problem: A train travels from City A to City B at 60 mph.
The return trip is at 40 mph. The total distance is
240 miles (one way). What's the average speed for
the round trip?
Let's solve this step by step:
Step 1: Calculate time for first trip
- Distance: 240 miles
- Speed: 60 mph
- Time = 240/60 = 4 hours
Step 2: Calculate time for return trip
- Distance: 240 miles
- Speed: 40 mph
- Time = 240/40 = 6 hours
Step 3: Calculate total distance and time
- Total distance: 240 + 240 = 480 miles
- Total time: 4 + 6 = 10 hours
Step 4: Calculate average speed
- Average speed = Total distance / Total time
- Average speed = 480/10 = 48 mph
Answer: 48 mph (not 50 mph as simple average would suggest!)
Razonamiento lógico
Problem: All roses are flowers. Some flowers fade quickly.
Can we conclude that some roses fade quickly?
Let's think through this logically:
1. Statement 1: All roses are flowers
- Every rose is a flower
- But not every flower is a rose
2. Statement 2: Some flowers fade quickly
- There exist flowers that fade quickly
- We don't know which flowers
3. Analysis:
- The flowers that fade quickly could be roses
- OR they could be other flowers (tulips, etc.)
- We have no information linking roses specifically
4. Conclusion: No, we cannot conclude that some roses
fade quickly. The flowers that fade might be other
types of flowers, not roses.
Zero-Shot vs Few-Shot CoT
Zero-Shot CoT
Simplemente agregue la frase disparadora:
"[Problem] Let's think step by step."
Few-Shot CoT
Proporcione ejemplos con razonamiento:
Example 1:
Q: If a shirt costs $20 and is 25% off, what's the price?
A: Let's think step by step.
- Original price: $20
- Discount: 25% of $20 = $5
- Final price: $20 - $5 = $15
Example 2:
Q: If a shirt costs $30 and is 20% off, what's the price?
A: Let's think step by step.
- Original price: $30
- Discount: 20% of $30 = $6
- Final price: $30 - $6 = $24
Now solve:
Q: If a shirt costs $45 and is 30% off, what's the price?
A:
Puntos clave
Summary
- El CoT prompting muestra los pasos del razonamiento, mejorando la precisión
- Use disparadores como "Pensemos paso a paso"
- Es ideal para matemáticas, lógica y razonamiento complejo
- Puede ser zero-shot (solo disparador) o few-shot (con ejemplos)
- Verifique que el razonamiento tenga sentido