Browse by type

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.
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.
A nice picture describing the structure of tnlearn will be produced here.
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](https://www.kaggle.com/datasets/basu369victor/prediction-of-
asteroid-diameter) | | :----------------: | :----------------------------------------------------------: | :----------------------------------------------------------: | | 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}$ |
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. |
You should ensure that the version of pytorch corresponds to the version of cuda so that gpu acceleration can be guaranteed. Here is a reference version
Pytorch >= 2.1.0
cuda >= 12.1
Other major dependencies are automatically installed when installing tnlearn.
Tnlearn and its dependencies can be easily installed with pip:
pip install tnlearn
Tnlearn and its dependencies can be easily installed locally:
setup.pypip install -e .
or
pip install -e . --no-deps
pip install -r requirements.txt
This is a quick example to show you how to use tnlearn in regression tasks. Note that your data types should be tabular data.
from tnlearn import VecSymRegressor
from tnlearn import MLPRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
# Generate data.
X, y = make_regression(n_samples=200, random_state=1)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
# A vectorized symbolic regression algorithm is used to generate task-based neurons.
neuron = VecSymRegressor()
neuron.fit(X_train, y_train)
# Build neural network using task-based neurons and train it.
clf = MLPRegressor(neurons=neuron.neuron,
layers_list=[50,30,10]) #Specify the structure of the hidden layers in the MLP.
clf.fit(X_train, y_train)
# Predict
clf.predict(X_test)
Use NeuronSeek to search pure polynomial and CP interaction orders, then build an MLP from the exported inner-product expression:
from tnlearn import PolyTensorRegressor
from tnlearn import MLPRegressor
from tnlearn.operator.inner_product import neuronseek_config_to_string
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
# Generate data.
X, y = make_regression(n_samples=200, n_features=10, random_state=1)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
# Search the structure; the MLP will learn its own weights.
neuron = PolyTensorRegressor(rank=3, poly_order=3, random_state=1)
neuron.fit(X_train, y_train)
print(neuron.structure_)
print(neuron.neuron)
assert neuron.neuron == (neuronseek_config_to_string(neuron.structure_) or '0')
# The default base mode understands inner products.
clf = MLPRegressor(neurons=neuron.neuron, layers_list=[50, 30, 10])
clf.fit(X_train, y_train)
# Predict
clf.predict(X_test)
pure_indices and interact_indices are polynomial orders, not feature
indices. A pure order 2 exports <w1, x**2>, while an interaction order 2
exports <w1, x>*<w2, x>. Each interaction order exports a sum of rank
independent CP components; omitting rank in a manual configuration defaults
to 1. Fitted search weights, gates and batch-normalization parameters are not
transferred to the MLP. If all gates are pruned, the searcher exports '0',
which produces bias-only custom layers.
All export paths, including track_callback and get_significant_polynomial(),
use neuronseek_config_to_string. Manual configurations may also include
periodic=True to add <w, sin(x)>; this searcher selects polynomial orders
only. PolyTensorRegressor supports CP search; the existing
PolyTensorRegression remains the separate legacy CP/Tucker implementation.
After installing pytest, run the focused regression checks with
python -m pytest tests/test_neuronseek.py. The four manual configurations are
also available in examples/example_neuronseek_configs.py.
Discover mathematical equations from data using LLMs. DrSR combines LLM reasoning with optimization to find interpretable expressions as task‑based neurons for MLPRegressor.
from tnlearn import LLMSymRegressor, MLPRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
# Generate data.
X, y = make_regression(n_samples=200, random_state=1)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
# Configure LLM (supporting deepseek, siliconflow, ollama, etc.)
llm_config = {'model': 'deepseek/deepseek-chat'} # Set environment variable DEEPSEEK_API_KEY
# Discover task-based neuron via LLM symbolic regression.
neuron = LLMSymRegressor(llm_config=llm_config, max_iterations=5)
neuron.fit(X_train, y_train)
# Build neural network using the discovered neuron and train it.
clf = MLPRegressor(neurons=neuron.neuron, layers_list=[50,30,10])
clf.fit(X_train, y_train)
# Predict
clf.predict(X_test)
| 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 |
Here's our official API documentation, available on Read the Docs.
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.
$ claude mcp add tnlearn \
-- python -m otcore.mcp_server <graph>