FTTransformerClassifier<T>

Models & Types ยท AiDotNet.NeuralNetworks.Tabular

FT-Transformer implementation for classification tasks.

Inheritance: FTTransformerBase<T> โ†’ FTTransformerClassifier<T>

For Beginners

Use this model when you want to predict categories (like spam/not spam, customer segments, product categories, etc.).

How it works:

  1. Features are tokenized and processed by transformer layers
  2. The [CLS] token captures information from all features
  3. A linear layer maps the [CLS] representation to class logits
  4. Softmax converts logits to probabilities

Example:

How It Works

FTTransformerClassifier applies the FT-Transformer architecture to multi-class classification problems. It uses the [CLS] token output with a linear classification head and softmax activation.

Constructors

Constructor Summary
FTTransformerClassifier(int numNumericalFeatures, int numClasses, FTTransformerOptions<T> options) Initializes a new instance of the FTTransformerClassifier class.

Properties

Property Summary
int NumClasses { get; } Gets the number of output classes.

Methods

Method Summary
T ComputeAccuracy(Tensor<T> numericalFeatures, int[] targets, Matrix<int> categoricalIndices) Computes classification accuracy.
T ComputeCrossEntropyLoss(Tensor<T> probabilities, int[] targets) Computes the cross-entropy loss.
T ComputeF1Score(Tensor<T> numericalFeatures, int[] targets, Matrix<int> categoricalIndices) Computes the macro F1 score across all classes.
T TrainStep(Tensor<T> numericalFeatures, int[] targets, T learningRate, Matrix<int> categoricalIndices) Performs a single training step.
Tensor<T> Forward(Tensor<T> numericalFeatures) Performs the forward pass with numerical features only.
Tensor<T> Forward(Tensor<T> numericalFeatures, Matrix<int> categoricalIndices) Performs the forward pass to get class logits.
Tensor<T> PredictProbabilities(Tensor<T> numericalFeatures) Predicts class probabilities with numerical features only.
Tensor<T> PredictProbabilities(Tensor<T> numericalFeatures, Matrix<int> categoricalIndices) Predicts class probabilities using softmax.
int[] Predict(Tensor<T> numericalFeatures) Predicts class indices with numerical features only.
int[] Predict(Tensor<T> numericalFeatures, Matrix<int> categoricalIndices) Predicts the most likely class for each sample.
void ResetState() Resets internal state.
void UpdateParameters(T learningRate) Updates all parameters including the classification head.