TabNetNetwork<T>

Models & Types · AiDotNet.NeuralNetworks.Tabular

TabNet neural network for interpretable tabular learning.

Inheritance: NeuralNetworkBase<T> → TabularNeuralNetworkBase<T> → TabNetNetwork<T>

For Beginners

TabNet is designed for interpretability:

Architecture:

  1. Feature Transformer: Shared layers process all features
  2. Attentive Transformer: Selects which features to use at each step
  3. Decision Steps: Multiple rounds of feature selection
  4. Sparse Attention: Only a few features are used per step

Key insight: At each decision step, TabNet decides “which features should I focus on?” This sequential attention makes the model interpretable - you can see exactly which features were used for each prediction.

TabNet often matches gradient boosting (XGBoost, LightGBM) while providing built-in feature importance and interpretability.

How It Works

TabNet uses sequential attention to choose which features to reason from at each decision step, enabling interpretable feature selection while achieving performance competitive with gradient boosting. This implementation follows the standard neural network architecture pattern with:

  • Proper inheritance from NeuralNetworkBase
  • Layer-based architecture using ILayer components
  • Engine-based tensor operations for CPU/GPU acceleration
  • Full autodiff and JIT compilation support

Reference: “TabNet: Attentive Interpretable Tabular Learning” (Arik & Pfister, AAAI 2021)

Example

var architecture = new NeuralNetworkArchitecture<float>(inputFeatures: 8, outputSize: 4);
var options = new TabNetOptions<double> { NumFeatures = 20, NumDecisionSteps = 5, RelaxationFactor = 1.5 };
var input = Tensor<float>.CreateRandom(new[] { 1, 20 });
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
    .ConfigureModel(new TabNetNetwork<float>(architecture))
    .Build(trainX, trainY);
var output = result.Predict(input);

Constructors

Constructor Summary
TabNetNetwork() Initializes a new instance with default architecture settings.
TabNetNetwork(NeuralNetworkArchitecture<T> architecture, TabNetOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Initializes a new TabNet network with the specified architecture.

Properties

Property Summary
TabNetOptions<T> Options { get; } Gets the TabNet-specific options.
int FeatureDimension { get; } Gets the feature dimension.
int NumDecisionSteps { get; } Gets the number of decision steps.

Methods

Method Summary
Dictionary<string, T> GetFeatureImportance()
ModelMetadata<T> GetModelMetadata()