MCPcopy Index your code
hub / github.com/NewT123-WM/tnlearn

github.com/NewT123-WM/tnlearn @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
407 symbols 1,307 edges 62 files 147 documented · 36%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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 Static Badge 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.

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.

Overview

A nice picture describing the structure of tnlearn will be produced here.

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](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}$ |

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.

Dependences

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.

Install

Tnlearn and its dependencies can be easily installed with pip:

pip install tnlearn

Tnlearn and its dependencies can be easily installed locally:

  1. download the package
  2. create a new virtual environment
  3. enter the same-level directory of setup.py
  4. Execute:
pip install -e .

or

pip install -e . --no-deps
pip install -r requirements.txt

Quick start

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)

Another quick example to show you how to use polynomial tensor regressor to build neurons:

from tnlearn import PolyTensorRegression
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 polynomial tensor regressor is used to generate task-based neurons.
neuron = PolyTensorRegression()
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)

DrSR: LLM-based Symbolic Regression

Discover mathematical equations from data using LLMs. DrSR combines LLM reasoning with optimization to find interpretable expressions as task‑based neurons for MLPRegressor.

Quick Start

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)

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

Here's our official API documentation, available on Read the Docs.

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, and Fenglei Fan.

License

Tnlearn is released under Apache License 2.0.

Core symbols most depended-on inside this repo

fit
called by 53
tnlearn/rl_regressor.py
score
called by 44
tnlearn/drsr/buffer.py
predict
called by 29
tnlearn/mlpregressor.py
fit_transform
called by 18
tnlearn/preprocessing.py
load
called by 8
tnlearn/base.py
random_seed
called by 7
tnlearn/seeds.py
update
called by 6
tnlearn/visualize.py
_ntuple
called by 5
tnlearn/modules/TNconv.py

Shape

Method 276
Class 77
Function 54

Languages

Python100%

Modules by API surface

tnlearn/modules/TNconv.py40 symbols
tnlearn/modules/TNtransformer.py29 symbols
tnlearn/modules/TNrnn.py28 symbols
tnlearn/drsr/llm.py20 symbols
tnlearn/drsr/code_manipulation.py20 symbols
tnlearn/drsr/buffer.py20 symbols
tnlearn/regressor.py15 symbols
benchmark/image_benchmark_polyregressor/TC_senet.py15 symbols
benchmark/image_benchmark_polyregressor/TC_Resnet.py15 symbols
tnlearn/drsr/sampler.py14 symbols
benchmark/image_benchmark_polyregressor/TC_densenet.py14 symbols
tnlearn/poly_regressor.py13 symbols

For agents

$ claude mcp add tnlearn \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page