Benchmarking ChatGPT on Algorithmic Reasoning

Sean McLeish, Avi Schwarzschild, Tom GoldsteinarXiv 2024

Abstract

We evaluate ChatGPT's ability to solve algorithm problems from the CLRS benchmark suite that is designed for GNNs. The benchmark requires the use of a specified classical algorithm to solve a given problem. We find that ChatGPT outperforms specialist GNN models, using Python to successfully solve these problems. This raises new points in the discussion about learning algorithms with neural networks and how we think about what out of distribution testing looks like with web scale training data.

Introduction

Algorithmic reasoning—the execution of logical steps to solve problems like sorting or finding shortest paths—has traditionally been a significant challenge for neural networks. Specialized architectures, such as Graph Neural Networks (GNNs), were developed to address these tasks, exemplified by the CLRS benchmark suite. This study investigates whether a general-purpose Large Language Model (LLM), specifically GPT-4 with Code Interpreter, can surpass these specialized models. Furthermore, it explores how the ubiquity of these algorithms in web-scale training data affects our understanding of "out-of-distribution" testing.

Methods

The evaluation utilized ChatGPT (gpt-4-preview-1106) equipped with a Code Interpreter. This setup allows the model to parse natural language problem descriptions, translate input data (often provided as arrays or one-hot encodings), write Python scripts to implement the required algorithms, and execute them to produce results. This "tool-use" approach offloads logical execution to a deterministic environment, mitigating the "hallucinations" common in text-only reasoning.

The researchers used a zero-shot approach on the CLRS Benchmark Suite, which includes 30 algorithms across categories such as Sorting & Searching, Graphs, Dynamic Programming, and Geometry. To facilitate this, the authors developed CLRS4LM, a version of the dataset adapted for LLM testing.

Results

ChatGPT demonstrated significant superiority, outperforming state-of-the-art GNNs on 24 out of 30 tasks. It achieved near-perfect F1 scores on complex graph and sorting tasks like Topological Sort and Quickselect.

F1 scores comparing ChatGPT with specialized neural algorithmic reasoners across the CLRS benchmark.

A key finding is that ChatGPT's success stems from its ability to use Python as a tool, bridging the gap between probabilistic prediction and exact execution. While GNNs are data-efficient specialists, GPT-4’s broad exposure to code allows it to generalize across the entire benchmark without task-specific tuning. However, performance was notably lower on Dynamic Programming (DP) tasks, such as Matrix Chain Order, where the model struggled with specific intermediate output formatting required by the benchmark.

Discussion and Limitations

The study highlights a shift in the definition of "out-of-distribution" testing. Since GPT-4 was likely trained on the algorithms in the CLRS textbook, traditional testing boundaries are blurred. Additionally, the model's struggles with DP suggest that abstract data manipulations, like filling complex 2D tables, remain challenging even with code execution.

Accuracy counts and failure classifications for ChatGPT on test and train datasets, highlighting infrastructure and logic failures.

Infrastructure fragility also played a role; failures often resulted from non-algorithmic issues like file-access errors or execution timeouts. While GPT-4 is highly accurate, it remains computationally expensive compared to specialized GNNs, which may still be preferable in resource-constrained environments. Future work could explore multi-turn reasoning to further improve performance by allowing the model to correct its own errors.

Summary updated

BibTeX
@misc{mcleish2024benchmarking,
  author = {Sean McLeish and Avi Schwarzschild and Tom Goldstein},
  title = {{Benchmarking ChatGPT on Algorithmic Reasoning}},
  year = {2024},
  eprint = {2404.03441},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2404.03441},
}
Figure