Skip to main content

⚡Flash-ANSR:
Fast Amortized Neural Symbolic Regression

PyPI version PyPI license Documentation Status

pytest quality checks CodeQL Advanced

Flash-ANSR is a library for amortized neural symbolic regression: load a pretrained model, call fit(X, y), and recover a symbolic expression for your tabular data, or train your own model. It is built for fast, ready-to-use inference.

Publications

Usage

Requires Python >= 3.12.

pip install flash-ansr
flash_ansr install psaegert/flash-ansr-v25.0-T7-3M   # the reference checkpoint (see "Models")
import torch
import numpy as np
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# Import flash_ansr
from flash_ansr import (
  FlashANSR,
  SoftmaxSamplingConfig,
)

# The installed checkpoint directory
from flash_ansr import get_path
CHECKPOINT = get_path("models", "psaegert/flash-ansr-v25.0-T7-3M")

# Load the model (KV-cache, auto-batching and static decoding are on by default; see "Inference speed")
model = FlashANSR.load(
  directory=CHECKPOINT,
  generation_config=SoftmaxSamplingConfig(choices=1024),
  # Candidate ranking (default): log10(FVU) + 1e-2 per bit of the refined expression's description
  # length. Alternatives: ranking_mode="weighted" with ranking_weights={"n_nodes": 0.05}, or
  # ranking_mode="pareto" with ranking_metrics=("fvu", "n_nodes").
  ranking_mode="mdl",
).to(device)

# Define data: a small synthetic example, y = 2 * x + sin(3 * x)
X = np.linspace(-5, 5, 100).reshape(-1, 1)
y = 2 * X[:, 0] + np.sin(3 * X[:, 0])

# Fit the model to the data
model.fit(X, y, verbose=True)

# Show the best expression
print(model.get_expression())

# Predict with the best expression
y_pred = model.predict(X)

Get all candidates at once (infer): instead of fit + read-back, call model.infer(X, y), which returns an InferenceResult carrying the best Candidate, the score-sorted refined candidates, and the full CandidateLedger (the generation pool joined with the refined survivors, each classified FIT_OK / FIT_FAILED / INVALID).

result = model.infer(X, y)
print(result.best.expression_infix, result.best.fvu)  # best refined candidate
for c in result.candidates:                            # score-sorted survivors
    print(c.score, c.expression_infix)
print(len(result.ledger))                              # all candidates considered

Explore more in the Demo Notebook.

Train your own: see the training guide.

Models

Checkpoint Parameters Training Notes
psaegert/flash-ansr-v25.0-T7-3M 3.5M 1M steps, batch 128, configs/v25.0-T7 the reference checkpoint for this release
flash_ansr install psaegert/flash-ansr-v25.0-T7-3M

Every catalog that srbf evaluates on is held out of the training data by canonical form (6,660 expressions across 29 catalogs).

Inference speed

Several inference-speed features are enabled by default and designed to be quality-neutral, so the quickstart above already runs in the fast regime. The speed-relevant settings live on the generation config:

Setting Default What it does
use_cache True KV-cache decoding
batch_size 'auto' candidate-budget-adaptive batching (pass an int to override)
static_decode None static decoding, auto-enabled for capable models (set True/False to force)
from flash_ansr import SoftmaxSamplingConfig

config = SoftmaxSamplingConfig(
  choices=1024,        # number of candidate expressions to sample
  use_cache=True,      # KV cache (default)
  batch_size='auto',   # candidate-budget-adaptive chunking (default)
  static_decode=None,  # auto for capable models (default)
)

Constant refinement runs in parallel; control it via FlashANSR.load(..., refiner_workers=N, persistent_refine_pool=True). By default (refiner_workers=None) the pool uses every available CPU core, which oversubscribes shared machines; pass an explicit integer to cap it (0 disables multiprocessing).

To opt out of these defaults:

SoftmaxSamplingConfig(choices=1024, use_cache=False, batch_size=128, static_decode=False)

Candidate ranking. Three modes, one sort: ranking_mode="mdl" (default; log10(FVU) plus mdl_strength decades per bit of the refined expression's description length), "weighted" (ranking_weights over n_nodes, n_constants, n_constant_placeholders, n_typed_literals, mdl, neg_log_prob) and "pareto" (the non-dominated front over ranking_metrics, ordered by ranking_tie_break). Each knob belongs to one mode and raises under another. The pre-0.14 ranking is ranking_mode="weighted", ranking_weights={"n_nodes": 0.05}.

Overview

SRSD/FastSRB Results

Results on the SRSD/FastSRB benchmark [Matsubara et al. 2022], [Martinek 2025] Left: Validation Numeric Recovery Rate (vNRR) as a function of inference time (log scale). FLASH-ANSR models (shades of blue) scale monotonically with compute, with the 120M model partially surpassing the PySR baseline (red). Baselines NeSymReS [Biggio et al. 2021] and E2E [Kamienny et al. 2022] fail to generalize to the benchmark. Right: Expression Length Ratio (predicted vs ground truth) versus compute. We observe a parsimony inversion: while PySR [Cranmer 2023] increases complexity to minimize error over time, FLASH-ANSR converges toward simpler, more canonical expressions as the sampling budget increases. Shaded regions denote 95% confidence intervals.

Training

The Flash-ANSR training pipeline. Following the established standard encoder-decoder paradigm, our framework integrates SimpliPy (top center) into the loop for synchronous simplification of on-the-fly generated training expressions.

Architecture

Flash-ANSR model architecture. The Set Transformer [Lee et al. 2019] encoder ingests a variable-sized set of input-output pairs and produces a fixed-size latent representation via Induced Set Attention Blocks (ISAB) and Set Attention Blocks (SAB). The Transformer decoder [Vaswani et al. 2017], [Xiong et al. 2020] autoregressively generates a symbolic expression token-by-token, attending to the encoded dataset at each step.

Related projects

  • SimpliPy: the expression simplification engine integrated into the Flash-ANSR training loop.
  • symbolic-data: the model-agnostic symbolic-regression data layer (catalogs, ProblemSource, holdouts) that feeds Flash-ANSR training. It is an unconditional runtime dependency and the backbone of the training loop.
  • srbf: the companion symbolic-regression evaluation and benchmarking framework (engine, model adapters, benchmarks, metrics), developed alongside Flash-ANSR.

Citation

@inproceedings{saegert2026breakingsimplificationbottleneckamortized,
  title   = {Breaking the Simplification Bottleneck in Amortized Neural Symbolic Regression},
  author  = {Paul Saegert and Ullrich Köthe},
  booktitle = {Proceedings of the 43rd International Conference on Machine Learning (ICML)},
  year    = {2026},
  eprint  = {2602.08885},
  archivePrefix =  {arXiv},
  primaryClass  = {cs.LG},
  url     = {https://arxiv.org/abs/2602.08885},
}

% Optionally
@mastersthesis{flash-ansr2024-thesis,
  author  = {Paul Saegert},
  title   = {Flash Amortized Neural Symbolic Regression},
  school  = {Heidelberg University},
  year    = {2025},
  url     = {https://github.com/psaegert/flash-ansr-thesis}
}
@software{flash-ansr2024,
  author  = {Paul Saegert},
  title   = {Flash Amortized Neural Symbolic Regression},
  year    = {2024},
  publisher   = {GitHub},
  version = {0.14.0},
  url     = {https://github.com/psaegert/flash-ansr}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flash_ansr-0.14.0.tar.gz (300.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flash_ansr-0.14.0-py3-none-any.whl (226.6 kB view details)

Uploaded Python 3

File details

Details for the file flash_ansr-0.14.0.tar.gz.

File metadata

  • Download URL: flash_ansr-0.14.0.tar.gz
  • Upload date:
  • Size: 300.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for flash_ansr-0.14.0.tar.gz
Algorithm Hash digest
SHA256 4aa3cf70f073594e616e795e29eca2be470888938f5487ed416eb49927606547
MD5 31bc07e180374fc545da4093a8dfbd25
BLAKE2b-256 528be14ec18cb2722ead702737ee67e9edf76d7b4a14a29d5abe3b6dd159abc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for flash_ansr-0.14.0.tar.gz:

Publisher: publish.yaml on psaegert/flash-ansr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flash_ansr-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: flash_ansr-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 226.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for flash_ansr-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72d4550cf05f3b7094e24b30b33f47f393ebc506118f74b3cf152d2aacb0f13e
MD5 cdd2a99159787c2aae46e8719f3b3f8b
BLAKE2b-256 4c484e3b4fe7d187b50094055034012aaadc06cc87d69425269220f904690e11

See more details on using hashes here.

Provenance

The following attestation bundles were made for flash_ansr-0.14.0-py3-none-any.whl:

Publisher: publish.yaml on psaegert/flash-ansr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.17.0

2 files

0.16.1

2 files

0.16.0

2 files

0.15.2

2 files

0.15.1

2 files

0.15.0

2 files

This release

0.14.0 This release

2 files

0.13.0

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.5

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.5

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page