In Context Learning and Reasoning for Symbolic Regression with Large Language Models
Samiha Sharlin, Tyler R. Josephson
TL;DR
This work investigates using large language models (LLMs) for symbolic regression by combining in-context learning with data- and theory-driven prompts and an external optimization loop. The proposed two-prompt, scratchpad-enabled workflow allows LLMs to propose symbolic expressions, which are then numerically optimized by SciPy and fed back for refinement, enabling iterative improvement toward accurate and parsimonious equations. Across multiple scientific datasets, GPT-4 and GPT-4o can rediscover several known laws, with performance boosted by including scientific context and stepwise scratchpad reasoning, though they struggle on noisier, larger datasets and do not outperform specialized SR methods on more complex targets. The study demonstrates that natural-language interfaces can facilitate theory-data integration and broaden accessibility to symbolic regression, while highlighting trade-offs related to data quality, computational cost, and prompt design; future work may leverage retrieval augmentation and more robust evaluation to enhance scalability and reliability.
Abstract
Large Language Models (LLMs) are transformer-based machine learning models that have shown remarkable performance in tasks for which they were not explicitly trained. Here, we explore the potential of LLMs to perform symbolic regression -- a machine-learning method for finding simple and accurate equations from datasets. We prompt GPT-4 to suggest expressions from data, which are then optimized and evaluated using external Python tools. These results are fed back to GPT-4, which proposes improved expressions while optimizing for complexity and loss. Using chain-of-thought prompting, we instruct GPT-4 to analyze the data, prior expressions, and the scientific context (expressed in natural language) for each problem before generating new expressions. We evaluated the workflow in rediscovery of five well-known scientific equations from experimental data, and on an additional dataset without a known equation. GPT-4 successfully rediscovered all five equations, and in general, performed better when prompted to use a scratchpad and consider scientific context. We demonstrate how strategic prompting improves the model's performance and how the natural language interface simplifies integrating theory with data. We also observe how theory can sometimes offset noisy data and, in other cases, data can make up for poor context. Although this approach does not outperform established SR programs where target equations are more complex, LLMs can nonetheless iterate toward improved solutions while following instructions and incorporating scientific context in natural language.
