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.
- Quick links
- Motivation
- Framework
- Features
- Dependencies
- Install
- Quick start
- API documentation
- Benchmarks
- Resource
- Citation
- The Team
- License
-
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.
-
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.
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.
From PyPI:
pip install tnlearnFrom 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.
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.
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.
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)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)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.
| 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 |
For complete module references, class parameters, and advanced usage:
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 | ||
| LightGBM | ||
| CatBoost | ||
| TabNet | ||
| TabTransformer | ||
| FT-Transformer | ||
| DANETs | ||
| Task-based Network |
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. |
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}
}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.
Tnlearn is released under Apache License 2.0.
