Python Apache-2.0

tnlearn

A Python package that uses task-based neurons to build neural networks.

N

NewT123-WM

Dernière activité 22 sept. 2026
NewT123-WM/tnlearn

302

étoiles

36

forks

0

issues ouvertes

deep-learning-algorithmsgenetic-programmingtask-based-neuronsvectorized-symbolic-regression

Ce README est souvent en anglais.

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{wang2026tnlearn,
  title={TNLearn: An Open Source Python Package for Task-based Neurons},
  author={Wang, Meng and Li, Tieyun and Fan, Juntong and Pei, Hanyu and Liao, Jing-Xiao and Yang, Yaodong and Ma, Jianwei and Fan, Fenglei},
  journal={arXiv preprint arXiv:2609.27564},
  year={2026}
}

@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.

Projets similaires

TensorFlow-based neural network library

Pythonartificial-intelligencedeep-learningmachine-learning
Ggoogle-deepmind
10 k étoiles1,3 k

Building and training artificial neural networks (regression or classification) using the genetic algorithm.

Pythondeep-learninggenetic-algorithmneural-networks
Aahmedfgad
254 étoiles92

Tensors and Dynamic neural networks in Python with strong GPU acceleration

Pythonautograddeep-learninggpu
Ppytorch
103,5 k étoiles30,9 k