PyTorchTabularModelsZoo Module

Collection of PyTorch tabular models and helper utilities for tabular datasets.

class HMB.PyTorchTabularModelsZoo.MLPModel(inputSize, numClasses, hiddenSizes=None, dropout=0.2)[source]

Bases: Module

Multi-layer perceptron for tabular classification.

Builds a stack of Linear -> BatchNorm -> ReLU -> Dropout blocks followed by a final linear classification layer.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • hiddenSizes (list[int] or None) – Hidden layer sizes. If None defaults are used.

  • dropout (float) – Dropout probability applied after activations.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.TCNModel(inputSize, numClasses, channels=None, kernelSize=3, dropout=0.2)[source]

Bases: Module

Temporal convolutional network style model for tabular data treated as a 1D sequence of features.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • channels (list[int] or None) – Channel sizes for convolutional blocks.

  • kernelSize (int) – Kernel size for Conv1d layers.

  • dropout (float) – Dropout probability.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.TabTransformerModel(inputSize, numClasses, embedDim=64, numHeads=4, numLayers=2)[source]

Bases: Module

Transformer-based model that embeds each numeric feature as a token and applies a Transformer encoder across features for classification.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • embedDim (int) – Embedding dimension for each feature token.

  • numHeads (int) – Number of attention heads.

  • numLayers (int) – Number of Transformer encoder layers.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.FTTransformerModel(inputSize, numClasses, embedDim=64, numHeads=4, numLayers=2, dropout=0.1)[source]

Bases: Module

Lightweight FT-Transformer style model embedding each feature as a token.

A CLS token is prepended and the classification is performed from the CLS token embedding after Transformer encoding.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • embedDim (int) – Token embedding dimensionality.

  • numHeads (int) – Number of attention heads.

  • numLayers (int) – Number of Transformer layers.

  • dropout (float) – Dropout probability inside Transformer layers.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.GANDALFModel(inputSize, numClasses, hidden=128, gate_hidden=64)[source]

Bases: Module

GANDALF-inspired gated feature learning model.

The model applies a per-feature gating network followed by a shared encoder and a classification head.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • hidden (int) – Hidden size of the shared encoder.

  • gate_hidden (int) – Hidden size of the gate network.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.HybridCNNTransformerModel(inputSize, numClasses, cnnChannels=None, kernelSize=3, embedDim=128, numHeads=4, numLayers=2, dropout=0.2)[source]

Bases: Module

Hybrid CNN + Transformer model for tabular inputs treated as feature sequences.

The convolutional front-end extracts local feature patterns and the Transformer provides global context before classification.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.VAEAnomalyDetector(inputSize, latentDim=32, hiddenSizes=None)[source]

Bases: Module

Variational autoencoder for anomaly detection on tabular features.

Trains as an autoencoder and uses reconstruction error as an anomaly score.

Parameters:
  • inputSize (int) – Number of input features.

  • latentDim (int) – Dimensionality of latent representation.

  • hiddenSizes (list[int] or None) – Hidden sizes for encoder/decoder.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

reparameterize(mu, logvar)[source]

Reparameterization trick to sample z ~ N(mu, sigma^2) from parameters.

Parameters:
Returns:

Sampled latent tensor.

Return type:

torch.Tensor

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: tuple[Tensor, Tensor, Tensor]

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

tuple[Tensor, Tensor, Tensor]

reconstruction_error(x)[source]

Compute per-sample reconstruction error used for anomaly scoring.

Parameters:

x (torch.Tensor) – Input batch of shape (batch, inputSize).

Returns:

Per-sample MSE reconstruction error of shape (batch,).

Return type:

torch.Tensor

class HMB.PyTorchTabularModelsZoo.VAEClassifier(inputSize, numClasses, latentDim=32)[source]

Bases: Module

Hybrid model combining a VAE for feature learning with a classifier head. The VAE learns a latent representation of the input features, and the classifier operates on the VAE’s reconstruction to perform classification.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • latentDim (int) – Dimensionality of the VAE latent space.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.ContrastiveEncoder(inputSize, embDim=128, projDim=64, hiddenSizes=None)[source]

Bases: Module

Lightweight encoder + projection head for contrastive pretraining (SimCLR style). Outputs normalized embeddings and a projection vector suitable for contrastive loss.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: tuple[Tensor, Tensor]

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

tuple[Tensor, Tensor]

class HMB.PyTorchTabularModelsZoo.ContrastiveClassifier(inputSize, numClasses, embDim=128)[source]

Bases: Module

Simple classifier that uses the ContrastiveEncoder for feature extraction. The encoder can be pretrained with a contrastive loss and then fine-tuned for classification.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • embDim (int) – Embedding dimension from the ContrastiveEncoder.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.GNNModel(inputSize, numClasses, hiddenDim=128, numLayers=2, dropout=0.2, useResidual=True)[source]

Bases: Module

Graph Neural Network for tabular data with graph structure. Supports both adjacency matrix and edge index formats. Implements basic message passing with optional residual connections. For production use with complex graphs, consider PyTorch Geometric or DGL.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Parameters:
forward(x, adj=None, edgeIndex=None, edgeWeight=None, batch=None)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.GraphConvLayer(inChannels, outChannels, dropout=0.2)[source]

Bases: Module

Single graph convolution layer with optional edge weights.

Implements: h_i’ = W_1 * h_i + W_2 * sum_{j in N(i)} (edge_weight_ij * h_j).

Parameters:
  • inChannels (int) – Input feature dimensionality per node.

  • outChannels (int) – Output feature dimensionality per node.

  • dropout (float) – Dropout probability applied after normalization.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x, adj=None, edgeIndex=None, edgeWeight=None)[source]

Forward pass performing message passing with optional adjacency formats.

Parameters:
  • x (torch.Tensor) – Node feature matrix of shape (numNodes, inChannels).

  • adj (torch.Tensor or None) – Dense adjacency matrix of shape (numNodes, numNodes).

  • edgeIndex (torch.Tensor or None) – Edge index tensor of shape (2, numEdges).

  • edgeWeight (torch.Tensor or None) – Optional edge weights of shape (numEdges,) or compatible.

Returns:

Updated node embeddings of shape (numNodes, outChannels).

Return type:

torch.Tensor

class HMB.PyTorchTabularModelsZoo.ResidualBlock(inFeatures, outFeatures, dropout=0.2)[source]

Bases: Module

Residual block for tabular data with skip connection.

Implements: output = activation(norm(linear(activation(norm(linear(input)))))) + input

Parameters:
  • inFeatures (int) – Number of input features.

  • outFeatures (int) – Number of output features.

  • dropout (float) – Dropout probability applied after activation.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.ResNetTabularModel(inputSize, numClasses, blockChannels=None, dropout=0.2)[source]

Bases: Module

Residual network for tabular data with skip connections.

Implements residual blocks: y = F(x) + x to enable deeper networks without vanishing gradients. Suitable for high-dimensional tabular data.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • blockChannels (list[int]) – Channel sizes for residual blocks.

  • dropout (float) – Dropout probability applied in residual blocks.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.AutoIntAttentionLayer(embedDim, numHeads, dropout=0.1)[source]

Bases: Module

Multi-head self-attention layer for feature interaction modeling.

Implements attention over feature tokens to capture explicit high-order feature interactions at different subspaces.

Parameters:
  • embedDim (int) – Embedding dimension per feature token.

  • numHeads (int) – Number of attention heads.

  • dropout (float) – Dropout probability applied after attention.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.AutoIntModel(inputSize, numClasses, embedDim=32, numAttentionLayers=3, numHeads=2, dropout=0.1)[source]

Bases: Module

Attentional Interaction Network for explicit feature crossing.

Uses multi-head self-attention to model feature interactions at different representation subspaces, followed by classification.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • embedDim (int) – Embedding dimension per feature token.

  • numAttentionLayers (int) – Number of attention interaction layers.

  • numHeads (int) – Number of attention heads per layer.

  • dropout (float) – Dropout probability in attention layers.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.SAINTIntersampleAttention(embedDim, numHeads, dropout=0.1)[source]

Bases: Module

Intersample attention module for batch-level feature refinement.

Computes attention across samples in a batch to enable few-shot generalization and context-aware representations.

Parameters:
  • embedDim (int) – Embedding dimension per feature token.

  • numHeads (int) – Number of attention heads.

  • dropout (float) – Dropout probability after attention.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.SAINTModel(inputSize, numClasses, embedDim=32, numHeads=2, numFeatureLayers=2, numIntersampleLayers=1, useIntersampleAttention=True, dropout=0.1)[source]

Bases: Module

SAINT: Self-Attention and Intersample Attention Transformer.

Combines intra-sample feature attention with inter-sample attention across the batch for few-shot generalization.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • embedDim (int) – Token embedding dimension.

  • numHeads (int) – Number of attention heads.

  • numFeatureLayers (int) – Number of intra-sample attention layers.

  • numIntersampleLayers (int) – Number of inter-sample attention layers.

  • useIntersampleAttention (bool) – Enable batch-level attention.

  • dropout (float) – Dropout probability in attention layers.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.ShapeFunctionNet(hiddenSize, outputDim=1, dropout=0.1)[source]

Bases: Module

Small subnetwork that processes a single feature for additive modeling.

Parameters:
  • hiddenSize (int) – Hidden dimension of the shape function network.

  • outputDim (int) – Output dimension (typically 1 for additive models).

  • dropout (float) – Dropout probability.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.NeuralAdditiveModel(inputSize, numClasses, shapeFunctionHidden=32, dropout=0.1)[source]

Bases: Module

Interpretable neural additive model for tabular data.

Each feature is processed by an independent subnetwork; outputs are summed for final prediction enabling interpretability.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • shapeFunctionHidden (int) – Hidden size per feature subnetwork.

  • dropout (float) – Dropout probability in shape functions.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.CrossLayer(inputSize)[source]

Bases: Module

Cross network layer for explicit polynomial feature crossing.

Implements: x_{l+1} = x_0 * (x_l^T * w_l + b_l) + x_l where x_0 is the original input and w_l, b_l are learned parameters.

Parameters:

inputSize (int) – Number of input features (must match original input).

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x0, xl)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:
Return type:

Tensor

class HMB.PyTorchTabularModelsZoo.DeepCrossNetwork(inputSize, numClasses, crossLayers=3, deepHiddenSizes=None, dropout=0.2)[source]

Bases: Module

Deep Cross Network for explicit low- and high-order feature crossing.

Combines a cross network (polynomial feature interactions) with a deep network (non-linear transformations) in parallel.

Parameters:
  • inputSize (int) – Number of input features.

  • numClasses (int) – Number of output classes.

  • crossLayers (int) – Number of cross network layers.

  • deepHiddenSizes (list[int]) – Hidden sizes for deep network branch.

  • dropout (float) – Dropout probability in deep network.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Parameters:

x (Tensor)

Return type:

Tensor

HMB.PyTorchTabularModelsZoo.GetModel(name, inputSize, numClasses)[source]

Factory that returns a model instance by its CamelCase name key.

Parameters:
  • name (str) – CamelCase model identifier string.

  • inputSize (int) – Number of input features for the model.

  • numClasses (int) – Number of output classes for classification models.

Returns:

Instantiated PyTorch model corresponding to name.

Return type:

nn.Module