Large Language Models as Analogical Reasoners

Michihiro Yasunaga, Xinyun Chen, Yujia Li, Panupong Pasupat, Jure Leskovec, Percy Liang, Ed H. Chi, Denny Zhou

TL;DR

Analogical prompting is a novel technique that enables Large Language Models (LLMs) to self-generate their own relevant examples and "tutorials" before solving a complex problem. By mimicking the human cognitive process of drawing on past experiences, this method outperforms standard Chain-of-Thought (CoT) prompting without requiring any manually labeled data or external retrieval systems.

The Gap in Chain-of-Thought Prompting

While Chain-of-Thought (CoT) prompting has significantly boosted LLM performance on complex reasoning tasks, it typically falls into two distinct camps, both of which have notable drawbacks:

  1. 0-shot CoT: Uses generic instructions like "think step by step." While easy to implement, this guidance is often too broad for specialized tasks like competitive programming or advanced mathematics.
  2. Few-shot CoT: Provides manually labeled examples in the prompt. This is labor-intensive to create, and the static examples provided may not be relevant to the specific nuances of the new problem being asked.

Retrieval-based methods attempt to solve this by pulling examples from a database, but they require external infrastructure and a pre-existing library of labeled solutions. The challenge is to provide the model with tailored, high-quality reasoning guidance automatically.

Introducing Analogical Prompting

To bridge this gap, the authors introduce Analogical Prompting. This approach instructs the LLM to recall and solve related problems (analogies) in-context before tackling the target problem.

Comparison of prompting methods: 0-shot, Few-shot CoT, and Analogical Prompting.

Instead of relying on a human to provide relevant examples, the model is prompted to "Recall three relevant and distinct problems" and provide their solutions. This forces the model to surface its internal knowledge of problem-solving patterns.

Key components of this method include:

  • Self-Generated Exemplars: The model surfaces its own relevant examples, acting as a specialized in-context learning trigger.
  • Self-Generated Knowledge (Tutorials): For highly complex tasks like coding, the model is instructed to identify core algorithms and write a brief "tutorial" on them before generating exemplars.
  • Single-Pass Execution: Unlike multi-step agentic workflows, this method operates in a single prompt. The model generates the knowledge, the exemplars, and the final solution in one continuous response.
  • Diversity Encouragement: The prompt explicitly asks for "distinct" problems to prevent the model from generating repetitive or trivial examples.

Key Insights

  • LLMs as Their Own Teachers: Modern LLMs already contain the necessary reasoning patterns in their weights; they just need a "warm-up" to activate the right circuits. Explicitly recalling an analogy serves this exact purpose.
  • Tailoring Beats Generality: Unlike fixed few-shot examples, self-generated analogies are dynamically tailored to the specific geometry, logic, or algorithmic requirements of the test problem.
  • The Power of Tutorials: For coding, high-level conceptual knowledge (the "tutorial") is more effective than low-level code examples alone. It helps the model identify the underlying logic rather than just matching surface-level text.
  • Scaling Synergy: Analogical prompting shows a "rich get richer" effect. As models get larger and more capable (e.g., moving from GPT-3.5 to GPT-4), their ability to generate useful analogies improves, leading to higher performance gains.

Experimental Results

The researchers evaluated the method across several demanding reasoning benchmarks, including GSM8K (elementary math), MATH (advanced high school math), Codeforces (competitive programming), and BIG-Bench (diverse logic tasks).

Accuracy on GSM8K and MATH benchmarks comparing Analogical Prompting to baselines.

The method consistently outperformed 0-shot and few-shot baselines across the board:

  • Mathematics: On the difficult MATH dataset, analogical prompting achieved 37.3% accuracy with GPT-3.5-turbo, compared to 33.9% for 0-shot CoT and 34.9% for 5-shot CoT.
  • Coding: On Codeforces, the "Knowledge + Exemplars" approach boosted GPT-4's Acc@1 from 16% (0-shot) to 19%, and GPT-3.5's from 9% to 15%.
  • Logic: Across BIG-Bench tasks, the method achieved an average accuracy gain of +4% over baselines.
  • Generation vs. Retrieval: Interestingly, for large models, self-generating examples actually worked better than retrieving "real" examples from a training set, likely because the generated examples were more precisely tailored to the query.

Limitations and Future Work

While powerful, Analogical Prompting does come with trade-offs. Because the model generates several "practice" problems before the real one, the token count per query is significantly higher, increasing both cost and latency.

Furthermore, this technique is highly model-dependent. It is less effective on smaller or weaker models that struggle to generate valid analogies, which can sometimes lead to "misdirection" if the generated exemplar is incorrect. Future work may explore ways to generate more diverse exemplars and investigate how this approach might integrate with self-correction or self-consistency techniques.

Summary updated

BibTeX
@inproceedings{yasunaga2024large,
  author = {Michihiro Yasunaga and Xinyun Chen and Yujia Li and Panupong Pasupat and Jure Leskovec and Percy Liang and Ed H. Chi and Denny Zhou},
  title = {{Large Language Models as Analogical Reasoners}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=AgDICX1h50},
}
Figure