LLM-SR

deep-symbolic-mathematicsMIT长期未更新

用大语言模型做科学方程发现和符号回归的官方实现,把公式搜索交给 LLM 智能体,从数据里自动找出可解释的数学表达式。

[ICLR 2025 Oral] This is the official repo for the paper "LLM-SR" on Scientific Equation Discovery and Symbolic Regression with Large Language Models

暂无版本283star54fork同步于 2026-11-07 07:29 UTC

怎么上手

由 README 提炼,执行前请确认
conda create -n llmsr python=3.11.7
conda activate llmsr
pip install -r requirements.txt
硬件要求按 README 说明

本地运行需 GPU 部署 Hugging Face 模型,可用 quantization 及 load_in_4bit/load_in_8bit 控制量化;README 未给出具体显存数值。也可改用 OpenAI API 免本地 GPU。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 LLM 生成程序骨架并结合进化搜索,从数据中发现可解释的科学方程

用大语言模型做科学方程发现和符号回归的官方实现,把公式搜索交给 LLM 智能体,从数据里自动找出可解释的数学表达式。

核心能力

  • 把方程表示为程序骨架,由 LLM 生成候选假设
  • 结合进化搜索迭代筛选方程
  • 支持 numpy+scipy BFGS 与 torch+Adam 两种模板
  • 可接本地开源模型或 OpenAI GPT API
  • 提供物理、生物、材料科学基准数据集

容易踩的坑

本地运行需先启动 llm_engine 服务,并把 sampler.py 里的端口改成与服务器一致;用 API 模式需先 export API_KEY 并加 --use_api True;problem_name 只能用 README 列出的 oscillator1、oscillator2、bactgrow、stressstrain。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

0 个版本

暂无 release 数据(可能没有发版,或尚未同步)。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    LLM-SR: Scientific Equation Discovery and Symbolic Regression via Programming with LLMs

    Paper Data GitHub Repo stars

    Official Implementation of paper LLM-SR: Scientific Equation Discovery via Programming with Large Language Models (ICLR 2025 Oral).

    Updates

    Overview

    In this paper, we introduce LLM-SR, a novel approach for scientific equation discovery and symbolic regression that leverages strengths of Large Language Models (LLMs). LLM-SR combines LLMs' scientific knowledge and code generation capabilities with evolutionary search to discover accurate and interpretable equations from data. The method represents equations as program skeletons, allowing for flexible hypothesis generation guided by domain-specific priors. Experiments on custom benchmark problems across physics, biology, and materials science demonstrate LLM-SR's superior performance compared to state-of-the-art symbolic regression methods, particularly in out-of-domain generalization. The paper also highlights the limitations of common benchmarks and proposes new, challenging datasets for evaluating LLM-based equation discovery methods.

    LLMSR-viz

    Installation

    To run the code, create a conda environment and install the dependencies provided in the requirements.txt or environment.yml:

    conda create -n llmsr python=3.11.7
    conda activate llmsr
    pip install -r requirements.txt
    

    or

    conda env create -f environment.yml
    conda activate llmsr
    

    Note: Requires Python ≥ 3.9

    Datasets

    Benchmark datasets studied in this paper are provided in the data/ directory. For details on datasets and generation settings, please refer to paper.

    Local Runs (Open-Source LLMs)

    Start the local LLM Server

    First, start the local LLM engine from huggingface models by using the bash run_server.sh script or running the following command:

    cd llm_engine
    
    python engine.py --model_path mistralai/Mixtral-8x7B-Instruct-v0.1 \
                        --gpu_ids [GPU_ID]  \
                        --port [PORT_ID] --quantization
    
    • Set gpu_ids and port parameters based on your server availability

    • Change model_path to use a different open-source model from Hugging Face

    • quantization activates efficient inference of LLM with quantization on GPUs

    • Control quantization level with load_in_4bit and load_in_8bit parameters in engine.py

    Run LLM-SR on Local Server

    After activating the local LLM server, run the LLM-SR framework on your dataset with the run_llmsr.sh script or running the following command:

    python main.py --problem_name [PROBLEM_NAME] \
                       --spec_path [SPEC_PATH] \
                       --log_path [LOG_PATH]
    
    • Update the port id in the url in sampler.py to match the LLM server port

    • problem_name refers to the target problem and dataset in data/

    • spec_path refers to the initial prompt specification file path in spec/

    • Available problem names for datasets: oscillator1, oscillator2, bactgrow, stressstrain

    For more example scripts, check run_llmsr.sh.

    API Runs (Closed LLMs)

    To run LLM-SR with the OpenAI GPT API, use the following command:

    export API_KEY=[YOUR_API_KEY_HERE]
    
    python main.py --use_api True \
                       --api_model "gpt-3.5-turbo" \
                       --problem_name [PROBLEM_NAME] \
                       --spec_path [SPEC_PATH] \
                       --log_path [LOG_PATH]
    
    • Replace [YOUR_API_KEY_HERE] with your actual OpenAI API key to set your API key as an environment variable.

    • --use_api True: Enables the use of the OpenAI API instead of local LLMs from Hugging Face

    • --api_model: Specifies the GPT model to use (e.g., "gpt-3.5-turbo", "gpt-4o")

    • --problem_name, --spec_path, --log_path: Set these as in the local runs section

    Runs with Torch Hypothesis Optimizer

    Most specifications in specs/ use equation program skeleton in numpy templates with scipy BFGS optimizer. LLM-SR can also leverage direct and differentiable optimizers for equation discovery. We provide specifications for the Oscillation 2 example using torch templates with Adam optimizer here.

    Note: We observed slightly better performance from numpy+BFGS compared to torch+Adam, mainly due to better proficiency of current LLM backbones in numpy generation.

    Configuration

    The above commands use default pipeline parameters. To change parameters for experiments, refer to config.py.

    Citation

    Read our paper for more information about the setup (or contact us ☺️)). If you find our paper or the repo helpful, please cite us with

    Star History

    Star History Chart

    License

    This repository is licensed under MIT licence.

    This work is built on top of other open source projects, including FunSearch, PySR, and Neural Symbolic Regression that scales. We thank the original contributors of these works for open-sourcing their valuable source codes.

    Contact Us

    For any questions or issues, you are welcome to open an issue in this repo, or contact us at [email protected], and [email protected] .