Skip to main content

Tnlearn is an open source python library. It is based on the symbolic regression algorithm to generate task-based neurons, and then utilizes diverse neurons to build neural networks.

Static Badge Static Badge PyPI GitHub Repo stars

Quick links

Motivation

  • NuronAI inspired In the past decade, successful networks have primarily used a single type of neurons within novel architectures, yet recent deep learning studies have been inspired by the diversity of human brain neurons, leading to the proposal of new artificial neuron designs.

  • Task-Based Neuron Design Given the human brain's reliance on task-based neurons, can artificial network design shift from focusing on task-based architecture to task-based neuron design?

  • Enhanced Representation Since there are no universally applicable neurons, task-based neurons could enhance feature representation ability within the same structure, due to the intrinsic inductive bias for the task.

Framework

Tnlearn framework

Features

  • Vectorized symbolic regression is employed to find optimal formulas that fit input data.

  • We parameterize the obtained elementary formula to create learnable parameters, serving as the neuron's aggregation function.

Dependencies

Tnlearn declares torch>=1.12.0 and installs required Python dependencies automatically. For GPU usage, install a PyTorch build that matches your hardware from the official PyTorch selector before installing tnlearn.

Install

From PyPI:

pip install tnlearn

From source:

git clone https://github.com/NewT123-WM/tnlearn.git
cd tnlearn
pip install -e .

If PyTorch is already installed with the correct CPU/GPU build, pip install -e . will use it as long as it satisfies torch>=1.12.0.

Quick start

Choose one symbolic regressor, search a task-based neuron expression, then pass that expression to MLPRegressor. For local experiments, start with GPSymRegressor or PolyTensorRegressor; use LLMSymRegressor when an LLM API key is available.

GPSymRegressor

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from tnlearn import GPSymRegressor, MLPRegressor

X, y = make_regression(n_samples=80, n_features=4, random_state=1)
X_train, X_test, y_train, _ = train_test_split(X, y, random_state=1)

search = GPSymRegressor(
    mode='legacy',
    pop_size=40,
    max_generations=2,
    tournament_size=3,
)
search.fit(X_train, y_train)

model = MLPRegressor(search.neuron, layers_list=[8], max_iter=20, mode='legacy')
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

GPSymRegressor(mode='legacy') exports the legacy @ expression format, so the MLP also uses mode='legacy'.

VecSymRegressor is the historical class name for this legacy GP path. In other symbolic regressors, mode='legacy' has the same compatibility meaning: it selects the older simplified vectorized expression format without inner-product interaction terms. The default/base modes below export inner-product expressions for the current MLP API.

PolyTensorRegressor

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from tnlearn import MLPRegressor, PolyTensorRegressor

X, y = make_regression(n_samples=80, n_features=6, random_state=1)
X_train, X_test, y_train, _ = train_test_split(X, y, random_state=1)

search = PolyTensorRegressor(rank=2, poly_order=2, num_epochs=10, random_state=1)
search.fit(X_train, y_train)

model = MLPRegressor(search.neuron, layers_list=[8], max_iter=20)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

RLSymRegressor

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from tnlearn import MLPRegressor, RLSymRegressor

X, y = make_regression(n_samples=80, n_features=4, random_state=1)
X_train, X_test, y_train, _ = train_test_split(X, y, random_state=1)

search = RLSymRegressor(
    max_episodes=10,
    max_terms_total=3,
    random_state=1,
    verbose=False,
)
search.fit(X_train, y_train)

model = MLPRegressor(search.neuron, layers_list=[8], max_iter=20)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

LLMSymRegressor

Set DEEPSEEK_API_KEY before running this example.

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from tnlearn import LLMSymRegressor, MLPRegressor

X, y = make_regression(n_samples=80, n_features=4, random_state=1)
X_train, X_test, y_train, _ = train_test_split(X, y, random_state=1)

search = LLMSymRegressor(
    llm_config={'model': 'deepseek/deepseek-chat'},
    max_iterations=1,
    samples_per_iteration=1,
    verbose=0,
    mode='base',
)
search.fit(X_train, y_train)

model = MLPRegressor(search.neuron, layers_list=[8], max_iter=20)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)

PolyTensorRegressor, RLSymRegressor, and LLMSymRegressor export inner-product expressions such as <w1, x**2> + <w2, x>*<w3, x>, which the default MLP mode understands directly.

Supported LLM Providers

Provider Environment Variable Example model
DeepSeek DEEPSEEK_API_KEY deepseek/deepseek-chat
SiliconFlow SILICONFLOW_API_KEY siliconflow/Qwen/Qwen3-8B
Ollama (local) – ollama/llama3.1:8b
BLT BLT_API_KEY blt/gpt-4
CSTCloud CSTCLOUD_API_KEY cstcloud/gpt-oss-120b

API documentation

For complete module references, class parameters, and advanced usage:

Open API Documentation

Benchmarks

We select several advanced machine learning methods for comparison.

Method Venues Code link
XGBoost ACM SIGKDD 2016 Adopt official code
LightGBM NeurIPS 2017 Implemented by widedeep
CatBoost Journal of big data Adopt official code
TabNet AAAI 2021 Implemented by widedeep
Tab Transformer arxiv Adopt official code
FT-Transformer NeurIPS 2021 Implemented by widedeep
DANETs AAAI 2022 Adopt official code

We test multiple advanced machine learning methods on two sets of real-world data. The test results (MSE) are shown in the following table:

Method Particle collision Asteroid prediction
XGBoost $0.0094\pm0.0006$ $0.0646\pm0.1031$
LightGBM $0.0056\pm0.0004$ $0.1391\pm0.1676$
CatBoost $0.0028\pm0.0002$ $0.0817\pm0.0846$
TabNet $0.0040\pm0.0006$ $0.0627\pm0.0939$
TabTransformer $0.0038\pm0.0008$ $0.4219\pm0.2776$
FT-Transformer $0.0050\pm0.0020$ $0.2136\pm0.2189$
DANETs $0.0076\pm0.0009$ $0.1709\pm0.1859$
Task-based Network $\mathbf{0.0016\pm0.0005}$ $\mathbf{0.0513\pm0.0551}$

Resource

Here is a resource summary for neuronal diversity in artificial networks.

Resource Type Description
QuadraLib Library The QuadraLib is a library for the efficient optimization and design exploration of quadratic networks.The paper of QuadraLib won MLSys 2022’s best paper award.
Dr. Fenglei Fan’s GitHub Page Code Dr. Fenglei Fan’s GitHub Page summarizes a series of papers and associated code on quadratic networks, including quadratic autoencoder and the training algorithm ReLinear.
Polynomial Network Code This repertoire shows how to build a deep polynomial network and sparsify it with tensor decomposition.
Dendrite Book A comprehensive book covering all aspects of dendritic computation.

Citation

If you find Tnlearn useful, please cite it in your publications.

@article{fan2026no,
  title={No one-size-fits-all neurons: Task-based neurons for artificial neural networks},
  author={Fan, Feng-Lei and Wang, Meng and Dong, Hang-Cheng and Ma, Jianwei and Zeng, Tieyong},
  journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
  year={2026},
  publisher={IEEE}
}

The Team

Tnlearn is a work by Meng Wang, Juntong Fan, Hanyu Pei, Tieyun LI, Jingxiao Liao, Shuren Qi, Lizhao Xu, Zeyu LI, Renfeng Peng, Yudong Wang, Can Dong, Tansheng Zhu, Liangchen Tan, Feifei Zhang, Yihan Jin, Yiqing Zhang, Kairan Zhang and Fenglei Fan.

License

Tnlearn is released under Apache License 2.0.

Metadata

Release files for tnlearn 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tnlearn 0.2.0
File Size Uploaded
tnlearn-0.2.0.tar.gz 103.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tnlearn 0.2.0
File Interpreter ABI Platform
tnlearn-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 218.9 kB

Release files / tnlearn-0.2.0.tar.gz

Download URL tnlearn-0.2.0.tar.gz
Size 103.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ab5240e6863d54646a97af4ec474f294a8e08f8891ed6236433c557d8ac5aab8
BLAKE2b-256 checksum
How to use checksums
dbc751df39a113b718040a7766974241384b344f9568c148fa6afb562fe5617c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / tnlearn-0.2.0-py3-none-any.whl

Download URL tnlearn-0.2.0-py3-none-any.whl
Size 115.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3121946768c7b300fb62a946cf33e1af4d921b4bed2f453245448e59042802d0
BLAKE2b-256 checksum
How to use checksums
4312aab0b06432840e25c43613b26db47097066860fcd0a32f51a0c843cb1135
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release 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